1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add pg_current_logfile() function.

The syslogger will write out the current stderr and csvlog names, if
it's running and there are any, to a new file in the data directory
called "current_logfiles".  We take care to remove this file when it
might no longer be valid (but not at shutdown).  The function
pg_current_logfile() can be used to read the entries in the file.

Gilles Darold, reviewed and modified by Karl O.  Pinc, Michael
Paquier, and me.  Further review by Álvaro Herrera and Christoph Berg.
This commit is contained in:
Robert Haas
2017-03-03 11:32:45 +05:30
parent aea5d29836
commit 19dc233c32
12 changed files with 288 additions and 4 deletions

View File

@ -4280,6 +4280,11 @@ SELECT * FROM parent WHERE key = 2400;
<primary>where to log</primary>
</indexterm>
<indexterm>
<primary>current_logfiles</primary>
<secondary>and the log_destination configuration parameter</secondary>
</indexterm>
<variablelist>
<varlistentry id="guc-log-destination" xreflabel="log_destination">
@ -4310,6 +4315,27 @@ SELECT * FROM parent WHERE key = 2400;
<xref linkend="guc-logging-collector"> must be enabled to generate
CSV-format log output.
</para>
<para>
When either <systemitem>stderr</systemitem> or
<systemitem>csvlog</systemitem> are included, the file
<filename>current_logfiles</> is created to record the location
of the log file(s) currently in use by the logging collector and the
associated logging destination. This provides a convenient way to
find the logs currently in use by the instance. Here is an example of
this file's content:
<programlisting>
stderr pg_log/postgresql.log
csvlog pg_log/postgresql.csv
</programlisting>
<filename>current_logfiles</filename> is recreated when a new log file
is created as an effect of rotation, and
when <varname>log_destination</> is reloaded. It is removed when
neither <systemitem>stderr</systemitem>
nor <systemitem>csvlog</systemitem> are included
in <varname>log_destination</>, and when the logging collector is
disabled.
</para>
<note>
<para>

View File

@ -15478,6 +15478,13 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n);
<entry>configuration load time</entry>
</row>
<row>
<entry><literal><function>pg_current_logfile(<optional><type>text</></optional>)</function></literal></entry>
<entry><type>text</type></entry>
<entry>Primary log file name, or log in the requested format,
currently in use by the logging collector</entry>
</row>
<row>
<entry><literal><function>pg_my_temp_schema()</function></literal></entry>
<entry><type>oid</type></entry>
@ -15696,6 +15703,45 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
the time when the postmaster process re-read the configuration files.)
</para>
<indexterm>
<primary>pg_current_logfile</primary>
</indexterm>
<indexterm>
<primary>Logging</primary>
<secondary>pg_current_logfile function</secondary>
</indexterm>
<indexterm>
<primary>current_logfiles</primary>
<secondary>and the pg_current_logfile function</secondary>
</indexterm>
<indexterm>
<primary>Logging</primary>
<secondary>current_logfiles file and the pg_current_logfile
function</secondary>
</indexterm>
<para>
<function>pg_current_logfile</function> returns, as <type>text</type>,
the path of the log file(s) currently in use by the logging collector.
The path includes the <xref linkend="guc-log-directory"> directory
and the log file name. Log collection must be enabled or the return value
is <literal>NULL</literal>. When multiple log files exist, each in a
different format, <function>pg_current_logfile</function> called
without arguments returns the path of the file having the first format
found in the ordered list: <systemitem>stderr</>, <systemitem>csvlog</>.
<literal>NULL</literal> is returned when no log file has any of these
formats. To request a specific file format supply, as <type>text</type>,
either <systemitem>csvlog</> or <systemitem>stderr</> as the value of the
optional parameter. The return value is <literal>NULL</literal> when the
log format requested is not a configured
<xref linkend="guc-log-destination">. The
<function>pg_current_logfiles</function> reflects the contents of the
<filename>current_logfiles</> file.
</para>
<indexterm>
<primary>pg_my_temp_schema</primary>
</indexterm>

View File

@ -60,6 +60,12 @@ Item
<entry>Subdirectory containing per-database subdirectories</entry>
</row>
<row>
<entry><filename>current_logfiles</></entry>
<entry>File recording the log file(s) currently written to by the logging
collector</entry>
</row>
<row>
<entry><filename>global</></entry>
<entry>Subdirectory containing cluster-wide tables, such as