mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Implement "pg_ctl logrotate" command
Currently there are two ways to trigger log rotation in logging collector process: call pg_rotate_logfile() SQL-function or send SIGUSR1 signal directly to logging collector process. However, it's nice to have more suitable way for external tools to do that, which wouldn't require SQL connection or knowledge of logging collector pid. This commit implements triggering log rotation by "pg_ctl logrotate" command. Discussion: https://postgr.es/m/20180416.115435.28153375.horiguchi.kyotaro%40lab.ntt.co.jp Author: Kyotaro Horiguchi, Alexander Kuzmenkov, Alexander Korotkov
This commit is contained in:
@ -932,8 +932,8 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
|
||||
program if you have one that you are already using with other
|
||||
server software. For example, the <application>rotatelogs</application>
|
||||
tool included in the <productname>Apache</productname> distribution
|
||||
can be used with <productname>PostgreSQL</productname>. To do this,
|
||||
just pipe the server's
|
||||
can be used with <productname>PostgreSQL</productname>. One way to
|
||||
do this is to pipe the server's
|
||||
<systemitem>stderr</systemitem> output to the desired program.
|
||||
If you start the server with
|
||||
<command>pg_ctl</command>, then <systemitem>stderr</systemitem>
|
||||
@ -945,6 +945,36 @@ pg_ctl start | rotatelogs /var/log/pgsql_log 86400
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
You can combine these approaches by setting up <application>logrotate</application>
|
||||
to collect log files produced by <productname>PostgreSQL</productname> built-in
|
||||
logging collector. In this case, the logging collector defines the names and
|
||||
location of the log files, while <application>logrotate</application>
|
||||
periodically archives these files. When initiating log rotation,
|
||||
<application>logrotate</application> must ensure that the application
|
||||
sends further output to the new file. This is commonly done with a
|
||||
<literal>postrotate</literal> script that sends a <literal>SIGHUP</literal>
|
||||
signal to the application, which then reopens the log file.
|
||||
In <productname>PostgreSQL</productname>, you can run <command>pg_ctl</command>
|
||||
with the <literal>logrotate</literal> option instead. When the server receives
|
||||
this command, the server either switches to a new log file or reopens the
|
||||
existing file, depending on the logging configuration
|
||||
(see <xref linkend="runtime-config-logging-where"/>).
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
When using static log file names, the server might fail to reopen the log
|
||||
file if the max open file limit is reached or a file table overflow occurs.
|
||||
In this case, log messages are sent to the old log file until a
|
||||
successful log rotation. If <application>logrotate</application> is
|
||||
configured to compress the log file and delete it, the server may lose
|
||||
the messages logged in this timeframe. To avoid this issue, you can
|
||||
configure the logging collector to dynamically assign log file names
|
||||
and use a <literal>prerotate</literal> script to ignore open log files.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<para>
|
||||
Another production-grade approach to managing log output is to
|
||||
send it to <application>syslog</application> and let
|
||||
|
@ -97,6 +97,13 @@ PostgreSQL documentation
|
||||
<arg choice="opt"><option>-s</option></arg>
|
||||
</cmdsynopsis>
|
||||
|
||||
<cmdsynopsis>
|
||||
<command>pg_ctl</command>
|
||||
<arg choice="plain"><option>logrotate</option></arg>
|
||||
<arg choice="opt"><option>-D</option> <replaceable>datadir</replaceable></arg>
|
||||
<arg choice="opt"><option>-s</option></arg>
|
||||
</cmdsynopsis>
|
||||
|
||||
<cmdsynopsis>
|
||||
<command>pg_ctl</command>
|
||||
<arg choice="plain"><option>kill</option></arg>
|
||||
@ -226,6 +233,12 @@ PostgreSQL documentation
|
||||
and begin read-write operations.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<option>logrotate</option> mode rotates the server log file.
|
||||
For details on how to use this mode with external log rotation tools, see
|
||||
<xref linkend="logfile-maintenance"/>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<option>kill</option> mode sends a signal to a specified process.
|
||||
This is primarily valuable on <productname>Microsoft Windows</productname>
|
||||
|
Reference in New Issue
Block a user