mirror of https://github.com/postgres/postgres
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 Korotkovpull/34/head
parent
ab0ed6153a
commit
ec74369931
@ -0,0 +1,42 @@ |
||||
use strict; |
||||
use warnings; |
||||
|
||||
use PostgresNode; |
||||
use TestLib; |
||||
use Test::More tests => 1; |
||||
use Time::HiRes qw(usleep); |
||||
|
||||
my $tempdir = TestLib::tempdir; |
||||
|
||||
my $node = get_new_node('primary'); |
||||
$node->init(allows_streaming => 1); |
||||
$node->append_conf( |
||||
'postgresql.conf', qq( |
||||
logging_collector = on |
||||
log_directory = 'log' |
||||
log_filename = 'postgresql.log' |
||||
)); |
||||
|
||||
$node->start(); |
||||
|
||||
# Rename log file and rotate log. Then log file should appear again. |
||||
|
||||
my $logfile = $node->data_dir . '/log/postgresql.log'; |
||||
my $old_logfile = $node->data_dir . '/log/postgresql.old'; |
||||
rename($logfile, $old_logfile); |
||||
|
||||
$node->logrotate(); |
||||
|
||||
# pg_ctl logrotate doesn't wait until rotation request being completed. So |
||||
# we have to wait some time until log file appears. |
||||
my $attempts = 0; |
||||
my $max_attempts = 180 * 10; |
||||
while (not -e $logfile and $attempts < $max_attempts) |
||||
{ |
||||
usleep(100_000); |
||||
$attempts++; |
||||
} |
||||
|
||||
ok(-e $logfile, "log file exists"); |
||||
|
||||
$node->stop(); |
Loading…
Reference in new issue