Home Explore Blog CI



postgresql

9th chunk of `doc/src/sgml/ref/pg_ctl-ref.sgml`
9c4a2c994ada39fcc60fe7f913b05cec88c670aa1ca9e1720000000100000d69
 </para>

  <para>
   For additional variables that affect the server,
   see <xref linkend="app-postgres"/>.
  </para>
 </refsect1>


 <refsect1>
  <title>Files</title>

  <variablelist>
   <varlistentry>
    <term><filename>postmaster.pid</filename></term>

    <listitem>
     <para>
      <application>pg_ctl</application> examines this file in the data
      directory to determine whether the server is currently running.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><filename>postmaster.opts</filename></term>

    <listitem>
     <para>If this file exists in the data directory,
      <application>pg_ctl</application> (in <option>restart</option> mode)
      will pass the contents of the file as options to
      <application>postgres</application>, unless overridden
      by the <option>-o</option> option. The contents of this file
      are also displayed in <option>status</option> mode.
     </para>
    </listitem>
   </varlistentry>

  </variablelist>
 </refsect1>


 <refsect1 id="r1-app-pgctl-2">
  <title>Examples</title>

  <refsect2 id="r2-app-pgctl-3">
   <title>Starting the Server</title>

   <para>
    To start the server, waiting until the server is
    accepting connections:
<screen>
<prompt>$</prompt> <userinput>pg_ctl start</userinput>
</screen>
   </para>

   <para>
    To start the server using port 5433, and
    running without <function>fsync</function>, use:
<screen>
<prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
</screen></para>
  </refsect2>

  <refsect2 id="r2-app-pgctl-4">
   <title>Stopping the Server</title>
   <para>
    To stop the server, use:
<screen>
<prompt>$</prompt> <userinput>pg_ctl stop</userinput>
</screen>
    The <option>-m</option> option allows control over
    <emphasis>how</emphasis> the server shuts down:
<screen>
<prompt>$</prompt> <userinput>pg_ctl stop -m smart</userinput>
</screen></para>
  </refsect2>

  <refsect2 id="r2-app-pgctl-5">
   <title>Restarting the Server</title>

   <para>
    Restarting the server is almost equivalent to stopping the
    server and starting it again, except that by default,
    <command>pg_ctl</command> saves and reuses the command line options that
    were passed to the previously-running instance.  To restart
    the server using the same options as before, use:
<screen>
<prompt>$</prompt> <userinput>pg_ctl restart</userinput>
</screen>
   </para>

   <para>
    But if <option>-o</option> is specified, that replaces any previous options.
    To restart using port 5433, disabling <function>fsync</function> upon restart:
<screen>
<prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
</screen></para>
  </refsect2>

  <refsect2 id="r2-app-pgctl-6">
   <title>Showing the Server Status</title>

   <para>
    Here is sample status output from
    <application>pg_ctl</application>:
<screen>
<prompt>$</prompt> <userinput>pg_ctl status</userinput>
<computeroutput>
pg_ctl: server is running (PID: 13718)
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128"
</computeroutput></screen>
    The second line is the command that would be invoked in restart mode.
   </para>
  </refsect2>
 </refsect1>


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

  <simplelist type="inline">
   <member><xref linkend="app-initdb"/></member>
   <member><xref linkend="app-postgres"/></member>
  </simplelist>
 </refsect1>

</refentry>

Title: pg_ctl Examples and See Also
Summary
This section provides examples of using `pg_ctl` to start, stop, and restart the PostgreSQL server. It demonstrates how to start the server with default and custom options, including specifying the port and disabling fsync. It also shows how to stop the server with different shutdown modes and how to restart the server with or without reusing previous options. Additionally, it illustrates the output of the status command. Finally, it lists related documentation, including initdb and postgres.