OSDN Git Service

eaf901d328df53925896ed7600b2cf89d2825434
[pg-rex/syncrep.git] / doc / src / sgml / ref / psql-ref.sgml
1 <!--
2 doc/src/sgml/ref/psql-ref.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="APP-PSQL">
7   <refmeta>
8     <refentrytitle><application>psql</application></refentrytitle>
9     <manvolnum>1</manvolnum>
10     <refmiscinfo>Application</refmiscinfo>
11   </refmeta>
12
13   <refnamediv>
14     <refname><application>psql</application></refname>
15     <refpurpose>
16       <productname>PostgreSQL</productname> interactive terminal
17     </refpurpose>
18   </refnamediv>
19
20  <indexterm zone="app-psql">
21   <primary>psql</primary>
22  </indexterm>
23
24  <refsynopsisdiv>
25   <cmdsynopsis>
26    <command>psql</command>
27    <arg rep="repeat"><replaceable class="parameter">option</replaceable></arg>
28    <arg><replaceable class="parameter">dbname</replaceable>
29    <arg><replaceable class="parameter">username</replaceable></arg></arg>
30   </cmdsynopsis>
31  </refsynopsisdiv>
32
33  <refsect1>
34   <title>Description</title>
35
36     <para>
37      <application>psql</application> is a terminal-based front-end to
38      <productname>PostgreSQL</productname>. It enables you to type in
39      queries interactively, issue them to
40      <productname>PostgreSQL</productname>, and see the query results.
41      Alternatively, input can be from a file. In addition, it provides a
42      number of meta-commands and various shell-like features to
43      facilitate writing scripts and automating a wide variety of tasks.
44     </para>
45  </refsect1>
46
47  <refsect1 id="R1-APP-PSQL-3">
48   <title>Options</title>
49
50   <variablelist>
51     <varlistentry>
52       <term><option>-a</></term>
53       <term><option>--echo-all</></term>
54       <listitem>
55       <para>
56       Print all input lines to standard output as they are read. This is more
57       useful for script processing than interactive mode. This is
58       equivalent to setting the variable <varname>ECHO</varname> to
59       <literal>all</literal>.
60       </para>
61       </listitem>
62     </varlistentry>
63
64     <varlistentry>
65       <term><option>-A</></term>
66       <term><option>--no-align</></term>
67       <listitem>
68       <para>
69       Switches to unaligned output mode. (The default output mode is
70       otherwise aligned.)
71       </para>
72       </listitem>
73     </varlistentry>
74
75     <varlistentry>
76       <term><option>-c <replaceable class="parameter">command</replaceable></></term>
77       <term><option>--command=<replaceable class="parameter">command</replaceable></></term>
78       <listitem>
79       <para>
80       Specifies that <application>psql</application> is to execute one
81       command string, <replaceable class="parameter">command</replaceable>,
82       and then exit. This is useful in shell scripts. Start-up files
83       (<filename>psqlrc</filename> and <filename>~/.psqlrc</filename>) are
84       ignored with this option.
85       </para>
86       <para>
87       <replaceable class="parameter">command</replaceable> must be either
88       a command string that is completely parsable by the server (i.e.,
89       it contains no <application>psql</application>-specific features),
90       or a single backslash command. Thus you cannot mix
91       <acronym>SQL</acronym> and <application>psql</application>
92       meta-commands with this option. To achieve that, you could
93       pipe the string into <application>psql</application>, like
94       this: <literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
95       (<literal>\\</> is the separator meta-command.)
96       </para>
97       <para>
98        If the command string contains multiple SQL commands, they are
99        processed in a single transaction, unless there are explicit
100        <command>BEGIN</>/<command>COMMIT</> commands included in the
101        string to divide it into multiple transactions.  This is
102        different from the behavior when the same string is fed to
103        <application>psql</application>'s standard input.
104       </para>
105       </listitem>
106     </varlistentry>
107
108     <varlistentry>
109       <term><option>-d <replaceable class="parameter">dbname</replaceable></></term>
110       <term><option>--dbname=<replaceable class="parameter">dbname</replaceable></></term>
111       <listitem>
112       <para>
113        Specifies the name of the database to connect to. This is
114        equivalent to specifying <replaceable
115        class="parameter">dbname</replaceable> as the first non-option
116        argument on the command line.
117       </para>
118       <para>
119        If this parameter contains an <symbol>=</symbol> sign, it is treated as a
120        <parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information.
121       </para>
122       </listitem>
123     </varlistentry>
124
125     <varlistentry>
126       <term><option>-e</></term>
127       <term><option>--echo-queries</></term>
128       <listitem>
129       <para>
130       Copy all SQL commands sent to the server to standard output as well.
131       This is equivalent
132       to setting the variable <varname>ECHO</varname> to
133       <literal>queries</literal>.
134       </para>
135       </listitem>
136     </varlistentry>
137
138     <varlistentry>
139       <term><option>-E</></term>
140       <term><option>--echo-hidden</></term>
141       <listitem>
142       <para>
143       Echo the actual queries generated by <command>\d</command> and other backslash
144       commands. You can use this to study <application>psql</application>'s
145       internal operations. This is equivalent to
146       setting the variable <varname>ECHO_HIDDEN</varname> from within
147       <application>psql</application>.
148       </para>
149       </listitem>
150     </varlistentry>
151
152     <varlistentry>
153       <term><option>-f <replaceable class="parameter">filename</replaceable></></term>
154       <term><option>--file=<replaceable class="parameter">filename</replaceable></></term>
155       <listitem>
156       <para>
157       Use the file <replaceable class="parameter">filename</replaceable>
158       as the source of commands instead of reading commands interactively.
159       After the file is processed, <application>psql</application>
160       terminates. This is in many ways equivalent to the internal
161       command <command>\i</command>.
162       </para>
163
164       <para>
165        If <replaceable>filename</replaceable> is <literal>-</literal>
166        (hyphen), then standard input is read.
167       </para>
168
169       <para>
170       Using this option is subtly different from writing <literal>psql
171       &lt; <replaceable
172       class="parameter">filename</replaceable></literal>. In general,
173       both will do what you expect, but using <literal>-f</literal>
174       enables some nice features such as error messages with line
175       numbers. There is also a slight chance that using this option will
176       reduce the start-up overhead. On the other hand, the variant using
177       the shell's input redirection is (in theory) guaranteed to yield
178       exactly the same output you would have received had you entered
179       everything by hand.
180       </para>
181       </listitem>
182     </varlistentry>
183
184     <varlistentry>
185       <term><option>-F <replaceable class="parameter">separator</replaceable></></term>
186       <term><option>--field-separator=<replaceable class="parameter">separator</replaceable></></term>
187       <listitem>
188       <para>
189       Use <replaceable class="parameter">separator</replaceable> as the
190       field separator for unaligned output. This is equivalent to
191       <command>\pset fieldsep</command> or <command>\f</command>.
192       </para>
193       </listitem>
194     </varlistentry>
195
196     <varlistentry>
197       <term><option>-h <replaceable class="parameter">hostname</replaceable></></term>
198       <term><option>--host=<replaceable class="parameter">hostname</replaceable></></term>
199       <listitem>
200       <para>
201       Specifies the host name of the machine on which the
202       server is running. If the value begins
203       with a slash, it is used as the directory for the Unix-domain
204       socket.
205       </para>
206       </listitem>
207     </varlistentry>
208
209     <varlistentry>
210       <term><option>-H</></term>
211       <term><option>--html</></term>
212       <listitem>
213       <para>
214       Turn on <acronym>HTML</acronym> tabular output. This is
215       equivalent to <literal>\pset format html</literal> or the
216       <command>\H</command> command.
217       </para>
218       </listitem>
219     </varlistentry>
220
221     <varlistentry>
222       <term><option>-l</></term>
223       <term><option>--list</></term>
224       <listitem>
225       <para>
226       List all available databases, then exit. Other non-connection
227       options are ignored. This is similar to the internal command
228       <command>\list</command>.
229       </para>
230       </listitem>
231     </varlistentry>
232
233     <varlistentry>
234       <term><option>-L <replaceable class="parameter">filename</replaceable></></term>
235       <term><option>--log-file=<replaceable class="parameter">filename</replaceable></></term>
236       <listitem>
237       <para>
238        Write all query output into file <replaceable
239        class="parameter">filename</replaceable>, in addition to the
240        normal output destination.
241       </para>
242       </listitem>
243     </varlistentry>
244
245     <varlistentry>
246       <term><option>-n</></term>
247       <term><option>--no-readline</></term>
248       <listitem>
249       <para>
250        Do not use readline for line editing and do not use the history.
251        This can be useful to turn off tab expansion when cutting and pasting.
252       </para>
253       </listitem>
254     </varlistentry>
255
256     <varlistentry>
257       <term><option>-o <replaceable class="parameter">filename</replaceable></></term>
258       <term><option>--output=<replaceable class="parameter">filename</replaceable></></term>
259       <listitem>
260       <para>
261       Put all query output into file <replaceable
262       class="parameter">filename</replaceable>. This is equivalent to
263       the command <command>\o</command>.
264       </para>
265       </listitem>
266     </varlistentry>
267
268     <varlistentry>
269       <term><option>-p <replaceable class="parameter">port</replaceable></></term>
270       <term><option>--port=<replaceable class="parameter">port</replaceable></></term>
271       <listitem>
272       <para>
273       Specifies the TCP port or the local Unix-domain
274       socket file extension on which the server is listening for
275       connections. Defaults to the value of the <envar>PGPORT</envar>
276       environment variable or, if not set, to the port specified at
277       compile time, usually 5432.
278       </para>
279       </listitem>
280     </varlistentry>
281
282     <varlistentry>
283       <term><option>-P <replaceable class="parameter">assignment</replaceable></></term>
284       <term><option>--pset=<replaceable class="parameter">assignment</replaceable></></term>
285       <listitem>
286       <para>
287       Specifies printing options, in the style of
288       <command>\pset</command>. Note that here you
289       have to separate name and value with an equal sign instead of a
290       space. For example, to set the output format to LaTeX, you could write
291       <literal>-P format=latex</literal>.
292       </para>
293       </listitem>
294     </varlistentry>
295
296     <varlistentry>
297       <term><option>-q</></term>
298       <term><option>--quiet</></term>
299       <listitem>
300       <para>
301       Specifies that <application>psql</application> should do its work
302       quietly. By default, it prints welcome messages and various
303       informational output. If this option is used, none of this
304       happens. This is useful with the <option>-c</option> option.
305       Within <application>psql</application> you can also set the
306       <varname>QUIET</varname> variable to achieve the same effect.
307       </para>
308       </listitem>
309     </varlistentry>
310
311     <varlistentry>
312       <term><option>-R <replaceable class="parameter">separator</replaceable></></term>
313       <term><option>--record-separator=<replaceable class="parameter">separator</replaceable></></term>
314       <listitem>
315       <para>
316       Use <replaceable class="parameter">separator</replaceable> as the
317       record separator for unaligned output. This is equivalent to the
318       <command>\pset recordsep</command> command.
319       </para>
320       </listitem>
321     </varlistentry>
322
323     <varlistentry>
324       <term><option>-s</></term>
325       <term><option>--single-step</></term>
326       <listitem>
327       <para>
328       Run in single-step mode. That means the user is prompted before
329       each command is sent to the server, with the option to cancel
330       execution as well. Use this to debug scripts.
331       </para>
332       </listitem>
333     </varlistentry>
334
335     <varlistentry>
336       <term><option>-S</></term>
337       <term><option>--single-line</></term>
338       <listitem>
339       <para>
340       Runs in single-line mode where a newline terminates an SQL command, as a
341       semicolon does.
342       </para>
343
344       <note>
345       <para>
346       This mode is provided for those who insist on it, but you are not
347       necessarily encouraged to use it. In particular, if you mix
348       <acronym>SQL</acronym> and meta-commands on a line the order of
349       execution might not always be clear to the inexperienced user.
350       </para>
351       </note>
352       </listitem>
353     </varlistentry>
354
355     <varlistentry>
356       <term><option>-t</></term>
357       <term><option>--tuples-only</></term>
358       <listitem>
359       <para>
360       Turn off printing of column names and result row count footers,
361       etc. This is equivalent to the <command>\t</command> command.
362       </para>
363       </listitem>
364     </varlistentry>
365
366     <varlistentry>
367       <term><option>-T <replaceable class="parameter">table_options</replaceable></></term>
368       <term><option>--table-attr=<replaceable class="parameter">table_options</replaceable></></term>
369       <listitem>
370       <para>
371       Specifies options to be placed within the
372       <acronym>HTML</acronym> <sgmltag>table</sgmltag> tag. See
373       <command>\pset</command> for details.
374       </para>
375       </listitem>
376     </varlistentry>
377
378     <varlistentry>
379       <term><option>-U <replaceable class="parameter">username</replaceable></></term>
380       <term><option>--username=<replaceable class="parameter">username</replaceable></></term>
381       <listitem>
382       <para>
383       Connect to the database as the user <replaceable
384       class="parameter">username</replaceable> instead of the default.
385       (You must have permission to do so, of course.)
386       </para>
387       </listitem>
388     </varlistentry>
389
390     <varlistentry>
391       <term><option>-v <replaceable class="parameter">assignment</replaceable></></term>
392       <term><option>--set=<replaceable class="parameter">assignment</replaceable></></term>
393       <term><option>--variable=<replaceable class="parameter">assignment</replaceable></></term>
394       <listitem>
395       <para>
396       Perform a variable assignment, like the <command>\set</command>
397       internal command. Note that you must separate name and value, if
398       any, by an equal sign on the command line. To unset a variable,
399       leave off the equal sign. To just set a variable without a value,
400       use the equal sign but leave off the value. These assignments are
401       done during a very early stage of start-up, so variables reserved
402       for internal purposes might get overwritten later.
403       </para>
404       </listitem>
405     </varlistentry>
406
407     <varlistentry>
408       <term><option>-V</></term>
409       <term><option>--version</></term>
410       <listitem>
411       <para>
412       Print the <application>psql</application> version and exit.
413       </para>
414       </listitem>
415     </varlistentry>
416
417     <varlistentry>
418      <term><option>-w</></term>
419      <term><option>--no-password</></term>
420      <listitem>
421       <para>
422        Never issue a password prompt.  If the server requires password
423        authentication and a password is not available by other means
424        such as a <filename>.pgpass</filename> file, the connection
425        attempt will fail.  This option can be useful in batch jobs and
426        scripts where no user is present to enter a password.
427       </para>
428
429       <para>
430        Note that this option will remain set for the entire session,
431        and so it affects uses of the meta-command
432        <command>\connect</command> as well as the initial connection attempt.
433       </para>
434      </listitem>
435     </varlistentry>
436
437     <varlistentry>
438       <term><option>-W</></term>
439       <term><option>--password</></term>
440       <listitem>
441       <para>
442        Force <application>psql</application> to prompt for a
443        password before connecting to a database.
444       </para>
445
446       <para>
447        This option is never essential, since <application>psql</application>
448        will automatically prompt for a password if the server demands
449        password authentication.  However, <application>psql</application>
450        will waste a connection attempt finding out that the server wants a
451        password.  In some cases it is worth typing <option>-W</> to avoid
452        the extra connection attempt.
453       </para>
454
455       <para>
456        Note that this option will remain set for the entire session,
457        and so it affects uses of the meta-command
458        <command>\connect</command> as well as the initial connection attempt.
459       </para>
460       </listitem>
461     </varlistentry>
462
463     <varlistentry>
464       <term><option>-x</></term>
465       <term><option>--expanded</></term>
466       <listitem>
467       <para>
468       Turn on the expanded table formatting mode. This is equivalent to the
469       <command>\x</command> command.
470       </para>
471       </listitem>
472     </varlistentry>
473
474     <varlistentry>
475       <term><option>-X,</></term>
476       <term><option>--no-psqlrc</></term>
477       <listitem>
478       <para>
479       Do not read the start-up file (neither the system-wide
480       <filename>psqlrc</filename> file nor the user's
481       <filename>~/.psqlrc</filename> file).
482       </para>
483       </listitem>
484     </varlistentry>
485
486      <varlistentry>
487       <term><option>-1</option></term>
488       <term><option>--single-transaction</option></term>
489       <listitem>
490        <para>
491         When <application>psql</application> executes a script with the
492         <option>-f</> option, adding this option wraps
493         <command>BEGIN</>/<command>COMMIT</> around the script to execute it
494         as a single transaction.  This ensures that either all the commands
495         complete successfully, or no changes are applied.
496        </para>
497
498        <para>
499         If the script itself uses <command>BEGIN</>, <command>COMMIT</>,
500         or <command>ROLLBACK</>, this option will not have the desired
501         effects.
502         Also, if the script contains any command that cannot be executed
503         inside a transaction block, specifying this option will cause that
504         command (and hence the whole transaction) to fail.
505        </para>
506       </listitem>
507      </varlistentry>
508
509     <varlistentry>
510       <term><option>-?</></term>
511       <term><option>--help</></term>
512       <listitem>
513       <para>
514       Show help about <application>psql</application> command line
515       arguments, and exit.
516       </para>
517       </listitem>
518     </varlistentry>
519
520   </variablelist>
521  </refsect1>
522
523
524  <refsect1>
525   <title>Exit Status</title>
526
527   <para>
528    <application>psql</application> returns 0 to the shell if it
529    finished normally, 1 if a fatal error of its own occurs (e.g. out of memory,
530    file not found), 2 if the connection to the server went bad
531    and the session was not interactive, and 3 if an error occurred in a
532    script and the variable <varname>ON_ERROR_STOP</varname> was set.
533   </para>
534  </refsect1>
535
536
537  <refsect1>
538   <title>Usage</title>
539
540   <refsect2 id="R2-APP-PSQL-connecting">
541     <title>Connecting to a Database</title>
542
543     <para>
544     <application>psql</application> is a regular
545     <productname>PostgreSQL</productname> client application. In order
546     to connect to a database you need to know the name of your target
547     database, the host name and port number of the server, and what user
548     name you want to connect as. <application>psql</application> can be
549     told about those parameters via command line options, namely
550     <option>-d</option>, <option>-h</option>, <option>-p</option>, and
551     <option>-U</option> respectively. If an argument is found that does
552     not belong to any option it will be interpreted as the database name
553     (or the user name, if the database name is already given). Not all
554     of these options are required; there are useful defaults. If you omit the host
555     name, <application>psql</> will connect via a Unix-domain socket
556     to a server on the local host, or via TCP/IP to <literal>localhost</> on
557     machines that don't have Unix-domain sockets. The default port number is
558     determined at compile time.
559     Since the database server uses the same default, you will not have
560     to specify the port in most cases. The default user name is your
561     Unix user name, as is the default database name. Note that you cannot
562     just connect to any database under any user name. Your database
563     administrator should have informed you about your access rights.
564     </para>
565
566     <para>
567     When the defaults aren't quite right, you can save yourself
568     some typing by setting the environment variables
569     <envar>PGDATABASE</envar>, <envar>PGHOST</envar>,
570     <envar>PGPORT</envar> and/or <envar>PGUSER</envar> to appropriate
571     values. (For additional environment variables, see <xref
572     linkend="libpq-envars">.) It is also convenient to have a
573     <filename>~/.pgpass</> file to avoid regularly having to type in
574     passwords. See <xref linkend="libpq-pgpass"> for more information.
575     </para>
576
577     <para>
578      An alternative way to specify connection parameters is in a
579      <parameter>conninfo</parameter> string, which is used instead of a
580      database name. This mechanism give you very wide control over the
581      connection. For example:
582 <programlisting>
583 $ <userinput>psql "service=myservice sslmode=require"</userinput>
584 </programlisting>
585      This way you can also use LDAP for connection parameter lookup as
586      described in <xref linkend="libpq-ldap">.
587      See <xref linkend="libpq-connect"> for more information on all the
588      available connection options.
589     </para>
590
591     <para>
592     If the connection could not be made for any reason (e.g., insufficient
593     privileges, server is not running on the targeted host, etc.),
594     <application>psql</application> will return an error and terminate.
595     </para>
596
597     <para>
598      If at least one of standard input or standard output are a
599      terminal, then <application>psql</application> sets the client
600      encoding to <quote>auto</quote>, which will detect the
601      appropriate client encoding from the locale settings
602      (<envar>LC_CTYPE</envar> environment variable on Unix systems).
603      If this doesn't work out as expected, the client encoding can be
604      overridden using the environment
605      variable <envar>PGCLIENTENCODING</envar>.
606     </para>
607   </refsect2>
608
609   <refsect2 id="R2-APP-PSQL-4">
610     <title>Entering SQL Commands</title>
611
612     <para>
613     In normal operation, <application>psql</application> provides a
614     prompt with the name of the database to which
615     <application>psql</application> is currently connected, followed by
616     the string <literal>=&gt;</literal>. For example:
617 <programlisting>
618 $ <userinput>psql testdb</userinput>
619 psql (&version;)
620 Type "help" for help.
621
622 testdb=&gt;
623 </programlisting>
624     </para>
625
626     <para>
627     At the prompt, the user can type in <acronym>SQL</acronym> commands.
628     Ordinarily, input lines are sent to the server when a
629     command-terminating semicolon is reached. An end of line does not
630     terminate a command.  Thus commands can be spread over several lines for
631     clarity. If the command was sent and executed without error, the results
632     of the command are displayed on the screen.
633     </para>
634
635     <para>
636     Whenever a command is executed, <application>psql</application> also polls
637     for asynchronous notification events generated by
638     <xref linkend="SQL-LISTEN"> and
639     <xref linkend="SQL-NOTIFY">.
640     </para>
641   </refsect2>
642
643   <refsect2 id="APP-PSQL-meta-commands">
644     <title>Meta-Commands</title>
645
646     <para>
647     Anything you enter in <application>psql</application> that begins
648     with an unquoted backslash is a <application>psql</application>
649     meta-command that is processed by <application>psql</application>
650     itself. These commands make
651     <application>psql</application> more useful for administration or
652     scripting. Meta-commands are often called slash or backslash commands.
653     </para>
654
655     <para>
656     The format of a <application>psql</application> command is the backslash,
657     followed immediately by a command verb, then any arguments. The arguments
658     are separated from the command verb and each other by any number of
659     whitespace characters.
660     </para>
661
662     <para>
663     To include whitespace into an argument you can quote it with a
664     single quote. To include a single quote into such an argument,
665     use two single quotes. Anything contained in single quotes is
666     furthermore subject to C-like substitutions for
667     <literal>\n</literal> (new line), <literal>\t</literal> (tab),
668     <literal>\</literal><replaceable>digits</replaceable> (octal), and
669     <literal>\x</literal><replaceable>digits</replaceable> (hexadecimal).
670     </para>
671
672     <para>
673     If an unquoted argument begins with a colon (<literal>:</literal>),
674     it is taken as a <application>psql</> variable and the value of the
675     variable is used as the argument instead.  If the variable name is
676     surrounded by single quotes (e.g. <literal>:'var'</literal>), it
677     will be escaped as an SQL literal and the result will be used as
678     the argument.  If the variable name is surrounded by double quotes,
679     it will be escaped as an SQL identifier and the result will be used
680     as the argument.
681     </para>
682
683     <para>
684     Arguments that are enclosed in backquotes (<literal>`</literal>)
685     are taken as a command line that is passed to the shell. The
686     output of the command (with any trailing newline removed) is taken
687     as the argument value. The above escape sequences also apply in
688     backquotes.
689     </para>
690
691     <para>
692     Some commands take an <acronym>SQL</acronym> identifier (such as a
693     table name) as argument. These arguments follow the syntax rules
694     of <acronym>SQL</acronym>: Unquoted letters are forced to
695     lowercase, while double quotes (<literal>"</>) protect letters
696     from case conversion and allow incorporation of whitespace into
697     the identifier.  Within double quotes, paired double quotes reduce
698     to a single double quote in the resulting name.  For example,
699     <literal>FOO"BAR"BAZ</> is interpreted as <literal>fooBARbaz</>,
700     and <literal>"A weird"" name"</> becomes <literal>A weird"
701     name</>.
702     </para>
703
704     <para>
705     Parsing for arguments stops at the end of the line, or when another
706     unquoted backslash is found.  An unquoted backslash
707     is taken as the beginning of a new meta-command. The special
708     sequence <literal>\\</literal> (two backslashes) marks the end of
709     arguments and continues parsing <acronym>SQL</acronym> commands, if
710     any. That way <acronym>SQL</acronym> and
711     <application>psql</application> commands can be freely mixed on a
712     line. But in any case, the arguments of a meta-command cannot
713     continue beyond the end of the line.
714     </para>
715
716     <para>
717     The following meta-commands are defined:
718
719     <variablelist>
720       <varlistentry>
721         <term><literal>\a</literal></term>
722         <listitem>
723         <para>
724         If the current table output format is unaligned, it is switched to aligned.
725         If it is not unaligned, it is set to unaligned. This command is
726         kept for backwards compatibility. See <command>\pset</command> for a
727         more general solution.
728         </para>
729         </listitem>
730       </varlistentry>
731
732       <varlistentry>
733         <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>
734         <listitem>
735         <para>
736         Establishes a new connection to a <productname>PostgreSQL</>
737         server. If the new connection is successfully made, the
738         previous connection is closed. If any of <replaceable
739         class="parameter">dbname</replaceable>, <replaceable
740         class="parameter">username</replaceable>, <replaceable
741         class="parameter">host</replaceable> or <replaceable
742         class="parameter">port</replaceable> are omitted or specified
743         as <literal>-</literal>, the value of that parameter from the
744         previous connection is used. If there is no previous
745         connection, the <application>libpq</application> default for
746         the parameter's value is used.
747         </para>
748
749         <para>
750         If the connection attempt failed (wrong user name, access
751         denied, etc.), the previous connection will only be kept if
752         <application>psql</application> is in interactive mode. When
753         executing a non-interactive script, processing will
754         immediately stop with an error. This distinction was chosen as
755         a user convenience against typos on the one hand, and a safety
756         mechanism that scripts are not accidentally acting on the
757         wrong database on the other hand.
758         </para>
759         </listitem>
760       </varlistentry>
761
762       <varlistentry>
763         <term><literal>\C [ <replaceable class="parameter">title</replaceable> ]</literal></term>
764         <listitem>
765         <para>
766         Sets the title of any tables being printed as the result of a
767         query or unset any such title. This command is equivalent to
768         <literal>\pset title <replaceable
769         class="parameter">title</replaceable></literal>. (The name of
770         this command derives from <quote>caption</quote>, as it was
771         previously only used to set the caption in an
772         <acronym>HTML</acronym> table.)
773         </para>
774         </listitem>
775       </varlistentry>
776
777       <varlistentry>
778        <term><literal>\cd [ <replaceable>directory</replaceable> ]</literal></term>
779        <listitem>
780         <para>
781          Changes the current working directory to
782          <replaceable>directory</replaceable>. Without argument, changes
783          to the current user's home directory.
784         </para>
785
786         <tip>
787          <para>
788           To print your current working directory, use <literal>\! pwd</literal>.
789          </para>
790         </tip>
791        </listitem>
792       </varlistentry>
793
794       <varlistentry>
795         <term><literal>\conninfo</literal></term>
796         <listitem>
797         <para>
798         Outputs information about the current database connection.
799         </para>
800         </listitem>
801       </varlistentry>
802
803       <varlistentry>
804         <term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
805         { <literal>from</literal> | <literal>to</literal> }
806         { <replaceable class="parameter">filename</replaceable> | stdin | stdout | pstdin | pstdout }
807         [ with ]
808             [ binary ]
809             [ oids ]
810             [ delimiter [ as ] '<replaceable class="parameter">character</replaceable>' ]
811             [ null [ as ] '<replaceable class="parameter">string</replaceable>' ]
812             [ csv
813               [ header ]
814               [ quote [ as ] '<replaceable class="parameter">character</replaceable>' ]
815               [ escape [ as ] '<replaceable class="parameter">character</replaceable>' ]
816               [ force quote <replaceable class="parameter">column_list</replaceable> | * ]
817               [ force not null <replaceable class="parameter">column_list</replaceable> ] ]</literal>
818         </term>
819
820         <listitem>
821         <para>
822         Performs a frontend (client) copy. This is an operation that
823         runs an <acronym>SQL</acronym> <xref linkend="SQL-COPY">
824         command, but instead of the server
825         reading or writing the specified file,
826         <application>psql</application> reads or writes the file and
827         routes the data between the server and the local file system.
828         This means that file accessibility and privileges are those of
829         the local user, not the server, and no SQL superuser
830         privileges are required.
831         </para>
832
833         <para>
834         The syntax of the command is similar to that of the
835         <acronym>SQL</acronym> <xref linkend="sql-copy">
836         command.  Note that, because of this,
837         special parsing rules apply to the <command>\copy</command>
838         command. In particular, the variable substitution rules and
839         backslash escapes do not apply.
840         </para>
841
842         <para>
843         <literal>\copy ... from stdin | to stdout</literal>
844         reads/writes based on the command input and output respectively.
845         All rows are read from the same source that issued the command,
846         continuing until <literal>\.</literal> is read or the stream
847         reaches <acronym>EOF</>. Output is sent to the same place as
848         command output. To read/write from
849         <application>psql</application>'s standard input or output, use
850         <literal>pstdin</> or <literal>pstdout</>. This option is useful
851         for populating tables in-line within a SQL script file.
852         </para>
853
854         <tip>
855         <para>
856         This operation is not as efficient as the <acronym>SQL</acronym>
857         <command>COPY</command> command because all data must pass
858         through the client/server connection. For large
859         amounts of data the <acronym>SQL</acronym> command might be preferable.
860         </para>
861         </tip>
862
863         </listitem>
864       </varlistentry>
865
866       <varlistentry>
867         <term><literal>\copyright</literal></term>
868         <listitem>
869         <para>
870         Shows the copyright and distribution terms of
871         <productname>PostgreSQL</productname>.
872         </para>
873         </listitem>
874       </varlistentry>
875
876       <varlistentry>
877         <term><literal>\d[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
878
879         <listitem>
880         <para>
881         For each relation (table, view, index, sequence or foreign table)
882         matching the
883         <replaceable class="parameter">pattern</replaceable>, show all
884         columns, their types, the tablespace (if not the default) and any
885         special attributes such as <literal>NOT NULL</literal> or defaults.
886         Associated indexes, constraints, rules, and triggers are
887         also shown.  For foreign tables, the associated foreign
888         server is shown as well.
889         (<quote>Matching the pattern</> is defined in
890         <xref linkend="APP-PSQL-patterns" endterm="APP-PSQL-patterns-title">
891         below.)
892         </para>
893
894         <para>
895         The command form <literal>\d+</literal> is identical, except that
896         more information is displayed: any comments associated with the
897         columns of the table are shown, as is the presence of OIDs in the
898         table, the view definition if the relation is a view, and the generic
899         options if the relation is a foreign table.
900         </para>
901
902         <para>
903         By default, only user-created objects are shown;  supply a
904         pattern or the <literal>S</literal> modifier to include system
905         objects.
906         </para>
907
908         <note>
909         <para>
910         If <command>\d</command> is used without a
911         <replaceable class="parameter">pattern</replaceable> argument, it is
912         equivalent to <command>\dtvsE</command> which will show a list of
913         all visible tables, views, sequences and foreign tables.
914         This is purely a convenience measure.
915         </para>
916         </note>
917         </listitem>
918       </varlistentry>
919
920       <varlistentry>
921         <term><literal>\da[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
922
923         <listitem>
924         <para>
925         Lists aggregate functions, together with their
926         return type and the data types they operate on. If <replaceable
927         class="parameter">pattern</replaceable>
928         is specified, only aggregates whose names match the pattern are shown.
929         By default, only user-created objects are shown;  supply a
930         pattern or the <literal>S</literal> modifier to include system
931         objects.
932         </para>
933         </listitem>
934       </varlistentry>
935
936
937       <varlistentry>
938         <term><literal>\db[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
939
940         <listitem>
941         <para>
942         Lists tablespaces. If <replaceable
943         class="parameter">pattern</replaceable>
944         is specified, only tablespaces whose names match the pattern are shown.
945         If <literal>+</literal> is appended to the command name, each object
946         is listed with its associated permissions.
947         </para>
948         </listitem>
949       </varlistentry>
950
951
952       <varlistentry>
953         <term><literal>\dc[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
954         <listitem>
955         <para>
956         Lists conversions between character-set encodings.
957         If <replaceable class="parameter">pattern</replaceable>
958         is specified, only conversions whose names match the pattern are
959         listed.
960         By default, only user-created objects are shown;  supply a
961         pattern or the <literal>S</literal> modifier to include system
962         objects.
963         </para>
964         </listitem>
965       </varlistentry>
966
967
968       <varlistentry>
969         <term><literal>\dC [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
970         <listitem>
971         <para>
972         Lists type casts.
973         If <replaceable class="parameter">pattern</replaceable>
974         is specified, only casts whose source or target types match the
975         pattern are listed.
976         </para>
977         </listitem>
978       </varlistentry>
979
980
981       <varlistentry>
982         <term><literal>\dd[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
983         <listitem>
984         <para>
985         Shows the descriptions of objects matching the <replaceable
986         class="parameter">pattern</replaceable>, or of all visible objects if
987         no argument is given.  But in either case, only objects that have
988         a description are listed.
989         By default, only user-created objects are shown;  supply a
990         pattern or the <literal>S</literal> modifier to include system
991         objects.
992         <quote>Object</quote> covers aggregates, functions, operators,
993         types, relations (tables, views, indexes, sequences), large
994         objects, rules, and triggers. For example:
995 <programlisting>
996 =&gt; <userinput>\dd version</userinput>
997                      Object descriptions
998    Schema   |  Name   |  Object  |        Description
999 ------------+---------+----------+---------------------------
1000  pg_catalog | version | function | PostgreSQL version string
1001 (1 row)
1002 </programlisting>
1003         </para>
1004
1005         <para>
1006         Descriptions for objects can be created with the <xref
1007         linkend="sql-comment">
1008         <acronym>SQL</acronym> command.
1009        </para>
1010         </listitem>
1011       </varlistentry>
1012
1013
1014       <varlistentry>
1015         <term><literal>\ddp [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1016         <listitem>
1017         <para>
1018         Lists default access privilege settings.  An entry is shown for
1019         each role (and schema, if applicable) for which the default
1020         privilege settings have been changed from the built-in defaults.
1021         If <replaceable class="parameter">pattern</replaceable> is
1022         specified, only entries whose role name or schema name matches
1023         the pattern are listed.
1024         </para>
1025
1026         <para>
1027         The <xref linkend="sql-alterdefaultprivileges"> command is used to set
1028         default access privileges.  The meaning of the
1029         privilege display is explained under
1030         <xref linkend="sql-grant">.
1031         </para>
1032         </listitem>
1033       </varlistentry>
1034
1035
1036       <varlistentry>
1037         <term><literal>\dD[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1038         <listitem>
1039         <para>
1040         Lists domains. If <replaceable
1041         class="parameter">pattern</replaceable>
1042         is specified, only domains whose names match the pattern are shown.
1043         By default, only user-created objects are shown;  supply a
1044         pattern or the <literal>S</literal> modifier to include system
1045         objects.
1046         </para>
1047         </listitem>
1048       </varlistentry>
1049
1050
1051       <varlistentry>
1052         <term><literal>\dE[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1053         <term><literal>\di[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1054         <term><literal>\ds[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1055         <term><literal>\dt[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1056         <term><literal>\dv[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1057
1058         <listitem>
1059         <para>
1060         In this group of commands, the letters <literal>E</literal>,
1061         <literal>i</literal>, <literal>s</literal>,
1062         <literal>t</literal>, and <literal>v</literal>
1063         stand for foreign table, index, sequence, table, and view,
1064         respectively.
1065         You can specify any or all of
1066         these letters, in any order, to obtain a listing of objects
1067         of these types.  For example, <literal>\dit</> lists indexes
1068         and tables.  If <literal>+</literal> is
1069         appended to the command name, each object is listed with its
1070         physical size on disk and its associated description, if any.
1071         If <replaceable class="parameter">pattern</replaceable> is
1072         specified, only objects whose names match the pattern are listed.
1073         By default, only user-created objects are shown; supply a
1074         pattern or the <literal>S</literal> modifier to include system
1075         objects.
1076         </para>
1077         </listitem>
1078       </varlistentry>
1079
1080
1081       <varlistentry>
1082         <term><literal>\des[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1083         <listitem>
1084         <para>
1085         Lists foreign servers (mnemonic: <quote>external
1086         servers</quote>).
1087         If <replaceable class="parameter">pattern</replaceable> is
1088         specified, only those servers whose name matches the pattern
1089         are listed.  If the form <literal>\des+</literal> is used, a
1090         full description of each server is shown, including the
1091         server's ACL, type, version, and options.
1092         </para>
1093         </listitem>
1094       </varlistentry>
1095
1096
1097       <varlistentry>
1098         <term><literal>\det[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1099         <listitem>
1100         <para>
1101         Lists foreign tables (mnemonic: <quote>external tables</quote>).
1102         If <replaceable class="parameter">pattern</replaceable> is
1103         specified, only entries whose table name or schema name matches
1104         the pattern are listed.  If the form <literal>\det+</literal>
1105         is used, generic options are also displayed.
1106         </para>
1107         </listitem>
1108       </varlistentry>
1109
1110
1111       <varlistentry>
1112         <term><literal>\deu[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1113         <listitem>
1114         <para>
1115         Lists user mappings (mnemonic: <quote>external
1116         users</quote>).
1117         If <replaceable class="parameter">pattern</replaceable> is
1118         specified, only those mappings whose user names match the
1119         pattern are listed.  If the form <literal>\deu+</literal> is
1120         used, additional information about each mapping is shown.
1121         </para>
1122
1123         <caution>
1124         <para>
1125         <literal>\deu+</literal> might also display the user name and
1126         password of the remote user, so care should be taken not to
1127         disclose them.
1128         </para>
1129         </caution>
1130         </listitem>
1131       </varlistentry>
1132
1133
1134       <varlistentry>
1135         <term><literal>\dew[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1136         <listitem>
1137         <para>
1138         Lists foreign-data wrappers (mnemonic: <quote>external
1139         wrappers</quote>).
1140         If <replaceable class="parameter">pattern</replaceable> is
1141         specified, only those foreign-data wrappers whose name matches
1142         the pattern are listed.  If the form <literal>\dew+</literal>
1143         is used, the ACL and options of the foreign-data wrapper are
1144         also shown.
1145         </para>
1146         </listitem>
1147       </varlistentry>
1148
1149
1150       <varlistentry>
1151         <term><literal>\df[antwS+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1152
1153         <listitem>
1154         <para>
1155         Lists functions, together with their arguments, return types, and
1156         function types, which are classified as <quote>agg</> (aggregate),
1157         <quote>normal</>, <quote>trigger</>, or <quote>window</>.
1158         To display only functions
1159         of specific type(s), add the corresponding letters <literal>a</>,
1160         <literal>n</>, <literal>t</>, or <literal>w</> to the command.
1161         If <replaceable
1162         class="parameter">pattern</replaceable> is specified, only
1163         functions whose names match the pattern are shown.  If the
1164         form <literal>\df+</literal> is used, additional information
1165         about each function, including volatility, language, source
1166         code and description, is shown.  By default, only user-created
1167         objects are shown; supply a pattern or the <literal>S</literal>
1168         modifier to include system objects.
1169         </para>
1170
1171         <tip>
1172         <para>
1173         To look up functions taking arguments or returning values of a specific
1174         type, use your pager's search capability to scroll through the
1175         <literal>\df</> output.
1176         </para>
1177         </tip>
1178
1179         </listitem>
1180       </varlistentry>
1181
1182       <varlistentry>
1183         <term><literal>\dF[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1184         <listitem>
1185         <para>
1186          Lists text search configurations.
1187          If <replaceable class="parameter">pattern</replaceable> is specified,
1188          only configurations whose names match the pattern are shown.
1189          If the form <literal>\dF+</literal> is used, a full description of
1190          each configuration is shown, including the underlying text search
1191          parser and the dictionary list for each parser token type.
1192         </para>
1193         </listitem>
1194       </varlistentry>
1195
1196       <varlistentry>
1197         <term><literal>\dFd[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1198         <listitem>
1199         <para>
1200          Lists text search dictionaries.
1201          If <replaceable class="parameter">pattern</replaceable> is specified,
1202          only dictionaries whose names match the pattern are shown.
1203          If the form <literal>\dFd+</literal> is used, additional information
1204          is shown about each selected dictionary, including the underlying
1205          text search template and the option values.
1206         </para>
1207         </listitem>
1208       </varlistentry>
1209
1210       <varlistentry>
1211         <term><literal>\dFp[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1212         <listitem>
1213         <para>
1214          Lists text search parsers.
1215          If <replaceable class="parameter">pattern</replaceable> is specified,
1216          only parsers whose names match the pattern are shown.
1217          If the form <literal>\dFp+</literal> is used, a full description of
1218          each parser is shown, including the underlying functions and the
1219          list of recognized token types.
1220         </para>
1221         </listitem>
1222       </varlistentry>
1223
1224       <varlistentry>
1225         <term><literal>\dFt[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1226         <listitem>
1227         <para>
1228          Lists text search templates.
1229          If <replaceable class="parameter">pattern</replaceable> is specified,
1230          only templates whose names match the pattern are shown.
1231          If the form <literal>\dFt+</literal> is used, additional information
1232          is shown about each template, including the underlying function names.
1233         </para>
1234         </listitem>
1235       </varlistentry>
1236
1237
1238       <varlistentry>
1239         <term><literal>\dg[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1240         <listitem>
1241         <para>
1242         Lists database roles. If <replaceable
1243         class="parameter">pattern</replaceable> is specified, only
1244         those roles whose names match the pattern are listed.
1245         (This command is now effectively the same as <literal>\du</literal>).
1246         If the form <literal>\dg+</literal> is used, additional information
1247         is shown about each role, including the comment for each role.
1248         </para>
1249         </listitem>
1250       </varlistentry>
1251
1252
1253       <varlistentry>
1254         <term><literal>\dl</literal></term>
1255         <listitem>
1256         <para>
1257         This is an alias for <command>\lo_list</command>, which shows a
1258         list of large objects.
1259         </para>
1260         </listitem>
1261       </varlistentry>
1262
1263       <varlistentry>
1264         <term><literal>\dL[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1265         <listitem>
1266         <para>
1267         Lists procedural languages. If <replaceable
1268         class="parameter">pattern</replaceable>
1269         is specified, only languages whose names match the pattern are listed.
1270         By default, only user-created languages
1271         are shown; supply the <literal>S</literal> modifier to include system
1272         objects. If <literal>+</literal> is appended to the command name, each
1273         language is listed with its call handler, validator, access privileges,
1274         and whether it is a system object.
1275         </para>
1276         </listitem>
1277       </varlistentry>
1278
1279
1280       <varlistentry>
1281         <term><literal>\dn[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1282
1283         <listitem>
1284         <para>
1285         Lists schemas (namespaces). If <replaceable
1286         class="parameter">pattern</replaceable>
1287         is specified, only schemas whose names match the pattern are listed.
1288         By default, only user-created objects are shown; supply a
1289         pattern or the <literal>S</literal> modifier to include system objects.
1290         If <literal>+</literal> is appended to the command name, each object
1291         is listed with its associated permissions and description, if any.
1292         </para>
1293         </listitem>
1294       </varlistentry>
1295
1296
1297       <varlistentry>
1298         <term><literal>\do[S] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1299         <listitem>
1300         <para>
1301         Lists operators with their operand and return types.
1302         If <replaceable class="parameter">pattern</replaceable> is
1303         specified, only operators whose names match the pattern are listed.
1304         By default, only user-created objects are shown;  supply a
1305         pattern or the <literal>S</literal> modifier to include system
1306         objects.
1307         </para>
1308         </listitem>
1309       </varlistentry>
1310
1311
1312       <varlistentry>
1313         <term><literal>\dO[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1314         <listitem>
1315         <para>
1316         Lists collations.
1317         If <replaceable class="parameter">pattern</replaceable> is
1318         specified, only collations whose names match the pattern are
1319         listed.  By default, only user-created objects are shown;
1320         supply a pattern or the <literal>S</literal> modifier to
1321         include system objects.  If <literal>+</literal> is appended
1322         to the command name, each collation is listed with its associated
1323         description, if any.
1324         Note that only collations usable with the current database's encoding
1325         are shown, so the results may vary in different databases of the
1326         same installation.
1327         </para>
1328         </listitem>
1329       </varlistentry>
1330
1331
1332       <varlistentry>
1333         <term><literal>\dp [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1334         <listitem>
1335         <para>
1336         Lists tables, views and sequences with their
1337         associated access privileges.
1338         If <replaceable class="parameter">pattern</replaceable> is
1339         specified, only tables, views and sequences whose names match the
1340         pattern are listed.
1341         </para>
1342
1343         <para>
1344         The <xref linkend="sql-grant"> and
1345         <xref linkend="sql-revoke">
1346         commands are used to set access privileges.  The meaning of the
1347         privilege display is explained under
1348         <xref linkend="sql-grant">.
1349         </para>
1350         </listitem>
1351       </varlistentry>
1352
1353       <varlistentry>
1354         <term><literal>\drds [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">role-pattern</replaceable></link> [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">database-pattern</replaceable></link> ] ]</literal></term>
1355         <listitem>
1356         <para>
1357         Lists defined configuration settings.  These settings can be
1358         role-specific, database-specific, or both.
1359         <replaceable>role-pattern</replaceable> and
1360         <replaceable>database-pattern</replaceable> are used to select
1361         specific roles and databases to list, respectively.  If omitted, or if
1362         <literal>*</> is specified, all settings are listed, including those
1363         not role-specific or database-specific, respectively.
1364         </para>
1365
1366         <para>
1367         The <xref linkend="sql-alterrole"> and
1368         <xref linkend="sql-alterdatabase">
1369         commands are used to define per-role and per-database configuration
1370         settings.
1371         </para>
1372         </listitem>
1373       </varlistentry>
1374
1375       <varlistentry>
1376         <term><literal>\dT[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1377         <listitem>
1378         <para>
1379         Lists data types.
1380         If <replaceable class="parameter">pattern</replaceable> is
1381         specified, only types whose names match the pattern are listed.
1382         If <literal>+</literal> is appended to the command name, each type is
1383         listed with its internal name and size, as well as its allowed values
1384         if it is an <type>enum</> type.
1385         By default, only user-created objects are shown;  supply a
1386         pattern or the <literal>S</literal> modifier to include system
1387         objects.
1388         </para>
1389         </listitem>
1390       </varlistentry>
1391
1392       <varlistentry>
1393         <term><literal>\du[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1394         <listitem>
1395         <para>
1396         Lists database roles. If <replaceable
1397         class="parameter">pattern</replaceable> is specified, only
1398         those roles whose names match the pattern are listed.
1399         If the form <literal>\du+</literal> is used, additional information
1400         is shown about each role, including the comment for each role.
1401         </para>
1402         </listitem>
1403       </varlistentry>
1404
1405       <varlistentry>
1406         <term><literal>\dx[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1407         <listitem>
1408         <para>
1409         Lists installed extensions.
1410         If <replaceable class="parameter">pattern</replaceable>
1411         is specified, only those extensions whose names match the pattern
1412         are listed.
1413         If the form <literal>\dx+</literal> is used, all the objects belonging
1414         to each matching extension are listed.
1415         </para>
1416         </listitem>
1417       </varlistentry>
1418
1419       <varlistentry>
1420         <term><literal>\e</literal> or <literal>\edit</> <literal> <optional> <replaceable class="parameter">filename</> </optional> <optional> <replaceable class="parameter">line_number</> </optional> </literal></term>
1421
1422         <listitem>
1423         <para>
1424         If <replaceable class="parameter">filename</replaceable> is
1425         specified, the file is edited; after the editor exits, its
1426         content is copied back to the query buffer. If no <replaceable
1427         class="parameter">filename</replaceable> is given, the current query
1428         buffer is copied to a temporary file which is then edited in the same
1429         fashion.
1430         </para>
1431
1432         <para>
1433         The new query buffer is then re-parsed according to the normal
1434         rules of <application>psql</application>, where the whole buffer
1435         is treated as a single line. (Thus you cannot make scripts this
1436         way. Use <command>\i</command> for that.) This means that
1437         if the query ends with (or contains) a semicolon, it is
1438         immediately executed. Otherwise it will merely wait in the
1439         query buffer; type semicolon or <literal>\g</> to send it, or
1440         <literal>\r</> to cancel.
1441         </para>
1442
1443         <tip>
1444         <para>
1445         <application>psql</application> checks the environment
1446         variables <envar>PSQL_EDITOR</envar>, <envar>EDITOR</envar>, and
1447         <envar>VISUAL</envar> (in that order) for an editor to use. If
1448         all of them are unset, <filename>vi</filename> is used on Unix
1449         systems, <filename>notepad.exe</filename> on Windows systems.
1450         </para>
1451         </tip>
1452
1453         <para>
1454         If a line number is specified, <application>psql</application> will
1455         position the cursor on the specified line of the file or query buffer.
1456         This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
1457         variable to be set, so that <application>psql</application> knows how
1458         to specify the line number to the editor.  Note that if a single
1459         all-digits argument is given, <application>psql</application> assumes
1460         it is a line number not a file name.
1461         </para>
1462         </listitem>
1463       </varlistentry>
1464
1465       <varlistentry>
1466         <term><literal>\echo <replaceable class="parameter">text</replaceable> [ ... ]</literal></term>
1467         <listitem>
1468         <para>
1469         Prints the arguments to the standard output, separated by one
1470         space and followed by a newline. This can be useful to
1471         intersperse information in the output of scripts. For example:
1472 <programlisting>
1473 =&gt; <userinput>\echo `date`</userinput>
1474 Tue Oct 26 21:40:57 CEST 1999
1475 </programlisting>
1476         If the first argument is an unquoted <literal>-n</literal> the trailing
1477         newline is not written.
1478         </para>
1479
1480         <tip>
1481         <para>
1482         If you use the <command>\o</command> command to redirect your
1483         query output you might wish to use <command>\qecho</command>
1484         instead of this command.
1485         </para>
1486         </tip>
1487         </listitem>
1488       </varlistentry>
1489
1490       <varlistentry>
1491         <term><literal>\ef <optional> <replaceable class="parameter">function_description</> <optional>  <replaceable class="parameter">line_number</> </optional> </optional> </literal></term>
1492
1493         <listitem>
1494         <para>
1495          This command fetches and edits the definition of the named function,
1496          in the form of a <command>CREATE OR REPLACE FUNCTION</> command.
1497          Editing is done in the same way as for <literal>\edit</>.
1498          After the editor exits, the updated command waits in the query buffer;
1499          type semicolon or <literal>\g</> to send it, or <literal>\r</>
1500          to cancel.
1501         </para>
1502
1503         <para>
1504          The target function can be specified by name alone, or by name
1505          and arguments, for example <literal>foo(integer, text)</>.
1506          The argument types must be given if there is more
1507          than one function of the same name.
1508         </para>
1509
1510         <para>
1511          If no function is specified, a blank <command>CREATE FUNCTION</>
1512          template is presented for editing.
1513         </para>
1514
1515         <para>
1516         If a line number is specified, <application>psql</application> will
1517         position the cursor on the specified line of the function body
1518         (note that the function body typically does not begin on the
1519         first line of the file).
1520         This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
1521         variable to be set, so that <application>psql</application> knows how
1522         to specify the line number to the editor.
1523         </para>
1524         </listitem>
1525       </varlistentry>
1526
1527
1528       <varlistentry>
1529         <term><literal>\encoding [ <replaceable class="parameter">encoding</replaceable> ]</literal></term>
1530
1531         <listitem>
1532         <para>
1533         Sets the client character set encoding.  Without an argument, this command
1534         shows the current encoding.
1535         </para>
1536         </listitem>
1537       </varlistentry>
1538
1539
1540       <varlistentry>
1541         <term><literal>\f [ <replaceable class="parameter">string</replaceable> ]</literal></term>
1542
1543         <listitem>
1544         <para>
1545         Sets the field separator for unaligned query output. The default
1546         is the vertical bar (<literal>|</literal>). See also
1547         <command>\pset</command> for a generic way of setting output
1548         options.
1549         </para>
1550         </listitem>
1551       </varlistentry>
1552
1553
1554       <varlistentry>
1555         <term><literal>\g</literal> [ { <replaceable class="parameter">filename</replaceable> | <literal>|</literal><replaceable class="parameter">command</replaceable> } ]</term>
1556
1557         <listitem>
1558         <para>
1559         Sends the current query input buffer to the server and
1560         optionally stores the query's output in <replaceable
1561         class="parameter">filename</replaceable> or pipes the output
1562         into a separate Unix shell executing <replaceable
1563         class="parameter">command</replaceable>. A bare
1564         <literal>\g</literal> is virtually equivalent to a semicolon. A
1565         <literal>\g</literal> with argument is a <quote>one-shot</quote>
1566         alternative to the <command>\o</command> command.
1567         </para>
1568         </listitem>
1569       </varlistentry>
1570
1571       <varlistentry>
1572         <term><literal>\h</literal> or <literal>\help</literal> <literal>[ <replaceable class="parameter">command</replaceable> ]</literal></term>
1573         <listitem>
1574         <para>
1575         Gives syntax help on the specified <acronym>SQL</acronym>
1576         command. If <replaceable class="parameter">command</replaceable>
1577         is not specified, then <application>psql</application> will list
1578         all the commands for which syntax help is available. If
1579         <replaceable class="parameter">command</replaceable> is an
1580         asterisk (<literal>*</literal>), then syntax help on all
1581         <acronym>SQL</acronym> commands is shown.
1582         </para>
1583
1584         <note>
1585         <para>
1586         To simplify typing, commands that consists of several words do
1587         not have to be quoted. Thus it is fine to type <userinput>\help
1588         alter table</userinput>.
1589         </para>
1590         </note>
1591         </listitem>
1592       </varlistentry>
1593
1594
1595       <varlistentry>
1596         <term><literal>\H</literal></term>
1597         <listitem>
1598         <para>
1599         Turns on <acronym>HTML</acronym> query output format. If the
1600         <acronym>HTML</acronym> format is already on, it is switched
1601         back to the default aligned text format. This command is for
1602         compatibility and convenience, but see <command>\pset</command>
1603         about setting other output options.
1604         </para>
1605         </listitem>
1606       </varlistentry>
1607
1608
1609       <varlistentry>
1610         <term><literal>\i <replaceable class="parameter">filename</replaceable></literal></term>
1611         <listitem>
1612         <para>
1613         Reads input from the file <replaceable
1614         class="parameter">filename</replaceable> and executes it as
1615         though it had been typed on the keyboard.
1616         </para>
1617         <note>
1618         <para>
1619         If you want to see the lines on the screen as they are read you
1620         must set the variable <varname>ECHO</varname> to
1621         <literal>all</literal>.
1622         </para>
1623         </note>
1624         </listitem>
1625       </varlistentry>
1626
1627
1628       <varlistentry>
1629         <term><literal>\l</literal> (or <literal>\list</literal>)</term>
1630         <term><literal>\l+</literal> (or <literal>\list+</literal>)</term>
1631         <listitem>
1632         <para>
1633         List the names, owners, character set encodings, and access privileges
1634         of all the databases in the server.
1635         If <literal>+</literal> is appended to the command name, database
1636         sizes, default tablespaces, and descriptions are also displayed.
1637         (Size information is only available for databases that the current
1638         user can connect to.)
1639         </para>
1640         </listitem>
1641       </varlistentry>
1642
1643
1644       <varlistentry>
1645         <term><literal>\lo_export <replaceable class="parameter">loid</replaceable> <replaceable class="parameter">filename</replaceable></literal></term>
1646
1647         <listitem>
1648         <para>
1649         Reads the large object with <acronym>OID</acronym> <replaceable
1650         class="parameter">loid</replaceable> from the database and
1651         writes it to <replaceable
1652         class="parameter">filename</replaceable>. Note that this is
1653         subtly different from the server function
1654         <function>lo_export</function>, which acts with the permissions
1655         of the user that the database server runs as and on the server's
1656         file system.
1657         </para>
1658         <tip>
1659         <para>
1660         Use <command>\lo_list</command> to find out the large object's
1661         <acronym>OID</acronym>.
1662         </para>
1663         </tip>
1664         </listitem>
1665       </varlistentry>
1666
1667
1668       <varlistentry>
1669         <term><literal>\lo_import <replaceable class="parameter">filename</replaceable> [ <replaceable class="parameter">comment</replaceable> ]</literal></term>
1670
1671         <listitem>
1672         <para>
1673         Stores the file into a <productname>PostgreSQL</productname>
1674         large object. Optionally, it associates the given
1675         comment with the object. Example:
1676 <programlisting>
1677 foo=&gt; <userinput>\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'</userinput>
1678 lo_import 152801
1679 </programlisting>
1680         The response indicates that the large object received object
1681         ID 152801, which can be used to access the newly-created large
1682         object in the future. For the sake of readability, it is
1683         recommended to always associate a human-readable comment with
1684         every object. Both OIDs and comments can be viewed with the
1685         <command>\lo_list</command> command.
1686         </para>
1687
1688         <para>
1689         Note that this command is subtly different from the server-side
1690         <function>lo_import</function> because it acts as the local user
1691         on the local file system, rather than the server's user and file
1692         system.
1693         </para>
1694         </listitem>
1695       </varlistentry>
1696
1697       <varlistentry>
1698         <term><literal>\lo_list</literal></term>
1699         <listitem>
1700         <para>
1701         Shows a list of all <productname>PostgreSQL</productname>
1702         large objects currently stored in the database,
1703         along with any comments provided for them.
1704         </para>
1705         </listitem>
1706       </varlistentry>
1707
1708       <varlistentry>
1709         <term><literal>\lo_unlink <replaceable class="parameter">loid</replaceable></literal></term>
1710
1711         <listitem>
1712         <para>
1713         Deletes the large object with <acronym>OID</acronym>
1714         <replaceable class="parameter">loid</replaceable> from the
1715         database.
1716         </para>
1717
1718         <tip>
1719         <para>
1720         Use <command>\lo_list</command> to find out the large object's
1721         <acronym>OID</acronym>.
1722         </para>
1723         </tip>
1724         </listitem>
1725       </varlistentry>
1726
1727
1728       <varlistentry>
1729         <term><literal>\o</literal> [ {<replaceable class="parameter">filename</replaceable> | <literal>|</literal><replaceable class="parameter">command</replaceable>} ]</term>
1730
1731         <listitem>
1732         <para>
1733         Saves future query results to the file <replaceable
1734         class="parameter">filename</replaceable> or pipes future results
1735         into a separate Unix shell to execute <replaceable
1736         class="parameter">command</replaceable>. If no arguments are
1737         specified, the query output will be reset to the standard output.
1738         </para>
1739
1740         <para>
1741         <quote>Query results</quote> includes all tables, command
1742         responses, and notices obtained from the database server, as
1743         well as output of various backslash commands that query the
1744         database (such as <command>\d</command>), but not error
1745         messages.
1746         </para>
1747
1748         <tip>
1749         <para>
1750         To intersperse text output in between query results, use
1751         <command>\qecho</command>.
1752         </para>
1753         </tip>
1754         </listitem>
1755       </varlistentry>
1756
1757
1758       <varlistentry>
1759         <term><literal>\p</literal></term>
1760         <listitem>
1761         <para>
1762         Print the current query buffer to the standard output.
1763         </para>
1764         </listitem>
1765       </varlistentry>
1766
1767       <varlistentry>
1768         <term><literal>\password [ <replaceable class="parameter">username</replaceable> ]</literal></term>
1769         <listitem>
1770         <para>
1771         Changes the password of the specified user (by default, the current
1772         user).  This command prompts for the new password, encrypts it, and
1773         sends it to the server as an <command>ALTER ROLE</> command.  This
1774         makes sure that the new password does not appear in cleartext in the
1775         command history, the server log, or elsewhere.
1776         </para>
1777         </listitem>
1778       </varlistentry>
1779
1780       <varlistentry>
1781         <term><literal>\prompt [ <replaceable class="parameter">text</replaceable> ] <replaceable class="parameter">name</replaceable></literal></term>
1782         <listitem>
1783         <para>
1784          Prompts the user to set variable <replaceable
1785          class="parameter">name</>.  An optional prompt, <replaceable
1786          class="parameter">text</>, can be specified.  (For multiword
1787          prompts, use single quotes.)
1788         </para>
1789
1790         <para>
1791          By default, <literal>\prompt</> uses the terminal for input and
1792          output.  However, if the <option>-f</> command line switch is
1793          used, <literal>\prompt</> uses standard input and standard output.
1794         </para>
1795         </listitem>
1796       </varlistentry>
1797
1798       <varlistentry>
1799         <term><literal>\pset <replaceable class="parameter">option</replaceable> [ <replaceable class="parameter">value</replaceable> ]</literal></term>
1800
1801         <listitem>
1802         <para>
1803         This command sets options affecting the output of query result tables.
1804         <replaceable class="parameter">option</replaceable>
1805         indicates which option is to be set. The semantics of
1806         <replaceable class="parameter">value</replaceable> vary depending
1807         on the selected option.  For some options, omitting <replaceable
1808         class="parameter">value</replaceable> causes the option to be toggled
1809         or unset, as described under the particular option.  If no such
1810         behavior is mentioned, then omitting
1811         <replaceable class="parameter">value</replaceable> just results in
1812         the current setting being displayed.
1813         </para>
1814
1815         <para>
1816         Adjustable printing options are:
1817         <variablelist>
1818           <varlistentry>
1819           <term><literal>border</literal></term>
1820           <listitem>
1821           <para>
1822           The <replaceable class="parameter">value</replaceable> must be a
1823           number. In general, the higher
1824           the number the more borders and lines the tables will have,
1825           but this depends on the particular format. In
1826           <acronym>HTML</acronym> format, this will translate directly
1827           into the <literal>border=...</literal> attribute; in the
1828           other formats only values 0 (no border), 1 (internal dividing lines),
1829           and 2 (table frame) make sense.
1830           </para>
1831           </listitem>
1832           </varlistentry>
1833
1834           <varlistentry>
1835           <term><literal>columns</literal></term>
1836           <listitem>
1837           <para>
1838           Sets the target width for the <literal>wrapped</> format, and also
1839           the width limit for determining whether output is wide enough to
1840           require the pager.
1841           Zero (the default) causes the target width to be controlled by the
1842           environment variable <envar>COLUMNS</>, or the detected screen width
1843           if <envar>COLUMNS</> is not set.
1844           In addition, if <literal>columns</> is zero then the
1845           <literal>wrapped</> format only affects screen output.
1846           If <literal>columns</> is nonzero then file and pipe output is
1847           wrapped to that width as well.
1848           </para>
1849           </listitem>
1850           </varlistentry>
1851
1852           <varlistentry>
1853           <term><literal>expanded</literal> (or <literal>x</literal>)</term>
1854           <listitem>
1855           <para>
1856           If <replaceable class="parameter">value</replaceable> is specified
1857           it must be either <literal>on</literal> or <literal>off</literal>
1858           which will enable or disable expanded mode.  If <replaceable
1859           class="parameter">value</replaceable> is omitted the command toggles
1860           between regular and expanded mode.
1861           When expanded mode is enabled, query results
1862           are displayed in two columns, with the column name on the left and
1863           the data on the right. This mode is useful if the data wouldn't fit
1864           on the screen in the normal <quote>horizontal</quote> mode.
1865           </para>
1866           </listitem>
1867           </varlistentry>
1868
1869           <varlistentry>
1870           <term><literal>fieldsep</literal></term>
1871           <listitem>
1872           <para>
1873           Specifies the field separator to be used in unaligned output
1874           format. That way one can create, for example, tab- or
1875           comma-separated output, which other programs might prefer. To
1876           set a tab as field separator, type <literal>\pset fieldsep
1877           '\t'</literal>. The default field separator is
1878           <literal>'|'</literal> (a vertical bar).
1879           </para>
1880           </listitem>
1881           </varlistentry>
1882
1883           <varlistentry>
1884           <term><literal>footer</literal></term>
1885           <listitem>
1886           <para>
1887           If <replaceable class="parameter">value</replaceable> is specified
1888           it must be either <literal>on</literal> or <literal>off</literal>
1889           which will enable or disable display of the table footer
1890           (the <literal>(<replaceable>n</> rows)</literal> count).
1891           If <replaceable class="parameter">value</replaceable> is omitted the
1892           command toggles footer display on or off.
1893           </para>
1894           </listitem>
1895           </varlistentry>
1896
1897           <varlistentry>
1898           <term><literal>format</literal></term>
1899           <listitem>
1900           <para>
1901           Sets the output format to one of <literal>unaligned</literal>,
1902           <literal>aligned</literal>, <literal>wrapped</literal>,
1903           <literal>html</literal>,
1904           <literal>latex</literal>, or <literal>troff-ms</literal>.
1905           Unique abbreviations are allowed.  (That would mean one letter
1906           is enough.)
1907           </para>
1908
1909           <para>
1910           <literal>unaligned</> format writes all columns of a row on one
1911           line, separated by the currently active field separator. This
1912           is useful for creating output that might be intended to be read
1913           in by other programs (for example, tab-separated or comma-separated
1914           format).
1915           </para>
1916
1917           <para>
1918           <literal>aligned</literal> format is the standard, human-readable,
1919           nicely formatted text output;  this is the default.
1920           </para>
1921
1922           <para>
1923           <literal>wrapped</> format is like <literal>aligned</> but wraps
1924           wide data values across lines to make the output fit in the target
1925           column width.  The target width is determined as described under
1926           the <literal>columns</> option.  Note that <application>psql</> will
1927           not attempt to wrap column header titles; therefore,
1928           <literal>wrapped</> format behaves the same as <literal>aligned</>
1929           if the total width needed for column headers exceeds the target.
1930           </para>
1931
1932           <para>
1933           The <literal>html</>, <literal>latex</>, and <literal>troff-ms</>
1934           formats put out tables that are intended to
1935           be included in documents using the respective mark-up
1936           language. They are not complete documents! (This might not be
1937           so dramatic in <acronym>HTML</acronym>, but in LaTeX you must
1938           have a complete document wrapper.)
1939           </para>
1940           </listitem>
1941           </varlistentry>
1942
1943           <varlistentry>
1944           <term><literal>linestyle</literal></term>
1945           <listitem>
1946           <para>
1947           Sets the border line drawing style to one
1948           of <literal>ascii</literal>, <literal>old-ascii</literal>
1949           or <literal>unicode</literal>.
1950           Unique abbreviations are allowed.  (That would mean one
1951           letter is enough.)
1952           The default setting is <literal>ascii</>.
1953           This option only affects the <literal>aligned</> and
1954           <literal>wrapped</> output formats.
1955           </para>
1956
1957           <para>
1958           <literal>ascii</literal> style uses plain <acronym>ASCII</acronym>
1959           characters.  Newlines in data are shown using
1960           a <literal>+</literal> symbol in the right-hand margin.
1961           When the <literal>wrapped</literal> format wraps data from
1962           one line to the next without a newline character, a dot
1963           (<literal>.</>) is shown in the right-hand margin of the first line,
1964           and again in the left-hand margin of the following line.
1965           </para>
1966
1967           <para>
1968           <literal>old-ascii</literal> style uses plain <acronym>ASCII</>
1969           characters, using the formatting style used
1970           in <productname>PostgreSQL</productname> 8.4 and earlier.
1971           Newlines in data are shown using a <literal>:</literal>
1972           symbol in place of the left-hand column separator.
1973           When the data is wrapped from one line
1974           to the next without a newline character, a <literal>;</>
1975           symbol is used in place of the left-hand column separator.
1976           </para>
1977
1978           <para>
1979           <literal>unicode</literal> style uses Unicode box-drawing characters.
1980           Newlines in data are shown using a carriage return symbol
1981           in the right-hand margin.  When the data is wrapped from one line
1982           to the next without a newline character, an ellipsis symbol
1983           is shown in the right-hand margin of the first line, and
1984           again in the left-hand margin of the following line.
1985           </para>
1986
1987           <para>
1988           When the <literal>border</> setting is greater than zero,
1989           this option also determines the characters
1990           with which the border lines are drawn.
1991           Plain <acronym>ASCII</acronym> characters work everywhere, but
1992           Unicode characters look nicer on displays that recognize them.
1993           </para>
1994           </listitem>
1995           </varlistentry>
1996
1997           <varlistentry>
1998           <term><literal>null</literal></term>
1999           <listitem>
2000           <para>
2001           Sets the string to be printed in place of a null value.
2002           The default is to print nothing, which can easily be mistaken for
2003           an empty string. For example, one might prefer <literal>\pset null
2004           '(null)'</literal>.
2005           </para>
2006           </listitem>
2007           </varlistentry>
2008
2009           <varlistentry>
2010           <term><literal>numericlocale</literal></term>
2011           <listitem>
2012           <para>
2013           If <replaceable class="parameter">value</replaceable> is specified
2014           it must be either <literal>on</literal> or <literal>off</literal>
2015           which will enable or disable display of a locale-specific character
2016           to separate groups of digits to the left of the decimal marker.
2017           If <replaceable class="parameter">value</replaceable> is omitted the
2018           command toggles between regular and locale-specific numeric output.
2019           </para>
2020           </listitem>
2021           </varlistentry>
2022
2023           <varlistentry>
2024           <term><literal>pager</literal></term>
2025           <listitem>
2026           <para>
2027           Controls use of a pager program for query and <application>psql</>
2028           help output. If the environment variable <envar>PAGER</envar>
2029           is set, the output is piped to the specified program.
2030           Otherwise a platform-dependent default (such as
2031           <filename>more</filename>) is used.
2032           </para>
2033
2034           <para>
2035           When the <literal>pager</> option is <literal>off</>, the pager
2036           program is not used. When the <literal>pager</> option is
2037           <literal>on</>, the pager is used when appropriate, i.e., when the
2038           output is to a terminal and will not fit on the screen.
2039           The <literal>pager</> option can also be set to <literal>always</>,
2040           which causes the pager to be used for all terminal output regardless
2041           of whether it fits on the screen.  <literal>\pset pager</>
2042           without a <replaceable class="parameter">value</replaceable>
2043           toggles pager use on and off.
2044           </para>
2045           </listitem>
2046           </varlistentry>
2047
2048           <varlistentry>
2049           <term><literal>recordsep</literal></term>
2050           <listitem>
2051           <para>
2052           Specifies the record (line) separator to use in unaligned
2053           output format. The default is a newline character.
2054           </para>
2055           </listitem>
2056           </varlistentry>
2057
2058           <varlistentry>
2059           <term><literal>tableattr</literal> (or <literal>T</literal>)</term>
2060           <listitem>
2061           <para>
2062           Specifies attributes to be placed inside the
2063           <acronym>HTML</acronym> <sgmltag>table</sgmltag> tag in
2064           <literal>html</> output format. This
2065           could for example be <literal>cellpadding</literal> or
2066           <literal>bgcolor</literal>. Note that you probably don't want
2067           to specify <literal>border</literal> here, as that is already
2068           taken care of by <literal>\pset border</literal>.
2069           If no
2070           <replaceable class="parameter">value</replaceable> is given,
2071           the table attributes are unset.
2072           </para>
2073           </listitem>
2074           </varlistentry>
2075
2076           <varlistentry>
2077           <term><literal>title</literal></term>
2078           <listitem>
2079           <para>
2080           Sets the table title for any subsequently printed tables. This
2081           can be used to give your output descriptive tags. If no
2082           <replaceable class="parameter">value</replaceable> is given,
2083           the title is unset.
2084           </para>
2085           </listitem>
2086           </varlistentry>
2087
2088           <varlistentry>
2089           <term><literal>tuples_only</literal> (or <literal>t</literal>)</term>
2090           <listitem>
2091           <para>
2092           If <replaceable class="parameter">value</replaceable> is specified
2093           it must be either <literal>on</literal> or <literal>off</literal>
2094           which will enable or disable tuples-only mode.
2095           If <replaceable class="parameter">value</replaceable> is omitted the
2096           command toggles between regular and tuples-only output.
2097           Regular output includes extra information such
2098           as column headers, titles, and various footers. In tuples-only
2099           mode, only actual table data is shown.
2100           </para>
2101           </listitem>
2102           </varlistentry>
2103         </variablelist>
2104         </para>
2105
2106         <para>
2107         Illustrations of how these different formats look can be seen in
2108         the <xref linkend="APP-PSQL-examples"
2109         endterm="APP-PSQL-examples-title"> section.
2110         </para>
2111
2112         <tip>
2113         <para>
2114         There are various shortcut commands for <command>\pset</command>. See
2115         <command>\a</command>, <command>\C</command>, <command>\H</command>,
2116         <command>\t</command>, <command>\T</command>, and <command>\x</command>.
2117         </para>
2118         </tip>
2119
2120         <note>
2121         <para>
2122         It is an error to call <command>\pset</command> without any
2123         arguments. In the future this case might show the current status
2124         of all printing options.
2125         </para>
2126         </note>
2127
2128         </listitem>
2129       </varlistentry>
2130
2131
2132       <varlistentry>
2133         <term><literal>\q</literal></term>
2134         <listitem>
2135         <para>
2136         Quits the <application>psql</application> program.
2137         </para>
2138         </listitem>
2139       </varlistentry>
2140
2141
2142       <varlistentry>
2143         <term><literal>\qecho <replaceable class="parameter">text</replaceable> [ ... ] </literal></term>
2144         <listitem>
2145         <para>
2146         This command is identical to <command>\echo</command> except
2147         that the output will be written to the query output channel, as
2148         set by <command>\o</command>.
2149         </para>
2150         </listitem>
2151       </varlistentry>
2152
2153
2154       <varlistentry>
2155         <term><literal>\r</literal></term>
2156         <listitem>
2157         <para>
2158         Resets (clears) the query buffer.
2159         </para>
2160         </listitem>
2161       </varlistentry>
2162
2163
2164       <varlistentry>
2165         <term><literal>\s [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
2166         <listitem>
2167         <para>
2168         Print or save the command line history to <replaceable
2169         class="parameter">filename</replaceable>. If <replaceable
2170         class="parameter">filename</replaceable> is omitted, the history
2171         is written to the standard output. This option is only available
2172         if <application>psql</application> is configured to use the
2173         <acronym>GNU</acronym> <application>Readline</application> library.
2174         </para>
2175         </listitem>
2176       </varlistentry>
2177
2178
2179       <varlistentry>
2180         <term><literal>\set [ <replaceable class="parameter">name</replaceable> [ <replaceable class="parameter">value</replaceable> [ ... ] ] ]</literal></term>
2181
2182         <listitem>
2183         <para>
2184         Sets the internal variable <replaceable
2185         class="parameter">name</replaceable> to <replaceable
2186         class="parameter">value</replaceable> or, if more than one value
2187         is given, to the concatenation of all of them. If no second
2188         argument is given, the variable is just set with no value. To
2189         unset a variable, use the <command>\unset</command> command.
2190         </para>
2191
2192         <para>
2193         Valid variable names can contain characters, digits, and
2194         underscores. See the section <xref
2195         linkend="APP-PSQL-variables"
2196         endterm="APP-PSQL-variables-title"> below for details.
2197         Variable names are case-sensitive.
2198         </para>
2199
2200         <para>
2201         Although you are welcome to set any variable to anything you
2202         want, <application>psql</application> treats several variables
2203         as special. They are documented in the section about variables.
2204         </para>
2205
2206         <note>
2207         <para>
2208         This command is totally separate from the <acronym>SQL</acronym>
2209         command <xref linkend="SQL-SET">.
2210         </para>
2211         </note>
2212         </listitem>
2213       </varlistentry>
2214
2215
2216       <varlistentry>
2217         <term><literal>\sf[+] <replaceable class="parameter">function_description</> </literal></term>
2218
2219         <listitem>
2220         <para>
2221          This command fetches and shows the definition of the named function,
2222          in the form of a <command>CREATE OR REPLACE FUNCTION</> command.
2223          The definition is printed to the current query output channel,
2224          as set by <command>\o</command>.
2225         </para>
2226
2227         <para>
2228          The target function can be specified by name alone, or by name
2229          and arguments, for example <literal>foo(integer, text)</>.
2230          The argument types must be given if there is more
2231          than one function of the same name.
2232         </para>
2233
2234         <para>
2235          If <literal>+</literal> is appended to the command name, then the
2236          output lines are numbered, with the first line of the function body
2237          being line 1.
2238         </para>
2239         </listitem>
2240       </varlistentry>
2241
2242
2243       <varlistentry>
2244         <term><literal>\t</literal></term>
2245         <listitem>
2246         <para>
2247         Toggles the display of output column name headings and row count
2248         footer. This command is equivalent to <literal>\pset
2249         tuples_only</literal> and is provided for convenience.
2250         </para>
2251         </listitem>
2252       </varlistentry>
2253
2254
2255       <varlistentry>
2256         <term><literal>\T <replaceable class="parameter">table_options</replaceable></literal></term>
2257         <listitem>
2258         <para>
2259         Specifies attributes to be placed within the
2260         <sgmltag>table</sgmltag> tag in <acronym>HTML</acronym>
2261         output format. This command is equivalent to <literal>\pset
2262         tableattr <replaceable
2263         class="parameter">table_options</replaceable></literal>.
2264         </para>
2265         </listitem>
2266       </varlistentry>
2267
2268
2269       <varlistentry>
2270        <term><literal>\timing [ <replaceable class="parameter">on</replaceable> | <replaceable class="parameter">off</replaceable> ]</literal></term>
2271         <listitem>
2272         <para>
2273          Without parameter, toggles a display of how long each SQL statement
2274          takes, in milliseconds.  With parameter, sets same.
2275         </para>
2276        </listitem>
2277       </varlistentry>
2278
2279
2280       <varlistentry>
2281         <term><literal>\w</literal> <replaceable class="parameter">filename</replaceable></term>
2282         <term><literal>\w</literal> <literal>|</><replaceable class="parameter">command</replaceable></term>
2283         <listitem>
2284         <para>
2285         Outputs the current query buffer to the file <replaceable
2286         class="parameter">filename</replaceable> or pipes it to the Unix
2287         command <replaceable class="parameter">command</replaceable>.
2288         </para>
2289         </listitem>
2290       </varlistentry>
2291
2292
2293       <varlistentry>
2294         <term><literal>\x</literal></term>
2295         <listitem>
2296         <para>
2297         Toggles expanded table formatting mode. As such it is equivalent to
2298         <literal>\pset expanded</literal>.
2299        </para>
2300        </listitem>
2301       </varlistentry>
2302
2303
2304       <varlistentry>
2305         <term><literal>\z [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
2306         <listitem>
2307         <para>
2308         Lists tables, views and sequences with their
2309         associated access privileges.
2310         If a <replaceable class="parameter">pattern</replaceable> is
2311         specified, only tables, views and sequences whose names match the
2312         pattern are listed.
2313         </para>
2314
2315         <para>
2316         This is an alias for <command>\dp</command> (<quote>display
2317         privileges</quote>).
2318         </para>
2319         </listitem>
2320       </varlistentry>
2321
2322
2323       <varlistentry>
2324         <term><literal>\! [ <replaceable class="parameter">command</replaceable> ]</literal></term>
2325         <listitem>
2326         <para>
2327         Escapes to a separate Unix shell or executes the Unix command
2328         <replaceable class="parameter">command</replaceable>. The
2329         arguments are not further interpreted; the shell will see them
2330         as-is.
2331         </para>
2332         </listitem>
2333       </varlistentry>
2334
2335
2336       <varlistentry>
2337         <term><literal>\?</literal></term>
2338         <listitem>
2339         <para>
2340         Shows help information about the backslash commands.
2341         </para>
2342         </listitem>
2343       </varlistentry>
2344
2345     </variablelist>
2346   </para>
2347
2348   <refsect3 id="APP-PSQL-patterns">
2349    <title id="APP-PSQL-patterns-title">Patterns</title>
2350
2351    <indexterm>
2352     <primary>patterns</primary>
2353     <secondary>in psql and pg_dump</secondary>
2354    </indexterm>
2355
2356   <para>
2357    The various <literal>\d</> commands accept a <replaceable
2358    class="parameter">pattern</replaceable> parameter to specify the
2359    object name(s) to be displayed.  In the simplest case, a pattern
2360    is just the exact name of the object.  The characters within a
2361    pattern are normally folded to lower case, just as in SQL names;
2362    for example, <literal>\dt FOO</> will display the table named
2363    <literal>foo</>.  As in SQL names, placing double quotes around
2364    a pattern stops folding to lower case.  Should you need to include
2365    an actual double quote character in a pattern, write it as a pair
2366    of double quotes within a double-quote sequence; again this is in
2367    accord with the rules for SQL quoted identifiers.  For example,
2368    <literal>\dt "FOO""BAR"</> will display the table named
2369    <literal>FOO"BAR</> (not <literal>foo"bar</>).  Unlike the normal
2370    rules for SQL names, you can put double quotes around just part
2371    of a pattern, for instance <literal>\dt FOO"FOO"BAR</> will display
2372    the table named <literal>fooFOObar</>.
2373   </para>
2374
2375   <para>
2376    Whenever the <replaceable class="parameter">pattern</replaceable> parameter
2377    is omitted completely, the <literal>\d</> commands display all objects
2378    that are visible in the current schema search path &mdash; this is
2379    equivalent to using <literal>*</> as the pattern.
2380    (An object is said to be <firstterm>visible</> if its
2381    containing schema is in the search path and no object of the same
2382    kind and name appears earlier in the search path. This is equivalent to the
2383    statement that the object can be referenced by name without explicit
2384    schema qualification.)
2385    To see all objects in the database regardless of visibility,
2386    use <literal>*.*</> as the pattern.
2387   </para>
2388
2389   <para>
2390    Within a pattern, <literal>*</> matches any sequence of characters
2391    (including no characters) and <literal>?</> matches any single character.
2392    (This notation is comparable to Unix shell file name patterns.)
2393    For example, <literal>\dt int*</> displays tables whose names
2394    begin with <literal>int</>.  But within double quotes, <literal>*</>
2395    and <literal>?</> lose these special meanings and are just matched
2396    literally.
2397   </para>
2398
2399   <para>
2400    A pattern that contains a dot (<literal>.</>) is interpreted as a schema
2401    name pattern followed by an object name pattern.  For example,
2402    <literal>\dt foo*.*bar*</> displays all tables whose table name
2403    includes <literal>bar</> that are in schemas whose schema name
2404    starts with <literal>foo</>.  When no dot appears, then the pattern
2405    matches only objects that are visible in the current schema search path.
2406    Again, a dot within double quotes loses its special meaning and is matched
2407    literally.
2408   </para>
2409
2410   <para>
2411    Advanced users can use regular-expression notations such as character
2412    classes, for example <literal>[0-9]</> to match any digit.  All regular
2413    expression special characters work as specified in
2414    <xref linkend="functions-posix-regexp">, except for <literal>.</> which
2415    is taken as a separator as mentioned above, <literal>*</> which is
2416    translated to the regular-expression notation <literal>.*</>,
2417    <literal>?</> which is translated to <literal>.</>, and
2418    <literal>$</> which is matched literally.  You can emulate
2419    these pattern characters at need by writing
2420    <literal>?</> for <literal>.</>,
2421    <literal>(<replaceable class="parameter">R</replaceable>+|)</literal> for
2422    <literal><replaceable class="parameter">R</replaceable>*</literal>, or
2423    <literal>(<replaceable class="parameter">R</replaceable>|)</literal> for
2424    <literal><replaceable class="parameter">R</replaceable>?</literal>.
2425    <literal>$</> is not needed as a regular-expression character since
2426    the pattern must match the whole name, unlike the usual
2427    interpretation of regular expressions (in other words, <literal>$</>
2428    is automatically appended to your pattern).  Write <literal>*</> at the
2429    beginning and/or end if you don't wish the pattern to be anchored.
2430    Note that within double quotes, all regular expression special characters
2431    lose their special meanings and are matched literally.  Also, the regular
2432    expression special characters are matched literally in operator name
2433    patterns (i.e., the argument of <literal>\do</>).
2434   </para>
2435   </refsect3>
2436  </refsect2>
2437
2438  <refsect2>
2439   <title>Advanced Features</title>
2440
2441    <refsect3 id="APP-PSQL-variables">
2442     <title id="APP-PSQL-variables-title">Variables</title>
2443
2444     <para>
2445     <application>psql</application> provides variable substitution
2446     features similar to common Unix command shells.
2447     Variables are simply name/value pairs, where the value
2448     can be any string of any length. To set variables, use the
2449     <application>psql</application> meta-command
2450     <command>\set</command>:
2451 <programlisting>
2452 testdb=&gt; <userinput>\set foo bar</userinput>
2453 </programlisting>
2454     sets the variable <literal>foo</literal> to the value
2455     <literal>bar</literal>. To retrieve the content of the variable, precede
2456     the name with a colon and use it as the argument of any slash
2457     command:
2458 <programlisting>
2459 testdb=&gt; <userinput>\echo :foo</userinput>
2460 bar
2461 </programlisting>
2462     </para>
2463
2464     <note>
2465     <para>
2466     The arguments of <command>\set</command> are subject to the same
2467     substitution rules as with other commands. Thus you can construct
2468     interesting references such as <literal>\set :foo
2469     'something'</literal> and get <quote>soft links</quote> or
2470     <quote>variable variables</quote> of <productname>Perl</productname>
2471     or <productname><acronym>PHP</acronym></productname> fame,
2472     respectively. Unfortunately (or fortunately?), there is no way to do
2473     anything useful with these constructs. On the other hand,
2474     <literal>\set bar :foo</literal> is a perfectly valid way to copy a
2475     variable.
2476     </para>
2477     </note>
2478
2479     <para>
2480     If you call <command>\set</command> without a second argument, the
2481     variable is set, with an empty string as value. To unset (or delete) a
2482     variable, use the command <command>\unset</command>.
2483     </para>
2484
2485     <para>
2486     <application>psql</application>'s internal variable names can
2487     consist of letters, numbers, and underscores in any order and any
2488     number of them. A number of these variables are treated specially
2489     by <application>psql</application>. They indicate certain option
2490     settings that can be changed at run time by altering the value of
2491     the variable or that represent some state of the application. Although
2492     you can use these variables for any other purpose, this is not
2493     recommended, as the program behavior might grow really strange
2494     really quickly. By convention, all specially treated variables
2495     consist of all upper-case letters (and possibly numbers and
2496     underscores). To ensure maximum compatibility in the future, avoid
2497     using such variable names for your own purposes. A list of all specially
2498     treated variables follows.
2499    </para>
2500
2501     <variablelist>
2502       <varlistentry>
2503       <indexterm>
2504        <primary>autocommit</primary>
2505        <secondary>psql</secondary>
2506       </indexterm>
2507         <term><varname>AUTOCOMMIT</varname></term>
2508         <listitem>
2509         <para>
2510         When <literal>on</> (the default), each SQL command is automatically
2511         committed upon successful completion.  To postpone commit in this
2512         mode, you must enter a <command>BEGIN</> or <command>START
2513         TRANSACTION</> SQL command.  When <literal>off</> or unset, SQL
2514         commands are not committed until you explicitly issue
2515         <command>COMMIT</> or <command>END</>.  The autocommit-off
2516         mode works by issuing an implicit <command>BEGIN</> for you, just
2517         before any command that is not already in a transaction block and
2518         is not itself a <command>BEGIN</> or other transaction-control
2519         command, nor a command that cannot be executed inside a transaction
2520         block (such as <command>VACUUM</>).
2521         </para>
2522
2523         <note>
2524         <para>
2525          In autocommit-off mode, you must explicitly abandon any failed
2526          transaction by entering <command>ABORT</> or <command>ROLLBACK</>.
2527          Also keep in mind that if you exit the session
2528          without committing, your work will be lost.
2529         </para>
2530         </note>
2531
2532         <note>
2533         <para>
2534          The autocommit-on mode is <productname>PostgreSQL</>'s traditional
2535          behavior, but autocommit-off is closer to the SQL spec.  If you
2536          prefer autocommit-off, you might wish to set it in the system-wide
2537          <filename>psqlrc</filename> file or your
2538          <filename>~/.psqlrc</filename> file.
2539         </para>
2540         </note>
2541         </listitem>
2542       </varlistentry>
2543
2544       <varlistentry>
2545         <term><varname>DBNAME</varname></term>
2546         <listitem>
2547         <para>
2548         The name of the database you are currently connected to. This is
2549         set every time you connect to a database (including program
2550         start-up), but can be unset.
2551         </para>
2552         </listitem>
2553       </varlistentry>
2554
2555       <varlistentry>
2556         <term><varname>ECHO</varname></term>
2557         <listitem>
2558         <para>
2559         If set to <literal>all</literal>, all lines
2560         entered from the keyboard or from a script are written to the standard output
2561         before they are parsed or executed. To select this behavior on program
2562         start-up, use the switch <option>-a</option>. If set to
2563         <literal>queries</literal>,
2564         <application>psql</application> merely prints all queries as
2565         they are sent to the server. The switch for this is
2566         <option>-e</option>.
2567         </para>
2568         </listitem>
2569       </varlistentry>
2570
2571       <varlistentry>
2572         <term><varname>ECHO_HIDDEN</varname></term>
2573         <listitem>
2574         <para>
2575         When this variable is set and a backslash command queries the
2576         database, the query is first shown. This way you can study the
2577         <productname>PostgreSQL</productname> internals and provide
2578         similar functionality in your own programs. (To select this behavior
2579         on program start-up, use the switch <option>-E</option>.)  If you set
2580         the variable to the value <literal>noexec</literal>, the queries are
2581         just shown but are not actually sent to the server and executed.
2582         </para>
2583         </listitem>
2584       </varlistentry>
2585
2586       <varlistentry>
2587         <term><varname>EDITOR_LINENUMBER_SWITCH</varname></term>
2588         <listitem>
2589         <para>
2590         When <command>\edit</command> or <command>\ef</command> is used with a
2591         line number argument, this variable specifies the command-line switch
2592         used to pass the line number to the user's editor.  For editors such
2593         as <productname>emacs</> or <productname>vi</>, you can simply set
2594         this variable to a plus sign.  Include a trailing space in the value
2595         of the variable if there needs to be space between the switch name and
2596         the line number.
2597         Examples:
2598
2599 <programlisting>
2600 \set EDITOR_LINENUMBER_SWITCH +
2601 \set EDITOR_LINENUMBER_SWITCH '--line '
2602 </programlisting>
2603         </para>
2604         </listitem>
2605       </varlistentry>
2606
2607       <varlistentry>
2608         <term><varname>ENCODING</varname></term>
2609         <listitem>
2610         <para>
2611         The current client character set encoding.
2612         </para>
2613         </listitem>
2614       </varlistentry>
2615
2616       <varlistentry>
2617         <term><varname>FETCH_COUNT</varname></term>
2618         <listitem>
2619         <para>
2620         If this variable is set to an integer value &gt; 0,
2621         the results of <command>SELECT</command> queries are fetched
2622         and displayed in groups of that many rows, rather than the
2623         default behavior of collecting the entire result set before
2624         display.  Therefore only a
2625         limited amount of memory is used, regardless of the size of
2626         the result set.  Settings of 100 to 1000 are commonly used
2627         when enabling this feature.
2628         Keep in mind that when using this feature, a query might
2629         fail after having already displayed some rows.
2630         </para>
2631         <tip>
2632         <para>
2633         Although you can use any output format with this feature,
2634         the default <literal>aligned</> format tends to look bad
2635         because each group of <varname>FETCH_COUNT</varname> rows
2636         will be formatted separately, leading to varying column
2637         widths across the row groups.  The other output formats work better.
2638         </para>
2639         </tip>
2640         </listitem>
2641       </varlistentry>
2642
2643       <varlistentry>
2644         <term><varname>HISTCONTROL</varname></term>
2645         <listitem>
2646         <para>
2647          If this variable is set to <literal>ignorespace</literal>,
2648          lines which begin with a space are not entered into the history
2649          list. If set to a value of <literal>ignoredups</literal>, lines
2650          matching the previous history line are not entered. A value of
2651          <literal>ignoreboth</literal> combines the two options. If
2652          unset, or if set to any other value than those above, all lines
2653          read in interactive mode are saved on the history list.
2654         </para>
2655         <note>
2656         <para>
2657         This feature was shamelessly plagiarized from
2658         <application>Bash</application>.
2659         </para>
2660         </note>
2661         </listitem>
2662       </varlistentry>
2663
2664       <varlistentry>
2665         <term><varname>HISTFILE</varname></term>
2666         <listitem>
2667         <para>
2668         The file name that will be used to store the history list. The default
2669         value is <filename>~/.psql_history</filename>.  For example, putting:
2670 <programlisting>
2671 \set HISTFILE ~/.psql_history- :DBNAME
2672 </programlisting>
2673         in <filename>~/.psqlrc</filename> will cause
2674         <application>psql</application> to maintain a separate history for
2675         each database.
2676         </para>
2677         <note>
2678         <para>
2679         This feature was shamelessly plagiarized from
2680         <application>Bash</application>.
2681         </para>
2682         </note>
2683         </listitem>
2684       </varlistentry>
2685
2686       <varlistentry>
2687         <term><varname>HISTSIZE</varname></term>
2688         <listitem>
2689         <para>
2690         The number of commands to store in the command history. The
2691         default value is 500.
2692         </para>
2693         <note>
2694         <para>
2695         This feature was shamelessly plagiarized from
2696         <application>Bash</application>.
2697         </para>
2698         </note>
2699         </listitem>
2700       </varlistentry>
2701
2702       <varlistentry>
2703         <term><varname>HOST</varname></term>
2704         <listitem>
2705         <para>
2706         The database server host you are currently connected to. This is
2707         set every time you connect to a database (including program
2708         start-up), but can be unset.
2709         </para>
2710         </listitem>
2711       </varlistentry>
2712
2713       <varlistentry>
2714         <term><varname>IGNOREEOF</varname></term>
2715         <listitem>
2716         <para>
2717          If unset, sending an <acronym>EOF</> character (usually
2718          <keycombo action="simul"><keycap>Control</><keycap>D</></>)
2719          to an interactive session of <application>psql</application>
2720          will terminate the application. If set to a numeric value,
2721          that many <acronym>EOF</> characters are ignored before the
2722          application terminates.  If the variable is set but has no
2723          numeric value, the default is 10.
2724         </para>
2725         <note>
2726         <para>
2727         This feature was shamelessly plagiarized from
2728         <application>Bash</application>.
2729         </para>
2730         </note>
2731         </listitem>
2732       </varlistentry>
2733
2734       <varlistentry>
2735         <term><varname>LASTOID</varname></term>
2736         <listitem>
2737         <para>
2738         The value of the last affected OID, as returned from an
2739         <command>INSERT</command> or <command>\lo_import</command>
2740         command. This variable is only guaranteed to be valid until
2741         after the result of the next <acronym>SQL</acronym> command has
2742         been displayed.
2743         </para>
2744         </listitem>
2745       </varlistentry>
2746
2747       <varlistentry>
2748       <indexterm>
2749        <primary>rollback</primary>
2750        <secondary>psql</secondary>
2751       </indexterm>
2752         <term><varname>ON_ERROR_ROLLBACK</varname></term>
2753         <listitem>
2754         <para>
2755         When <literal>on</>, if a statement in a transaction block
2756         generates an error, the error is ignored and the transaction
2757         continues. When <literal>interactive</>, such errors are only
2758         ignored in interactive sessions, and not when reading script
2759         files. When <literal>off</> (the default), a statement in a
2760         transaction block that generates an error aborts the entire
2761         transaction. The on_error_rollback-on mode works by issuing an
2762         implicit <command>SAVEPOINT</> for you, just before each command
2763         that is in a transaction block, and rolls back to the savepoint
2764         on error.
2765         </para>
2766         </listitem>
2767       </varlistentry>
2768
2769       <varlistentry>
2770         <term><varname>ON_ERROR_STOP</varname></term>
2771         <listitem>
2772         <para>
2773         By default, if non-interactive scripts encounter an error, such
2774         as a malformed <acronym>SQL</acronym> command or internal
2775         meta-command, processing continues. This has been the
2776         traditional behavior of <application>psql</application> but it
2777         is sometimes not desirable. If this variable is set, script
2778         processing will immediately terminate. If the script was called
2779         from another script it will terminate in the same fashion. If
2780         the outermost script was not called from an interactive
2781         <application>psql</application> session but rather using the
2782         <option>-f</option> option, <application>psql</application> will
2783         return error code 3, to distinguish this case from fatal error
2784         conditions (error code 1).
2785         </para>
2786         </listitem>
2787       </varlistentry>
2788
2789       <varlistentry>
2790         <term><varname>PORT</varname></term>
2791         <listitem>
2792         <para>
2793         The database server port to which you are currently connected.
2794         This is set every time you connect to a database (including
2795         program start-up), but can be unset.
2796         </para>
2797         </listitem>
2798       </varlistentry>
2799
2800       <varlistentry>
2801         <term><varname>PROMPT1</varname></term>
2802         <term><varname>PROMPT2</varname></term>
2803         <term><varname>PROMPT3</varname></term>
2804         <listitem>
2805         <para>
2806         These specify what the prompts <application>psql</application>
2807         issues should look like. See <xref
2808         linkend="APP-PSQL-prompting"
2809         endterm="APP-PSQL-prompting-title"> below.
2810         </para>
2811         </listitem>
2812       </varlistentry>
2813
2814       <varlistentry>
2815         <term><varname>QUIET</varname></term>
2816         <listitem>
2817         <para>
2818         This variable is equivalent to the command line option
2819         <option>-q</option>. It is probably not too useful in
2820         interactive mode.
2821         </para>
2822         </listitem>
2823       </varlistentry>
2824
2825       <varlistentry>
2826         <term><varname>SINGLELINE</varname></term>
2827         <listitem>
2828         <para>
2829         This variable is equivalent to the command line option
2830         <option>-S</option>.
2831         </para>
2832         </listitem>
2833       </varlistentry>
2834
2835       <varlistentry>
2836         <term><varname>SINGLESTEP</varname></term>
2837         <listitem>
2838         <para>
2839         This variable is equivalent to the command line option
2840         <option>-s</option>.
2841         </para>
2842         </listitem>
2843       </varlistentry>
2844
2845       <varlistentry>
2846         <term><varname>USER</varname></term>
2847         <listitem>
2848         <para>
2849         The database user you are currently connected as. This is set
2850         every time you connect to a database (including program
2851         start-up), but can be unset.
2852         </para>
2853         </listitem>
2854       </varlistentry>
2855
2856       <varlistentry>
2857         <term><varname>VERBOSITY</varname></term>
2858         <listitem>
2859         <para>
2860         This variable can be set to the values <literal>default</>,
2861         <literal>verbose</>, or <literal>terse</> to control the verbosity
2862         of error reports.
2863         </para>
2864         </listitem>
2865       </varlistentry>
2866
2867     </variablelist>
2868
2869    </refsect3>
2870
2871    <refsect3>
2872     <title><acronym>SQL</acronym> Interpolation</title>
2873
2874     <para>
2875     An additional useful feature of <application>psql</application>
2876     variables is that you can substitute (<quote>interpolate</quote>)
2877     them into regular <acronym>SQL</acronym> statements.
2878     <application>psql</application> provides special facilities for
2879     ensuring that values used as SQL literals and identifiers are
2880     properly escaped.  The syntax for interpolating a value without
2881     any special escaping is again to prepend the variable name with a colon
2882     (<literal>:</literal>):
2883 <programlisting>
2884 testdb=&gt; <userinput>\set foo 'my_table'</userinput>
2885 testdb=&gt; <userinput>SELECT * FROM :foo;</userinput>
2886 </programlisting>
2887     would then query the table <literal>my_table</literal>. Note that this
2888     may be unsafe: the value of the variable is copied literally, so it can
2889     even contain unbalanced quotes or backslash commands. You must make sure
2890     that it makes sense where you put it.
2891     </para>
2892
2893     <para>
2894     When a value is to be used as an SQL literal or identifier, it is
2895     safest to arrange for it to be escaped.  To escape the value of
2896     a variable as an SQL literal, write a colon followed by the variable
2897     name in single quotes.  To escape the value an SQL identifier, write
2898     a colon followed by the variable name in double quotes.  The previous
2899     example would be more safely written this way:
2900 <programlisting>
2901 testdb=&gt; <userinput>\set foo 'my_table'</userinput>
2902 testdb=&gt; <userinput>SELECT * FROM :"foo";</userinput>
2903 </programlisting>
2904     Variable interpolation will not be performed into quoted
2905     <acronym>SQL</acronym> entities.
2906     </para>
2907
2908     <para>
2909     One  possible use of this mechanism is to
2910     copy the contents of a file into a table column. First load the file into a
2911     variable and then proceed as above:
2912 <programlisting>
2913 testdb=&gt; <userinput>\set content `cat my_file.txt`</userinput>
2914 testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
2915 </programlisting>
2916     (Note that this still won't work if <filename>my_file.txt</filename> contains NUL bytes.
2917     psql does not support embedded NUL bytes in variable values.)
2918     </para>
2919
2920     <para>
2921     Since colons can legally appear in SQL commands, an apparent attempt
2922     at interpolation (such as <literal>:name</literal>,
2923     <literal>:'name'</literal>, or <literal>:"name"</literal>) is not
2924     changed unless the named variable is currently set. In any case, you
2925     can escape a colon with a backslash to protect it from substitution.
2926     (The colon syntax for variables is standard <acronym>SQL</acronym> for
2927     embedded query languages, such as <application>ECPG</application>.
2928     The colon syntax for array slices and type casts are
2929     <productname>PostgreSQL</productname> extensions, hence the
2930     conflict.  The colon syntax for escaping a variable's value as an
2931     SQL literal or identifier is a <application>psql</application>
2932     extension.)
2933     </para>
2934
2935    </refsect3>
2936
2937    <refsect3 id="APP-PSQL-prompting">
2938     <title id="APP-PSQL-prompting-title">Prompting</title>
2939
2940     <para>
2941     The prompts <application>psql</application> issues can be customized
2942     to your preference. The three variables <varname>PROMPT1</varname>,
2943     <varname>PROMPT2</varname>, and <varname>PROMPT3</varname> contain strings
2944     and special escape sequences that describe the appearance of the
2945     prompt. Prompt 1 is the normal prompt that is issued when
2946     <application>psql</application> requests a new command. Prompt 2 is
2947     issued when more input is expected during command input because the
2948     command was not terminated with a semicolon or a quote was not closed.
2949     Prompt 3 is issued when you run an <acronym>SQL</acronym>
2950     <command>COPY</command> command and you are expected to type in the
2951     row values on the terminal.
2952     </para>
2953
2954     <para>
2955     The value of the selected prompt variable is printed literally,
2956     except where a percent sign (<literal>%</literal>) is encountered.
2957     Depending on the next character, certain other text is substituted
2958     instead. Defined substitutions are:
2959
2960     <variablelist>
2961       <varlistentry>
2962         <term><literal>%M</literal></term>
2963         <listitem>
2964          <para>
2965           The full host name (with domain name) of the database server,
2966           or <literal>[local]</literal> if the connection is over a Unix
2967           domain socket, or
2968           <literal>[local:<replaceable>/dir/name</replaceable>]</literal>,
2969           if the Unix domain socket is not at the compiled in default
2970           location.
2971         </para>
2972        </listitem>
2973       </varlistentry>
2974
2975       <varlistentry>
2976         <term><literal>%m</literal></term>
2977         <listitem>
2978          <para>
2979           The host name of the database server, truncated at the
2980           first dot, or <literal>[local]</literal> if the connection is
2981           over a Unix domain socket.
2982          </para>
2983         </listitem>
2984       </varlistentry>
2985
2986       <varlistentry>
2987         <term><literal>%&gt;</literal></term>
2988         <listitem><para>The port number at which the database server is listening.</para></listitem>
2989       </varlistentry>
2990
2991       <varlistentry>
2992         <term><literal>%n</literal></term>
2993         <listitem>
2994          <para>
2995           The database session user name.  (The expansion of this
2996           value might change during a database session as the result
2997           of the command <command>SET SESSION
2998           AUTHORIZATION</command>.)
2999          </para>
3000         </listitem>
3001       </varlistentry>
3002
3003       <varlistentry>
3004         <term><literal>%/</literal></term>
3005         <listitem><para>The name of the current database.</para></listitem>
3006       </varlistentry>
3007
3008       <varlistentry>
3009         <term><literal>%~</literal></term>
3010         <listitem><para>Like <literal>%/</literal>, but the output is <literal>~</literal>
3011          (tilde) if the database is your default database.</para></listitem>
3012       </varlistentry>
3013
3014       <varlistentry>
3015         <term><literal>%#</literal></term>
3016         <listitem>
3017          <para>
3018           If the session user is a database superuser, then a
3019           <literal>#</literal>, otherwise a <literal>&gt;</literal>.
3020           (The expansion of this value might change during a database
3021           session as the result of the command <command>SET SESSION
3022           AUTHORIZATION</command>.)
3023          </para>
3024         </listitem>
3025       </varlistentry>
3026
3027       <varlistentry>
3028         <term><literal>%R</literal></term>
3029         <listitem>
3030         <para>
3031         In prompt 1 normally <literal>=</literal>, but <literal>^</literal> if
3032         in single-line mode, and <literal>!</literal> if the session is
3033         disconnected from the database (which can happen if
3034         <command>\connect</command> fails). In prompt 2 the sequence is
3035         replaced by <literal>-</literal>, <literal>*</literal>, a single quote,
3036         a double quote, or a dollar sign, depending on whether
3037         <application>psql</application> expects more input because the
3038         command wasn't terminated yet, because you are inside a
3039         <literal>/* ... */</literal> comment, or because you are inside
3040         a quoted or dollar-escaped string. In prompt 3 the sequence doesn't
3041         produce anything.
3042         </para>
3043         </listitem>
3044       </varlistentry>
3045
3046       <varlistentry>
3047         <term><literal>%x</literal></term>
3048         <listitem>
3049         <para>
3050         Transaction status: an empty string when not in a transaction
3051         block, or <literal>*</> when in a transaction block, or
3052         <literal>!</> when in a failed transaction block, or <literal>?</>
3053         when the transaction state is indeterminate (for example, because
3054         there is no connection).
3055         </para>
3056         </listitem>
3057       </varlistentry>
3058
3059       <varlistentry>
3060         <term><literal>%</literal><replaceable class="parameter">digits</replaceable></term>
3061         <listitem>
3062         <para>
3063         The character with the indicated octal code is substituted.
3064         </para>
3065         </listitem>
3066       </varlistentry>
3067
3068       <varlistentry>
3069         <term><literal>%:</literal><replaceable class="parameter">name</replaceable><literal>:</literal></term>
3070         <listitem>
3071         <para>
3072         The value of the <application>psql</application> variable
3073         <replaceable class="parameter">name</replaceable>. See the
3074         section <xref linkend="APP-PSQL-variables"
3075         endterm="APP-PSQL-variables-title"> for details.
3076         </para>
3077         </listitem>
3078       </varlistentry>
3079
3080       <varlistentry>
3081         <term><literal>%`</literal><replaceable class="parameter">command</replaceable><literal>`</literal></term>
3082         <listitem>
3083         <para>
3084         The output of <replaceable
3085         class="parameter">command</replaceable>, similar to ordinary
3086         <quote>back-tick</quote> substitution.
3087         </para>
3088         </listitem>
3089       </varlistentry>
3090
3091       <varlistentry>
3092         <term><literal>%[</literal> ... <literal>%]</literal></term>
3093         <listitem>
3094          <para>
3095          Prompts can contain terminal control characters which, for
3096          example, change the color, background, or style of the prompt
3097          text, or change the title of the terminal window. In order for
3098          the line editing features of <application>Readline</application> to work properly, these
3099          non-printing control characters must be designated as invisible
3100          by surrounding them with <literal>%[</literal> and
3101          <literal>%]</literal>. Multiple pairs of these can occur within
3102          the prompt.  For example:
3103 <programlisting>
3104 testdb=&gt; \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
3105 </programlisting>
3106          results in a boldfaced (<literal>1;</literal>) yellow-on-black
3107          (<literal>33;40</literal>) prompt on VT100-compatible, color-capable
3108          terminals.
3109         </para>
3110         </listitem>
3111       </varlistentry>
3112
3113     </variablelist>
3114
3115     To insert a percent sign into your prompt, write
3116     <literal>%%</literal>. The default prompts are
3117     <literal>'%/%R%# '</literal> for prompts 1 and 2, and
3118     <literal>'&gt;&gt; '</literal> for prompt 3.
3119     </para>
3120
3121     <note>
3122     <para>
3123     This feature was shamelessly plagiarized from
3124     <application>tcsh</application>.
3125     </para>
3126     </note>
3127
3128    </refsect3>
3129
3130    <refsect3>
3131     <title>Command-Line Editing</title>
3132
3133     <para>
3134     <application>psql</application> supports the <application>Readline</application>
3135     library for convenient line editing and retrieval. The command
3136     history is automatically saved when <application>psql</application>
3137     exits and is reloaded when
3138     <application>psql</application> starts up. Tab-completion is also
3139     supported, although the completion logic makes no claim to be an
3140     <acronym>SQL</acronym> parser.  If for some reason you do not like the tab completion, you
3141     can turn it off by putting this in a file named
3142     <filename>.inputrc</filename> in your home directory:
3143 <programlisting>
3144 $if psql
3145 set disable-completion on
3146 $endif
3147 </programlisting>
3148     (This is not a <application>psql</application> but a
3149     <application>Readline</application> feature. Read its documentation
3150     for further details.)
3151     </para>
3152    </refsect3>
3153   </refsect2>
3154  </refsect1>
3155
3156
3157  <refsect1>
3158   <title>Environment</title>
3159
3160   <variablelist>
3161
3162    <varlistentry>
3163     <term><envar>COLUMNS</envar></term>
3164
3165     <listitem>
3166      <para>
3167       If <literal>\pset columns</> is zero, controls the
3168       width for the <literal>wrapped</> format and width for determining
3169       if wide output requires the pager.
3170      </para>
3171     </listitem>
3172    </varlistentry>
3173
3174    <varlistentry>
3175     <term><envar>PAGER</envar></term>
3176
3177     <listitem>
3178      <para>
3179       If the query results do not fit on the screen, they are piped
3180       through this command.  Typical values are
3181       <literal>more</literal> or <literal>less</literal>.  The default
3182       is platform-dependent.  The use of the pager can be disabled by
3183       using the <command>\pset</command> command.
3184      </para>
3185     </listitem>
3186    </varlistentry>
3187
3188    <varlistentry>
3189     <term><envar>PGDATABASE</envar></term>
3190     <term><envar>PGHOST</envar></term>
3191     <term><envar>PGPORT</envar></term>
3192     <term><envar>PGUSER</envar></term>
3193
3194     <listitem>
3195      <para>
3196       Default connection parameters (see <xref linkend="libpq-envars">).
3197      </para>
3198     </listitem>
3199    </varlistentry>
3200
3201    <varlistentry>
3202     <term><envar>PSQL_EDITOR</envar></term>
3203     <term><envar>EDITOR</envar></term>
3204     <term><envar>VISUAL</envar></term>
3205
3206     <listitem>
3207      <para>
3208       Editor used by the <command>\e</command> command.  The variables
3209       are examined in the order listed; the first that is set is used.
3210      </para>
3211     </listitem>
3212    </varlistentry>
3213
3214    <varlistentry>
3215     <term><envar>SHELL</envar></term>
3216
3217     <listitem>
3218      <para>
3219       Command executed by the <command>\!</command> command.
3220      </para>
3221     </listitem>
3222    </varlistentry>
3223
3224    <varlistentry>
3225     <term><envar>TMPDIR</envar></term>
3226
3227     <listitem>
3228      <para>
3229       Directory for storing temporary files.  The default is
3230       <filename>/tmp</filename>.
3231      </para>
3232     </listitem>
3233    </varlistentry>
3234   </variablelist>
3235
3236   <para>
3237    This utility, like most other <productname>PostgreSQL</> utilities,
3238    also uses the environment variables supported by <application>libpq</>
3239    (see <xref linkend="libpq-envars">).
3240   </para>
3241
3242  </refsect1>
3243
3244
3245  <refsect1>
3246   <title>Files</title>
3247
3248   <itemizedlist>
3249    <listitem>
3250     <para>
3251      Unless it is passed an <option>-X</option>
3252      or <option>-c</option> option,
3253      <application>psql</application> attempts to
3254      read and execute commands from the system-wide
3255      <filename>psqlrc</filename> file and the user's
3256      <filename>~/.psqlrc</filename> file before starting up.
3257      (On Windows, the user's startup file is named
3258      <filename>%APPDATA%\postgresql\psqlrc.conf</filename>.)
3259      See <filename><replaceable>PREFIX</>/share/psqlrc.sample</>
3260      for information on setting up the system-wide file.  It could be used
3261      to set up the client or the server to taste (using the <command>\set
3262      </command> and <command>SET</command> commands).
3263     </para>
3264    </listitem>
3265
3266    <listitem>
3267     <para>
3268      Both the system-wide <filename>psqlrc</filename> file and the user's
3269      <filename>~/.psqlrc</filename> file can be made version-specific
3270      by appending a dash and the <productname>PostgreSQL</productname>
3271      release number, for example <filename>~/.psqlrc-&version;</filename>.
3272      A matching version-specific file will be read in preference to a
3273      non-version-specific file.
3274     </para>
3275    </listitem>
3276
3277    <listitem>
3278     <para>
3279      The command-line history is stored in the file
3280      <filename>~/.psql_history</filename>, or
3281      <filename>%APPDATA%\postgresql\psql_history</filename> on Windows.
3282     </para>
3283    </listitem>
3284   </itemizedlist>
3285  </refsect1>
3286
3287
3288  <refsect1>
3289   <title>Notes</title>
3290
3291     <itemizedlist>
3292       <listitem>
3293       <para>
3294        In an earlier life <application>psql</application> allowed the
3295        first argument of a single-letter backslash command to start
3296        directly after the command, without intervening whitespace.
3297        As of <productname>PostgreSQL</productname> 8.4 this is no
3298        longer allowed.
3299       </para>
3300       </listitem>
3301
3302       <listitem>
3303       <para>
3304        <application>psql</application> is only guaranteed to work smoothly
3305        with servers of the same version. That does not mean other combinations
3306        will fail outright, but subtle and not-so-subtle problems might come
3307        up.  Backslash commands are particularly likely to fail if the
3308        server is of a newer version than <application>psql</> itself.  However,
3309        backslash commands of the <literal>\d</> family should work with
3310        servers of versions back to 7.4, though not necessarily with servers
3311        newer than  <application>psql</> itself.
3312       </para>
3313       </listitem>
3314
3315     </itemizedlist>
3316  </refsect1>
3317
3318
3319  <refsect1>
3320   <title>Notes for Windows Users</title>
3321
3322  <para>
3323   <application>psql</application> is built as a <quote>console
3324   application</>.  Since the Windows console windows use a different
3325   encoding than the rest of the system, you must take special care
3326   when using 8-bit characters within <application>psql</application>.
3327   If <application>psql</application> detects a problematic
3328   console code page, it will warn you at startup. To change the
3329   console code page, two things are necessary:
3330
3331    <itemizedlist>
3332     <listitem>
3333      <para>
3334       Set the code page by entering <userinput>cmd.exe /c chcp
3335       1252</userinput>. (1252 is a code page that is appropriate for
3336       German; replace it with your value.) If you are using Cygwin,
3337       you can put this command in <filename>/etc/profile</filename>.
3338      </para>
3339     </listitem>
3340
3341     <listitem>
3342      <para>
3343       Set the console font to <literal>Lucida Console</>, because the
3344       raster font does not work with the ANSI code page.
3345      </para>
3346     </listitem>
3347    </itemizedlist>
3348  </para>
3349
3350  </refsect1>
3351
3352
3353  <refsect1 id="APP-PSQL-examples">
3354   <title id="APP-PSQL-examples-title">Examples</title>
3355
3356   <para>
3357   The first example shows how to spread a command over several lines of
3358   input. Notice the changing prompt:
3359 <programlisting>
3360 testdb=&gt; <userinput>CREATE TABLE my_table (</userinput>
3361 testdb(&gt; <userinput> first integer not null default 0,</userinput>
3362 testdb(&gt; <userinput> second text)</userinput>
3363 testdb-&gt; <userinput>;</userinput>
3364 CREATE TABLE
3365 </programlisting>
3366   Now look at the table definition again:
3367 <programlisting>
3368 testdb=&gt; <userinput>\d my_table</userinput>
3369              Table "my_table"
3370  Attribute |  Type   |      Modifier
3371 -----------+---------+--------------------
3372  first     | integer | not null default 0
3373  second    | text    |
3374
3375 </programlisting>
3376   Now we change the prompt to something more interesting:
3377 <programlisting>
3378 testdb=&gt; <userinput>\set PROMPT1 '%n@%m %~%R%# '</userinput>
3379 peter@localhost testdb=&gt;
3380 </programlisting>
3381   Let's assume you have filled the table with data and want to take a
3382   look at it:
3383 <programlisting>
3384 peter@localhost testdb=&gt; SELECT * FROM my_table;
3385  first | second
3386 -------+--------
3387      1 | one
3388      2 | two
3389      3 | three
3390      4 | four
3391 (4 rows)
3392
3393 </programlisting>
3394   You can display tables in different ways by using the
3395   <command>\pset</command> command:
3396 <programlisting>
3397 peter@localhost testdb=&gt; <userinput>\pset border 2</userinput>
3398 Border style is 2.
3399 peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table;</userinput>
3400 +-------+--------+
3401 | first | second |
3402 +-------+--------+
3403 |     1 | one    |
3404 |     2 | two    |
3405 |     3 | three  |
3406 |     4 | four   |
3407 +-------+--------+
3408 (4 rows)
3409
3410 peter@localhost testdb=&gt; <userinput>\pset border 0</userinput>
3411 Border style is 0.
3412 peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table;</userinput>
3413 first second
3414 ----- ------
3415     1 one
3416     2 two
3417     3 three
3418     4 four
3419 (4 rows)
3420
3421 peter@localhost testdb=&gt; <userinput>\pset border 1</userinput>
3422 Border style is 1.
3423 peter@localhost testdb=&gt; <userinput>\pset format unaligned</userinput>
3424 Output format is unaligned.
3425 peter@localhost testdb=&gt; <userinput>\pset fieldsep ","</userinput>
3426 Field separator is ",".
3427 peter@localhost testdb=&gt; <userinput>\pset tuples_only</userinput>
3428 Showing only tuples.
3429 peter@localhost testdb=&gt; <userinput>SELECT second, first FROM my_table;</userinput>
3430 one,1
3431 two,2
3432 three,3
3433 four,4
3434 </programlisting>
3435   Alternatively, use the short commands:
3436 <programlisting>
3437 peter@localhost testdb=&gt; <userinput>\a \t \x</userinput>
3438 Output format is aligned.
3439 Tuples only is off.
3440 Expanded display is on.
3441 peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table;</userinput>
3442 -[ RECORD 1 ]-
3443 first  | 1
3444 second | one
3445 -[ RECORD 2 ]-
3446 first  | 2
3447 second | two
3448 -[ RECORD 3 ]-
3449 first  | 3
3450 second | three
3451 -[ RECORD 4 ]-
3452 first  | 4
3453 second | four
3454 </programlisting>
3455   </para>
3456
3457  </refsect1>
3458
3459 </refentry>