mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +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:
@ -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)
|
||||
|
Reference in New Issue
Block a user