connection is successfully made, the previous
connection is closed.
If the connection attempt fails (wrong user name, access
denied, etc.), the previous connection will be kept if
<application>psql</application> is in interactive mode. But when
executing a non-interactive script, the old connection is closed
and an error is reported. That may or may not terminate the
script; if it does not, all database-accessing commands will fail
until another <literal>\connect</literal> command is successfully
executed. This distinction was chosen as
a user convenience against typos on the one hand, and a safety
mechanism that scripts are not accidentally acting on the
wrong database on the other hand.
Note that whenever a <literal>\connect</literal> command attempts
to re-use parameters, the values re-used are those of the last
successful connection, not of any failed attempts made subsequently.
However, in the case of a
non-interactive <literal>\connect</literal> failure, no parameters
are allowed to be re-used later, since the script would likely be
expecting the values from the failed <literal>\connect</literal>
to be re-used.
</para>
<para>
Examples:
</para>
<programlisting>
=> \c mydb myuser host.dom 6432
=> \c service=foo
=> \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"
=> \c -reuse-previous=on sslmode=require -- changes only sslmode
=> \c postgresql://tom@localhost/mydb?application_name=myapp
</programlisting>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-c-uc">
<term><literal>\C [ <replaceable class="parameter">title</replaceable> ]</literal></term>
<listitem>
<para>
Sets the title of any tables being printed as the result of a
query or unset any such title. This command is equivalent to
<literal>\pset title <replaceable
class="parameter">title</replaceable></literal>. (The name of
this command derives from <quote>caption</quote>, as it was
previously only used to set the caption in an
<acronym>HTML</acronym> table.)
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-cd">
<term><literal>\cd [ <replaceable>directory</replaceable> ]</literal></term>
<listitem>
<para>
Changes the current working directory to
<replaceable>directory</replaceable>. Without argument, changes
to the current user's home directory. For details on how home
directories are found, see <xref linkend="libpq-pgpass"/>.
</para>
<tip>
<para>
To print your current working directory, use <literal>\! pwd</literal>.
</para>
</tip>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-close">
<term><literal>\close</literal> <replaceable class="parameter">prepared_statement_name</replaceable></term>
<listitem>
<para>
Closes the specified prepared statement. An empty string denotes the
unnamed prepared statement. If no prepared statement exists with this
name, the operation is a no-op.
</para>
<para>
Example:
<programlisting>
SELECT $1 \parse stmt1
\close stmt1
</programlisting>
</para>
<para>
This command causes the extended query protocol to be used,
unlike normal <application>psql</application> operation, which
uses the simple query protocol. So this command can be useful
to test the extended query protocol from
<application>psql</application>.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-conninfo">
<term><literal>\conninfo</literal></term>