rotate-on-sighup-v2.patch
text/x-patch
Filename: rotate-on-sighup-v2.patch
Type: text/x-patch
Part: 0
Message:
Re: Reopen logfile on SIGHUP
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| doc/src/sgml/config.sgml | 17 | 0 |
| src/backend/postmaster/syslogger.c | 7 | 0 |
| src/backend/utils/misc/guc.c | 9 | 0 |
| src/backend/utils/misc/postgresql.conf.sample | 2 | 0 |
| src/include/postmaster/syslogger.h | 1 | 0 |
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 5d5f2d2..b49711f 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4912,6 +4912,23 @@ local0.* /var/log/postgresql
</listitem>
</varlistentry>
+ <varlistentry id="guc-log-rotate-on-sighup" xreflabel="log_rotate_on_sighup">
+ <term><varname>log_rotate_on_sighup</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>log_rotate_on_sighup</> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ When <varname>logging_collector</varname> is enabled,
+ this parameter will cause the log file to be rotated when the <command>
+ postgres</> server receives SIGHUP.
+ This parameter can only be set in the <filename>postgresql.conf</>
+ file or on the server command line.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-log-truncate-on-rotation" xreflabel="log_truncate_on_rotation">
<term><varname>log_truncate_on_rotation</varname> (<type>boolean</type>)
<indexterm>
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 58b759f..70091cd 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -64,6 +64,7 @@
bool Logging_collector = false;
int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR;
int Log_RotationSize = 10 * 1024;
+bool Log_rotate_on_sighup;
char *Log_directory = NULL;
char *Log_filename = NULL;
bool Log_truncate_on_rotation = false;
@@ -353,6 +354,12 @@ SysLoggerMain(int argc, char *argv[])
}
/*
+ * Force rotation on SIGHUP if configured to do so.
+ */
+ if (Log_rotate_on_sighup)
+ rotation_requested = true;
+
+ /*
* Force rewriting last log filename when reloading configuration.
* Even if rotation_requested is false, log_destination may have
* been changed and we don't want to wait the next file rotation.
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index fa92ce2..924dc0b 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1494,6 +1494,15 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
{
+ {"log_rotate_on_sighup", PGC_SIGHUP, LOGGING_WHERE,
+ gettext_noop("Automatic log file rotation will occur on SIGHUP."),
+ NULL
+ },
+ &Log_rotate_on_sighup,
+ false,
+ NULL, NULL, NULL
+ },
+ {
{"log_truncate_on_rotation", PGC_SIGHUP, LOGGING_WHERE,
gettext_noop("Truncate existing log files of same name during log rotation."),
NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 66d0938..0a8b88c 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -389,6 +389,8 @@
#log_rotation_size = 10MB # Automatic rotation of logfiles will
# happen after that much log output.
# 0 disables.
+#log_rotate_on_sighup = off # If on, automatic rotation of logfiles
+ # will happen on SIGHUP.
# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h
index b35fadc..3b45dd5 100644
--- a/src/include/postmaster/syslogger.h
+++ b/src/include/postmaster/syslogger.h
@@ -65,6 +65,7 @@ typedef union
extern bool Logging_collector;
extern int Log_RotationAge;
extern int Log_RotationSize;
+extern bool Log_rotate_on_sighup;
extern PGDLLIMPORT char *Log_directory;
extern PGDLLIMPORT char *Log_filename;
extern bool Log_truncate_on_rotation;