From 3351f3a2b65ca2ff348bf0ad5cd3c472260ae226 Mon Sep 17 00:00:00 2001 From: Thomas Reiss Date: Sat, 18 Oct 2025 17:39:51 +0200 Subject: [PATCH 1/5] Enrich tests for archiver This test should cover issue #358 --- t/01-archiver.t | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/01-archiver.t b/t/01-archiver.t index 8fb9034a..22db43c0 100644 --- a/t/01-archiver.t +++ b/t/01-archiver.t @@ -16,7 +16,7 @@ my $node = pgNode->get_new_node('prod'); my $pga_data = "$TestLib::tmp_check/pga.data"; my $wal; my @stdout; -my $num_tests = 25; +my $num_tests = 29; $node->init(has_archiving => 1); @@ -157,6 +157,40 @@ SKIP: { ); } +# Specific tests for PG9.4+, edge cases with pg_stat_archiver +# Covers issue #358 and #384 +SKIP: { + skip "checking with non superuser role is not supported before v10", 4 + if $node->version < '9.4'; + + # Turn archiving off, pg_stat_archiver remains + # see issue #358 and #384 + $node->stop; + $node->append_conf('postgresql.conf', "archive_mode = 'off'"); + $node->start; + $node->psql('template1', 'insert into t select generate_series(20001,30000) as i'); + $wal = $node->switch_wal; + + # Current behavior is to bail out an error "could not stat file" + + $node->command_checks_all( [ + './check_pgactivity', '--service' => 'archiver', + '--username' => $ENV{'USER'} || 'postgres', + '--status-file' => $pga_data, + '--format' => 'human' + ], + 0, + [ + # Should not return an error in this case + qr/^Service *: POSTGRES_ARCHIVER$/m, + qr/^Returns *: 0 \(OK\)$/m, + ], + [ qr/^$/ ], + 'do not bail out when archiver is off' + ); + +} + ### End of tests ### $node->stop( 'immediate' ); From 9c31890aa4db424523d33de60ae12f503667085c Mon Sep 17 00:00:00 2001 From: Thomas Reiss Date: Tue, 4 Nov 2025 14:46:18 +0100 Subject: [PATCH 2/5] Fixes check_archiver when archive_mode is off --- check_pgactivity | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/check_pgactivity b/check_pgactivity index 8d4491c1..9b488158 100755 --- a/check_pgactivity +++ b/check_pgactivity @@ -2030,13 +2030,13 @@ sub check_archiver { ELSE 0 END, last_archived_wal, last_failed_wal, /* mod time of the next wal to archive - * executed only if superuser */ + * executed only if superuser and archiving is on */ (SELECT extract('epoch' from (current_timestamp - (pg_stat_file('pg_wal/'||pg_walfile_name( (to_hex((last_archived_off+1)/4294967296) ||'/'||to_hex((last_archived_off+1)%4294967296))::pg_lsn ))).modification )) - WHERE current_setting('is_superuser')::bool + WHERE (current_setting('is_superuser')::bool AND current_setting('archive_mode') <> 'off') ) AS oldest FROM ( SELECT last_archived_wal, last_archived_time, last_failed_wal, @@ -2098,12 +2098,15 @@ sub check_archiver { ELSE 0 END, last_archived_wal, last_failed_wal, /* mod time of the next wal to archive */ - extract('epoch' from (current_timestamp - + CASE WHEN current_setting('archive_mode')::bool IS TRUE + THEN extract('epoch' from (current_timestamp - (pg_stat_file('pg_wal/'||pg_walfile_name( (to_hex((last_archived_off+1)/4294967296) ||'/'||to_hex((last_archived_off+1)%4294967296))::pg_lsn ))).modification ) - ) AS oldest + ) + ELSE NULL + END AS oldest FROM ( SELECT last_archived_wal, last_archived_time, last_failed_wal, walsegsize, From b8da1a4a895a7748221bbb58eddad55f623ff4ed Mon Sep 17 00:00:00 2001 From: Thomas Reiss Date: Tue, 4 Nov 2025 14:47:15 +0100 Subject: [PATCH 3/5] Fix test --- t/01-archiver.t | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/t/01-archiver.t b/t/01-archiver.t index 22db43c0..dec913ac 100644 --- a/t/01-archiver.t +++ b/t/01-archiver.t @@ -163,6 +163,10 @@ SKIP: { skip "checking with non superuser role is not supported before v10", 4 if $node->version < '9.4'; + # repair archiving + $node->append_conf('postgresql.conf', "archive_command = 'true'"); + $node->reload; + sleep(1); # Turn archiving off, pg_stat_archiver remains # see issue #358 and #384 $node->stop; From 419c1248810d60d794c2bdc468a8ed8a2bdcc992 Mon Sep 17 00:00:00 2001 From: Thomas Reiss Date: Tue, 4 Nov 2025 15:57:26 +0100 Subject: [PATCH 4/5] Shameful commit --- check_pgactivity | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/check_pgactivity b/check_pgactivity index e42035aa..c87badc7 100755 --- a/check_pgactivity +++ b/check_pgactivity @@ -2107,15 +2107,10 @@ sub check_archiver { (pg_stat_file('pg_wal/'||pg_walfile_name( (to_hex((last_archived_off+1)/4294967296) ||'/'||to_hex((last_archived_off+1)%4294967296))::pg_lsn -<<<<<<< HEAD - ))).modification ) + ), true)).modification ) ) ELSE NULL END AS oldest -======= - ), true)).modification ) - ) AS oldest ->>>>>>> master FROM ( SELECT last_archived_wal, last_archived_time, last_failed_wal, walsegsize, From 00519294182928ba287cf7ef0bd92198e53d0156 Mon Sep 17 00:00:00 2001 From: Thomas <2677100+frost242@users.noreply.github.com> Date: Wed, 5 Nov 2025 07:57:29 +0100 Subject: [PATCH 5/5] Fix version check in archiver unit test Per report from Guillaume Lelarge. --- t/01-archiver.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/01-archiver.t b/t/01-archiver.t index 9e577435..2f3ecf6c 100644 --- a/t/01-archiver.t +++ b/t/01-archiver.t @@ -161,7 +161,7 @@ SKIP: { # Covers issue #358 and #384 SKIP: { skip "checking with non superuser role is not supported before v10", 4 - if $node->version < '9.4'; + if $node->version < '10'; # repair archiving $node->append_conf('postgresql.conf', "archive_command = 'true'");