Home Explore Blog CI



postgresql

10th chunk of `doc/src/sgml/ref/postgres-ref.sgml`
e4059cd4eba91c94fd64ab242e004490cbfa7ebbbaa809af0000000100000f88

<screen>
<userinput>postgres --single -D /usr/local/pgsql/data <replaceable>other-options</replaceable> my_database</userinput>
</screen>
    Provide the correct path to the database directory with <option>-D</option>, or
    make sure that the environment variable <envar>PGDATA</envar> is set.
    Also specify the name of the particular database you want to work in.
   </para>

   <para>
    Normally, the single-user mode server treats newline as the command
    entry terminator; there is no intelligence about semicolons,
    as there is in <application>psql</application>.  To continue a command
    across multiple lines, you must type backslash just before each
    newline except the last one.  The backslash and adjacent newline are
    both dropped from the input command.  Note that this will happen even
    when within a string literal or comment.
   </para>

   <para>
    But if you use the <option>-j</option> command line switch, a single newline
    does not terminate command entry; instead, the sequence
    semicolon-newline-newline does.  That is, type a semicolon immediately
    followed by a completely empty line.  Backslash-newline is not
    treated specially in this mode.  Again, there is no intelligence about
    such a sequence appearing within a string literal or comment.
   </para>

   <para>
    In either input mode, if you type a semicolon that is not just before or
    part of a command entry terminator, it is considered a command separator.
    When you do type a command entry terminator, the multiple statements
    you've entered will be executed as a single transaction.
   </para>

   <para>
    To quit the session, type <acronym>EOF</acronym>
    (<keycombo action="simul"><keycap>Control</keycap><keycap>D</keycap></keycombo>, usually).
    If you've entered any text since the last command entry terminator,
    then <acronym>EOF</acronym> will be taken as a command entry terminator,
    and another <acronym>EOF</acronym> will be needed to exit.
   </para>

   <para>
    Note that the single-user mode server does not provide sophisticated
    line-editing features (no command history, for example).
    Single-user mode also does not do any background processing, such as
    automatic checkpoints or replication.
   </para>
 </refsect1>

 <refsect1 id="app-postgres-examples">
  <title>Examples</title>

  <para>
   To start <command>postgres</command> in the background
   using default values, type:

<screen>
<prompt>$</prompt> <userinput>nohup postgres &gt;logfile 2&gt;&amp;1 &lt;/dev/null &amp;</userinput>
</screen>
  </para>

  <para>
   To start <command>postgres</command> with a specific
   port, e.g., 1234:
<screen>
<prompt>$</prompt> <userinput>postgres -p 1234</userinput>
</screen>
   To connect to this server using <application>psql</application>, specify this port with the -p option:
<screen>
<prompt>$</prompt> <userinput>psql -p 1234</userinput>
</screen>
   or set the environment variable <envar>PGPORT</envar>:
<screen>
<prompt>$</prompt> <userinput>export PGPORT=1234</userinput>
<prompt>$</prompt> <userinput>psql</userinput>
</screen>
  </para>

  <para>
   Named run-time parameters can be set in either of these styles:
<screen>
<prompt>$</prompt> <userinput>postgres -c work_mem=1234</userinput>
<prompt>$</prompt> <userinput>postgres --work-mem=1234</userinput>
</screen>
   Either form overrides whatever setting might exist for
   <varname>work_mem</varname> in <filename>postgresql.conf</filename>.  Notice that
   underscores in parameter names can be written as either underscore
   or dash on the command line.  Except for short-term experiments,
   it's probably better practice to edit the setting in
   <filename>postgresql.conf</filename> than to rely on a command-line switch
   to set a parameter.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <para>
   <xref linkend="app-initdb"/>,
   <xref linkend="app-pg-ctl"/>
  </para>
 </refsect1>
</refentry>

Title: Postgres Single-User Mode Details and Examples
Summary
This section expands on Postgres' single-user mode, detailing command entry termination with newlines and the semicolon-newline-newline sequence with the `-j` option. It explains how semicolons function as command separators and how to quit the session using EOF. It also notes the lack of line-editing features and background processing. Furthermore, it provides examples of starting Postgres in the background, specifying a port, connecting via psql, and setting runtime parameters.