Skip to content

Commit 8e6b3c2

Browse files
committed
check_wal_files: Use pg_ls_waldir() on PG10+
Close #145
1 parent c26294b commit 8e6b3c2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

check_postgres.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -8682,8 +8682,8 @@ sub check_wal_files {
86828682

86838683
## Figure out where the pg_xlog directory is
86848684
$SQL = qq{SELECT count(*) AS count FROM $lsfunc($lsargs) WHERE $lsfunc ~ E'^[0-9A-F]{24}$extrabit\$'}; ## no critic (RequireInterpolationOfMetachars)
8685-
my $SQL10 = $SQL;
8686-
$SQL10 =~ s/pg_xlog/pg_wal/g unless ($opt{lsfunc});
8685+
my $SQL10 = $opt{lsfunc} ? $SQL :
8686+
qq{SELECT count(*) AS count FROM pg_ls_waldir() WHERE name ~ E'^[0-9A-F]{24}$extrabit\$'}; ## no critic (RequireInterpolationOfMetachars)
86878687

86888688
my $info = run_command($SQL, {regex => qr[\d], version => [">9.6 $SQL10"] });
86898689

t/02_wal_files.t

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ like ($cp->run('--critical=1'), qr{^$label CRITICAL}, $t);
4949

5050
$cp->drop_schema_if_exists();
5151
$cp->create_fake_pg_table('pg_ls_dir', 'text');
52+
if ($ver >= 100000) {
53+
$dbh->do("CREATE OR REPLACE FUNCTION cptest.pg_ls_waldir() RETURNS table(name text) AS 'SELECT * FROM cptest.pg_ls_dir' LANGUAGE SQL");
54+
}
5255
$dbh->commit();
5356

5457
like ($cp->run('--critical=1'), qr{^$label OK}, $t);
@@ -67,7 +70,7 @@ is ($cp->run('--critical=101 --output=mrtg'), "99\n0\n\n\n", $t);
6770

6871
# test --lsfunc
6972
my $xlogdir = $ver >= 100000 ? 'pg_wal' : 'pg_xlog';
70-
$dbh->do(qq{CREATE FUNCTION ls_xlog_dir()
73+
$dbh->do(qq{CREATE OR REPLACE FUNCTION ls_xlog_dir()
7174
RETURNS SETOF TEXT
7275
AS \$\$ SELECT pg_ls_dir('$xlogdir') \$\$
7376
LANGUAGE SQL

0 commit comments

Comments
 (0)