Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/psql-ref.sgml`
c66a7522f6495239b634dc520b93d8f7087983b0cb13e6b90000000100000fa7
<!--
doc/src/sgml/ref/psql-ref.sgml
PostgreSQL documentation
-->

<refentry id="app-psql">
 <indexterm zone="app-psql">
  <primary>psql</primary>
 </indexterm>

  <refmeta>
    <refentrytitle><application>psql</application></refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo>Application</refmiscinfo>
  </refmeta>

  <refnamediv>
    <refname><application>psql</application></refname>
    <refpurpose>
      <productname>PostgreSQL</productname> interactive terminal
    </refpurpose>
  </refnamediv>

 <refsynopsisdiv>
  <cmdsynopsis>
   <command>psql</command>
   <arg rep="repeat"><replaceable class="parameter">option</replaceable></arg>
   <arg choice="opt"><replaceable class="parameter">dbname</replaceable>
   <arg choice="opt"><replaceable class="parameter">username</replaceable></arg></arg>
  </cmdsynopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

    <para>
     <application>psql</application> is a terminal-based front-end to
     <productname>PostgreSQL</productname>. It enables you to type in
     queries interactively, issue them to
     <productname>PostgreSQL</productname>, and see the query results.
     Alternatively, input can be from a file or from command line
     arguments. In addition, <application>psql</application> provides a
     number of meta-commands and various shell-like features to
     facilitate writing scripts and automating a wide variety of tasks.
    </para>
 </refsect1>

 <refsect1 id="r1-app-psql-3">
  <title>Options</title>

  <variablelist>
    <varlistentry id="app-psql-option-echo-all">
      <term><option>-a</option></term>
      <term><option>--echo-all</option></term>
      <listitem>
      <para>
      Print all nonempty input lines to standard output as they are read.
      (This does not apply to lines read interactively.) This is
      equivalent to setting the variable <varname>ECHO</varname> to
      <literal>all</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-no-align">
      <term><option>-A</option></term>
      <term><option>--no-align</option></term>
      <listitem>
      <para>
      Switches to unaligned output mode. (The default output mode is
      <literal>aligned</literal>.)  This is equivalent to
      <command>\pset format unaligned</command>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-echo-errors">
      <term><option>-b</option></term>
      <term><option>--echo-errors</option></term>
      <listitem>
      <para>
      Print failed SQL commands to standard error output. This is
      equivalent to setting the variable <varname>ECHO</varname> to
      <literal>errors</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-command">
      <term><option>-c <replaceable class="parameter">command</replaceable></option></term>
      <term><option>--command=<replaceable class="parameter">command</replaceable></option></term>
      <listitem>
      <para>
       Specifies that <application>psql</application> is to execute the given
       command string, <replaceable class="parameter">command</replaceable>.
       This option can be repeated and combined in any order with
       the <option>-f</option> option.  When either <option>-c</option>
       or <option>-f</option> is specified, <application>psql</application>
       does not read commands from standard input; instead it terminates
       after processing all the <option>-c</option> and <option>-f</option>
       options in sequence.
      </para>
      <para>
       <replaceable class="parameter">command</replaceable> must be either
       a command string that is completely parsable by the server (i.e.,
       it contains no <application>psql</application>-specific features),
       or a single backslash command. Thus you cannot mix
       <acronym>SQL</acronym> and <application>psql</application>
       meta-commands within a <option>-c</option>

Title: Introduction to psql and its Options
Summary
This section introduces psql, the PostgreSQL interactive terminal, and its basic usage. Psql allows users to interactively type and execute queries, read input from files or command-line arguments, and provides meta-commands and shell-like features for scripting and automation. The section also details several command-line options for psql, including options for echoing input lines, setting output mode, printing failed SQL commands, and executing a given command string.