aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/syslogger.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2018-09-01 19:46:49 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2018-09-01 19:46:49 +0300
commitec74369931687885cfb6ce9dac55deefdb410086 (patch)
treee40f466f4c0354fb679d72ad8a0785086dd673a3 /src/backend/postmaster/syslogger.c
parentab0ed6153a58294143d6d66ec5f3471477c59d57 (diff)
downloadpostgresql-ec74369931687885cfb6ce9dac55deefdb410086.tar.gz
postgresql-ec74369931687885cfb6ce9dac55deefdb410086.zip
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
Diffstat (limited to 'src/backend/postmaster/syslogger.c')
-rw-r--r--src/backend/postmaster/syslogger.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 2959d1374ee..29bdcec8958 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -57,6 +57,9 @@
*/
#define READ_BUF_SIZE (2 * PIPE_CHUNK_SIZE)
+/* Log rotation signal file path, relative to $PGDATA */
+#define LOGROTATE_SIGNAL_FILE "logrotate"
+
/*
* GUC parameters. Logging_collector cannot be changed after postmaster
@@ -405,7 +408,7 @@ SysLoggerMain(int argc, char *argv[])
{
/*
* Force rotation when both values are zero. It means the request
- * was sent by pg_rotate_logfile.
+ * was sent by pg_rotate_logfile() or "pg_ctl logrotate".
*/
if (!time_based_rotation && size_rotation_for == 0)
size_rotation_for = LOG_DESTINATION_STDERR | LOG_DESTINATION_CSVLOG;
@@ -1506,6 +1509,30 @@ update_metainfo_datafile(void)
* --------------------------------
*/
+/*
+ * Check to see if a log rotation request has arrived. Should be
+ * called by postmaster after receiving SIGUSR1.
+ */
+bool
+CheckLogrotateSignal(void)
+{
+ struct stat stat_buf;
+
+ if (stat(LOGROTATE_SIGNAL_FILE, &stat_buf) == 0)
+ return true;
+
+ return false;
+}
+
+/*
+ * Remove the file signaling a log rotateion request.
+ */
+void
+RemoveLogrotateSignalFiles(void)
+{
+ unlink(LOGROTATE_SIGNAL_FILE);
+}
+
/* SIGHUP: set flag to reload config file */
static void
sigHupHandler(SIGNAL_ARGS)