Large percentage of postgres installations, for example PGDG packages for Debian/Ubuntu, assume by default that log management will be handled by extrernals tools such as logrotate.

Unfortunately such tools have no way to tell postgres to reopen log file after rotation and forced to use copy-truncate strategy that leads to a loss of log messages which is unacceptable.

Small patch in the attachment implements logfile reopeninig on SIGHUP.
It only affects the file accessed by logging collector, which name you can check with pg_current_logfile().

I hope you will find this feature useful.

--
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

commit 3b3ea19d2dfb88dd0e3b31338a4b72a1cd0183e2
Author: Anastasia <a.lubennik...@postgrespro.ru>
Date:   Tue Feb 27 17:27:25 2018 +0300

    Reopen logfile and csv logfile on SIGHUP.

diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index f70eea3..54a5bdf 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -306,6 +306,24 @@ SysLoggerMain(int argc, char *argv[])
 		if (got_SIGHUP)
 		{
 			got_SIGHUP = false;
+
+			/* Reopen last logfiles on SIGHUP */
+			if (last_file_name != NULL)
+			{
+				fclose(syslogFile);
+				syslogFile = logfile_open(last_file_name, "a", false);
+				ereport(LOG,
+						(errmsg("Reopen current logfile on SIGHUP")));
+			}
+
+			if (last_csv_file_name != NULL)
+			{
+				fclose(csvlogFile);
+				csvlogFile = logfile_open(last_csv_file_name, "a", false);
+				ereport(LOG,
+						(errmsg("Reopen current CSV logfile on SIGHUP")));
+			}
+
 			ProcessConfigFile(PGC_SIGHUP);
 
 			/*

Reply via email to