Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions check_pgactivity
Original file line number Diff line number Diff line change
Expand Up @@ -2034,13 +2034,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
), true)).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,
Expand Down Expand Up @@ -2102,12 +2102,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
), true)).modification )
) AS oldest
)
ELSE NULL
END AS oldest
FROM (
SELECT last_archived_wal, last_archived_time, last_failed_wal,
walsegsize,
Expand Down
40 changes: 39 additions & 1 deletion t/01-archiver.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -157,6 +157,44 @@ 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 < '10';

# 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;
$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' );