Debian Codegraph @

doc/html/pgtcl-pgconnect.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.6.0">
6 <title>pg_connect</title>
7 <meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.79">
8 <link rev="MADE" href="mailto:[email protected]">
9 <link rel="HOME" title="PostgreSQL Tcl Interface Documentation" href="index.html">
10 <link rel="UP" title="pgtcl Command Reference" href="libpgtcl-ref.html">
11 <link rel="PREVIOUS" title="pgtcl Command Reference" href="libpgtcl-ref.html">
12 <link rel="NEXT" title="pg_dbinfo" href="pgtcl-pgconninfo.html">
13 <link rel="STYLESHEET" type="text/css" href="stylesheet.css">
14 </head>
15 <body class="REFENTRY">
16 <div class="NAVHEADER">
17 <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
18 <tr>
19 <th colspan="5" align="center" valign="bottom">PostgreSQL Tcl Interface Documentation</th>
20 </tr>
21 <tr>
22 <td width="10%" align="left" valign="top"><a href="libpgtcl-ref.html" accesskey="P">Prev</a></td>
23 <td width="10%" align="left" valign="top"><a href="libpgtcl-ref.html#LIBPGTCL-REF">Fast Backward</a></td>
24 <td width="60%" align="center" valign="bottom"></td>
25 <td width="10%" align="right" valign="top"><a href="pgtcl-pgconninfo.html">Fast Forward</a></td>
26 <td width="10%" align="right" valign="top"><a href="pgtcl-pgconninfo.html" accesskey="N">Next</a></td>
27 </tr>
28 </table>
29 <hr align="left" width="100%"></div>
30 <h1><a name="PGTCL-PGCONNECT" id="PGTCL-PGCONNECT"></a>pg_connect</h1>
31 <div class="REFNAMEDIV"><a name="AEN323" id="AEN323"></a>
32 <h2>Name</h2>
33 pg_connect&nbsp;--&nbsp;open a connection to the server<a name="IX-PGTCL-PGCONNECT-2" id="IX-PGTCL-PGCONNECT-2"></a></div>
34 <div class="REFSYNOPSISDIV"><a name="AEN328" id="AEN328"></a>
35 <h2>Synopsis</h2>
36 <pre class="SYNOPSIS">pg_connect -conninfo <code class="PARAMETER">connectOptions</code> ?<span class="OPTIONAL">-connhandle <code class="PARAMETER">connectionHandleName</code></span>? ?<span class="OPTIONAL">-async <code class="PARAMETER">bool</code></span>?
37 pg_connect <code class="PARAMETER">dbName</code> ?<span class="OPTIONAL">-host <code class="PARAMETER">hostName</code></span>? ?<span class="OPTIONAL">-port <code class="PARAMETER">portNumber</code></span>? ?<span class="OPTIONAL">-tty <code class="PARAMETER">tty</code></span>? ?<span class="OPTIONAL">-options <code class="PARAMETER">serverOptions</code></span>? ?<span class="OPTIONAL">-connhandle <code class="PARAMETER">connectionHandleName</code></span>? ?<span class="OPTIONAL">-async <code class="PARAMETER">bool</code></span>?
38 pg_connect -connlist <code class="PARAMETER">connectNameValueList</code> ?<span class="OPTIONAL">-connhandle <code class="PARAMETER">connectionHandleName</code></span>? ?<span class="OPTIONAL">-async <code class="PARAMETER">bool</code></span>?</pre></div>
39 <div class="REFSECT1"><a name="AEN353" id="AEN353"></a>
40 <h2>Description</h2>
41 <p><code class="FUNCTION">pg_connect</code> opens a connection to the <span class="PRODUCTNAME">PostgreSQL</span> server.</p>
42 <p>Three syntaxes are available. In the older one, each possible option has a separate option switch in the <tt class="COMMAND">pg_connect</tt> command. In the newer form, a single option string is supplied that can contain multiple option values. The third form takes the parameters as a name value Tcl list. <code class="FUNCTION">pg_conndefaults</code> can be used to retrieve information about the available options in the newer syntax.</p>
43 </div>
44 <div class="REFSECT1"><a name="AEN361" id="AEN361"></a>
45 <h2>Arguments</h2>
46 <div class="VARIABLELIST">
47 <p><b>New style</b></p>
48 <dl>
49 <dt><code class="PARAMETER">connectOptions</code></dt>
50 <dd>
51 <p><code class="FUNCTION">pg_connect</code> opens a new database connection using the parameters taken from the <tt class="LITERAL">connectOptions</tt> string. Unlike the old-style usage of <code class="FUNCTION">pg_connect</code>, with the new-style usage the parameter set can be extended without requiring changes to either <tt class="FILENAME">libpgtcl</tt> or the underlying <span class="APPLICATION">libpq</span> library, so use of the new style (or its nonexistent nonblocking analogues <code class="FUNCTION">pg_connect_start</code> and <code class="FUNCTION">pg_connect_poll</code>) is preferred for new application programming.</p>
52 <p>The passed string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace. Each parameter setting is in the form <tt class="LITERAL">keyword = value</tt>. (To write an empty value or a value containing spaces, surround it with single quotes, e.g., <tt class="LITERAL">keyword = 'a value'</tt>. Single quotes and backslashes within the value must be escaped with a backslash, i.e., <tt class="LITERAL">\'</tt> and <tt class="LITERAL">\\</tt>.) Spaces around the equal sign are optional.</p>
53 <p>The currently recognized parameter key words are:</p>
54 <div class="VARIABLELIST">
55 <dl>
56 <dt><tt class="LITERAL">host</tt></dt>
57 <dd>
58 <p>Name of host to connect to.<a name="AEN389" id="AEN389"></a> If this begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. The default is to connect to a Unix-domain socket in <tt class="FILENAME">/tmp</tt>.<a name="AEN392" id="AEN392"></a></p>
59 </dd>
60 <dt><tt class="LITERAL">hostaddr</tt></dt>
61 <dd>
62 <p>Numeric IP address of host to connect to. This should be in the standard IPv4 address format, e.g., <tt class="LITERAL">172.28.40.9</tt>. If your machine supports IPv6, you can also use IPv6 address format, e.g., <tt class="LITERAL">fe80::203:93ff:fedb:49bc</tt>. TCP/IP communication is always used when a nonempty string is specified for this parameter.</p>
63 <p>Using <tt class="LITERAL">hostaddr</tt> instead of <tt class="LITERAL">host</tt> allows the application to avoid a host name lookup, which may be important in applications with time constraints. However, Kerberos authentication requires the host name. The following therefore applies: If <tt class="LITERAL">host</tt> is specified without <tt class="LITERAL">hostaddr</tt>, a host name lookup occurs. If <tt class="LITERAL">hostaddr</tt> is specified without <tt class="LITERAL">host</tt>, the value for <tt class="LITERAL">hostaddr</tt> gives the remote address. When Kerberos is used, a reverse name query occurs to obtain the host name for Kerberos. If both <tt class="LITERAL">host</tt> and <tt class="LITERAL">hostaddr</tt> are specified, the value for <tt class="LITERAL">hostaddr</tt> gives the remote address; the value for <tt class="LITERAL">host</tt> is ignored, unless Kerberos is used, in which case that value is used for Kerberos authentication. (Note that authentication is likely to fail if <span class="APPLICATION">libpq</span> is passed a host name that is not the name of the machine at <tt class="LITERAL">hostaddr</tt>.) Also, <tt class="LITERAL">host</tt> rather than <tt class="LITERAL">hostaddr</tt> is used to identify the connection in <tt class="FILENAME">$HOME/.pgpass</tt>.</p>
64 <p>Without either a host name or host address, <span class="APPLICATION">Pgtcl</span> will connect using a local Unix domain socket.</p>
65 </dd>
66 <dt><tt class="LITERAL">port</tt></dt>
67 <dd>
68 <p>Port number to connect to at the server host, or socket file name extension for Unix-domain connections.<a name="AEN425" id="AEN425"></a></p>
69 </dd>
70 <dt><tt class="LITERAL">dbname</tt></dt>
71 <dd>
72 <p>The database name. Defaults to be the same as the user name.</p>
73 </dd>
74 <dt><tt class="LITERAL">user</tt></dt>
75 <dd>
76 <p><span class="PRODUCTNAME">PostgreSQL</span> user name to connect as.</p>
77 </dd>
78 <dt><tt class="LITERAL">password</tt></dt>
79 <dd>
80 <p>Password to be used if the server demands password authentication.</p>
81 </dd>
82 <dt><tt class="LITERAL">connect_timeout</tt></dt>
83 <dd>
84 <p>Maximum wait for connection, in seconds (write as a decimal integer string). Zero or not specified means wait indefinitely. It is not recommended to use a timeout of less than 2 seconds.</p>
85 </dd>
86 <dt><tt class="LITERAL">options</tt></dt>
87 <dd>
88 <p>Command-line options to be sent to the server.</p>
89 </dd>
90 <dt><tt class="LITERAL">tty</tt></dt>
91 <dd>
92 <p>Ignored (formerly, this specified where to send server debug output).</p>
93 </dd>
94 <dt><tt class="LITERAL">sslmode</tt></dt>
95 <dd>
96 <p>This option determines whether or with what priority an <acronym class="ACRONYM">SSL</acronym> connection will be negotiated with the server. There are four modes: <tt class="LITERAL">disable</tt> will attempt only an unencrypted <acronym class="ACRONYM">SSL</acronym> connection; <tt class="LITERAL">allow</tt> will negotiate, trying first a non-<acronym class="ACRONYM">SSL</acronym> connection, then if that fails, trying an <acronym class="ACRONYM">SSL</acronym> connection; <tt class="LITERAL">prefer</tt> (the default) will negotiate, trying first an <acronym class="ACRONYM">SSL</acronym> connection, then if that fails, trying a regular non-<acronym class="ACRONYM">SSL</acronym> connection; <tt class="LITERAL">require</tt> will try only an <acronym class="ACRONYM">SSL</acronym> connection.</p>
97 <p>If <span class="PRODUCTNAME">PostgreSQL</span> is compiled without SSL support, using option <tt class="LITERAL">require</tt> will cause an error, and options <tt class="LITERAL">allow</tt> and <tt class="LITERAL">prefer</tt> will be tolerated but <span class="APPLICATION">libpq</span> will be unable to negotiate an <acronym class="ACRONYM">SSL</acronym> connection.<a name="AEN481" id="AEN481"></a></p>
98 </dd>
99 <dt><tt class="LITERAL">requiressl</tt></dt>
100 <dd>
101 <p>This option is deprecated in favor of the <tt class="LITERAL">sslmode</tt> setting.</p>
102 <p>If set to 1, an <acronym class="ACRONYM">SSL</acronym> connection to the server is required (this is equivalent to <tt class="LITERAL">sslmode</tt> <tt class="LITERAL">require</tt>). <span class="APPLICATION">libpq</span> will then refuse to connect if the server does not accept an <acronym class="ACRONYM">SSL</acronym> connection. If set to 0 (default), <span class="APPLICATION">libpq</span> will negotiate the connection type with the server (equivalent to <tt class="LITERAL">sslmode</tt> <tt class="LITERAL">prefer</tt>). This option is only available if <span class="PRODUCTNAME">PostgreSQL</span> is compiled with SSL support.</p>
103 </dd>
104 <dt><tt class="LITERAL">service</tt></dt>
105 <dd>
106 <p>Service name to use for additional parameters. It specifies a service name in <tt class="FILENAME">pg_service.conf</tt> that holds additional connection parameters. This allows applications to specify only a service name so connection parameters can be centrally maintained. See <tt class="FILENAME"><tt class="REPLACEABLE"><i>PREFIX</i></tt>/share/pg_service.conf.sample</tt> for information on how to set up the file.</p>
107 </dd>
108 <dt><code class="OPTION">-connhandle <code class="PARAMETER">connectionHandleName</code></code></dt>
109 <dd>
110 <p>Name to use for the connection handle, instead of pgtcl generating the name automatically. Without the option, the name is auto-generated, prefixed with pgsql, and with a numeric id at the end. This gives the programmer control over the name of the connection handle.</p>
111 </dd>
112 <dt><code class="OPTION">-async <code class="PARAMETER">bool</code></code></dt>
113 <dd>
114 <p>Connect asyncronously if [<span class="OPTIONAL">bool</span>] is true.</p>
115 </dd>
116 </dl>
117 </div>
118 <p>If any parameter is unspecified, then the corresponding environment variable (see <tt class="LITERAL">libpq</tt> documentation in the <span class="PRODUCTNAME">PostgreSQL</span> manual) is checked. If the environment variable is not set either, then built-in defaults are used.</p>
119 </dd>
120 </dl>
121 </div>
122 <div class="VARIABLELIST">
123 <p><b>Old style</b></p>
124 <dl>
125 <dt><code class="PARAMETER">dbName</code></dt>
126 <dd>
127 <p>The name of the database to connect to.</p>
128 </dd>
129 <dt><code class="OPTION">-host <code class="PARAMETER">hostName</code></code></dt>
130 <dd>
131 <p>The host name of the database server to connect to.</p>
132 </dd>
133 <dt><code class="OPTION">-port <code class="PARAMETER">portNumber</code></code></dt>
134 <dd>
135 <p>The TCP port number of the database server to connect to.</p>
136 </dd>
137 <dt><code class="OPTION">-tty <code class="PARAMETER">tty</code></code></dt>
138 <dd>
139 <p>A file or <acronym class="ACRONYM">TTY</acronym> for optional debug output from the server.</p>
140 </dd>
141 <dt><code class="OPTION">-options <code class="PARAMETER">serverOptions</code></code></dt>
142 <dd>
143 <p>Additional configuration options to pass to the server.</p>
144 </dd>
145 <dt><code class="OPTION">-connhandle <code class="PARAMETER">connectionHandleName</code></code></dt>
146 <dd>
147 <p>Name to use for the connection handle, instead of pgtcl generating the name automatically. Without the option, the name is auto-generated, prefixed with pgsql, and with a numeric id at the end. This gives the programmer control over the name of the connection handle.</p>
148 </dd>
149 <dt><code class="OPTION">-async <code class="PARAMETER">bool</code></code></dt>
150 <dd>
151 <p>Connect asyncronously if [<span class="OPTIONAL">bool</span>] is true.</p>
152 </dd>
153 </dl>
154 </div>
155 <div class="VARIABLELIST">
156 <p><b>Third style (most recent one added)</b></p>
157 <dl>
158 <dt><code class="PARAMETER">-connlist connectNameValuelist</code></dt>
159 <dd>
160 <p><code class="FUNCTION">pg_connect</code> opens a new database connection using the parameters taken from the <tt class="LITERAL">connectNameValuelist</tt> list. The parameters are exactly the same for the New Style, but they are stored as a Tcl list, instead of a string. The list is a name value pair, for example: <tt class="COMMAND">[list host localhost port 5400 dbname template1]</tt>.</p>
161 <pre class="PROGRAMLISTING">array set conninfo {
162 host 192.168.123.180
163 port 5801
164 dbname template1
165 user postgres
166 }
167 set conn [pg::connect -connlist [array get ::conninfo]]</pre></dd>
168 <dt><code class="OPTION">-async <code class="PARAMETER">bool</code></code></dt>
169 <dd>
170 <p>Connect asyncronously if [<span class="OPTIONAL">bool</span>] is true.</p>
171 </dd>
172 <dt><code class="OPTION">-connhandle <code class="PARAMETER">connectionHandleName</code></code></dt>
173 <dd>
174 <p>Name to use for the connection handle, instead of pgtcl generating the name automatically. Without the option, the name is auto-generated, prefixed with pgsql, and with a numeric id at the end. This gives the programmer control over the name of the connection handle.</p>
175 </dd>
176 </dl>
177 </div>
178 </div>
179 <div class="REFSECT1"><a name="AEN592" id="AEN592"></a>
180 <h2>Return Value</h2>
181 <p>If successful, a handle for a database connection is returned. Handles start with the prefix <tt class="LITERAL">pgsql</tt>.</p>
182 </div>
183 <div class="NAVFOOTER">
184 <hr align="left" width="100%">
185 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
186 <tr>
187 <td width="33%" align="left" valign="top"><a href="libpgtcl-ref.html" accesskey="P">Prev</a></td>
188 <td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td>
189 <td width="33%" align="right" valign="top"><a href="pgtcl-pgconninfo.html" accesskey="N">Next</a></td>
190 </tr>
191 <tr>
192 <td width="33%" align="left" valign="top"><span class="APPLICATION">pgtcl</span> Command Reference</td>
193 <td width="34%" align="center" valign="top"><a href="libpgtcl-ref.html" accesskey="U">Up</a></td>
194 <td width="33%" align="right" valign="top">pg_dbinfo</td>
195 </tr>
196 </table>
197 </div>
198 </body>
199 </html>