aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-04-01 20:00:07 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-04-01 20:00:07 -0300
commitf4540cae10d8642b59deea50869888b78f16d722 (patch)
tree9a34fcc3026a4516d3e7d1e6cd6f28190e065370 /doc/src
parent44f8f56e6d7b5f19276dbe55c4305b54afddc0b9 (diff)
downloadpostgresql-f4540cae10d8642b59deea50869888b78f16d722.tar.gz
postgresql-f4540cae10d8642b59deea50869888b78f16d722.zip
psql: fix \connect with URIs and conninfo strings
psql was already accepting conninfo strings as the first parameter in \connect, but the way it worked wasn't sane; some of the other parameters would get the previous connection's values, causing it to connect to a completely unexpected server or, more likely, not finding any server at all because of completely wrong combinations of parameters. Fix by explicitely checking for a conninfo-looking parameter in the dbname position; if one is found, use its complete specification rather than mix with the other arguments. Also, change tab-completion to not try to complete conninfo/URI-looking "dbnames" and document that conninfos are accepted as first argument. There was a weak consensus to backpatch this, because while the behavior of using the dbname as a conninfo is nowhere documented for \connect, it is reasonable to expect that it works because it does work in many other contexts. Therefore this is backpatched all the way back to 9.0. To implement this, routines previously private to libpq have been duplicated so that psql can decide what looks like a conninfo/URI string. In back branches, just duplicate the same code all the way back to 9.2, where URIs where introduced; 9.0 and 9.1 have a simpler version. In master, the routines are moved to src/common and renamed. Author: David Fetter, Andrew Dunstan. Some editorialization by me (probably earning a Gierth's "Sloppy" badge in the process.) Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost, Robert Haas, Andrew Dunstan.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml40
1 files changed, 29 insertions, 11 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ca1daea838d..4e7d2eb249c 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -772,23 +772,31 @@ testdb=&gt;
</varlistentry>
<varlistentry>
- <term><literal>\c</literal> or <literal>\connect</literal> <literal>[ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] ]</literal></term>
+ <term><literal>\c</literal> or <literal>\connect</literal> <literal>[ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] ] | <replaceable class="parameter">conninfo</replaceable> </literal></term>
<listitem>
<para>
Establishes a new connection to a <productname>PostgreSQL</>
- server. If the new connection is successfully made, the
- previous connection is closed. If any of <replaceable
- class="parameter">dbname</replaceable>, <replaceable
- class="parameter">username</replaceable>, <replaceable
- class="parameter">host</replaceable> or <replaceable
- class="parameter">port</replaceable> are omitted or specified
- as <literal>-</literal>, the value of that parameter from the
- previous connection is used. If there is no previous
- connection, the <application>libpq</application> default for
- the parameter's value is used.
+ server. The connection parameters to use can be specified either
+ using a positional syntax, or using <literal>conninfo</> connection
+ strings as detailed in <xref linkend="libpq-connstring">.
</para>
<para>
+ When using positional parameters, if any of
+ <replaceable class="parameter">dbname</replaceable>,
+ <replaceable class="parameter">username</replaceable>,
+ <replaceable class="parameter">host</replaceable> or
+ <replaceable class="parameter">port</replaceable> are omitted or
+ specified as <literal>-</literal>, the value of that parameter from
+ the previous connection is used; if there is no previous connection,
+ the <application>libpq</application> default for the parameter's value
+ is used. When using <literal>conninfo</> strings, no values from the
+ previous connection are used for the new connection.
+ </para>
+
+ <para>
+ If the new connection is successfully made, the previous
+ connection is closed.
If the connection attempt failed (wrong user name, access
denied, etc.), the previous connection will only be kept if
<application>psql</application> is in interactive mode. When
@@ -798,6 +806,16 @@ testdb=&gt;
mechanism that scripts are not accidentally acting on the
wrong database on the other hand.
</para>
+
+ <para>
+ Examples:
+ </para>
+<programlisting>
+=&gt; \c mydb myuser host.dom 6432
+=&gt; \c service=foo
+=&gt; \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"
+=&gt; \c postgresql://tom@localhost/mydb?application_name=myapp
+</programlisting>
</listitem>
</varlistentry>