You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow a wrapper function for wal_files and archive_ready as a non-superuser.
The wrapper function around pg_ls_dir() must hardcode the pg_xlog or
pgxlog/archive_status path, and should take no arguments. It must be
created as a superuser with SECURITY DEFINER.
$SQL = qq{SELECT count(*) AS count FROM pg_ls_dir('pg_xlog$subdir') WHERE pg_ls_dir ~ E'^[0-9A-F]{24}$extrabit\$'}; ## no critic (RequireInterpolationOfMetachars)
8203
+
$SQL = qq{SELECT count(*) AS count FROM $lsfunc($lsargs) WHERE $lsfunc ~ E'^[0-9A-F]{24}$extrabit\$'}; ## no critic (RequireInterpolationOfMetachars)
8200
8204
8201
8205
my$info = run_command($SQL, {regex=>qr[\d] });
8202
8206
@@ -8587,7 +8591,7 @@ =head2 B<archive_ready>
8587
8591
8588
8592
(C<symlink: check_postgres_archive_ready>) Checks how many WAL files with extension F<.ready>
8589
8593
exist in the F<pg_xlog/archive_status> directory, which is found
8590
-
off of your B<data_directory>. This action must be run as a superuser, in order to access the
8594
+
off of your B<data_directory>. If the I<--lsfunc> option is not used then this action must be run as a superuser, in order to access the
8591
8595
contents of the F<pg_xlog/archive_status> directory. The minimum version to use this action is
8592
8596
Postgres 8.1. The I<--warning> and I<--critical> options are simply the number of
8593
8597
F<.ready> files in the F<pg_xlog/archive_status> directory.
@@ -8597,9 +8601,26 @@ =head2 B<archive_ready>
8597
8601
If the archive command fail, number of WAL in your F<pg_xlog> directory will grow until
8598
8602
exhausting all the disk space and force PostgreSQL to stop immediately.
8599
8603
8600
-
Example 1: Check that the number of ready WAL files is 10 or less on host "pluto"
8604
+
To avoid connecting as a database superuser, a wrapper function around
8605
+
C<pg_ls_dir()> should be defined as a superuser with SECURITY DEFINER,
8606
+
and the I<--lsfunc> option used. This example function, if defined by
8607
+
a superuser, will allow the script to connect as a normal user
8608
+
I<nagios> with I<--lsfunc=ls_archive_status_dir>
8609
+
8610
+
BEGIN;
8611
+
CREATE FUNCTION ls_archive_status_dir()
8612
+
RETURNS SETOF TEXT
8613
+
AS $$ SELECT pg_ls_dir('pg_xlog/archive_status') $$
8614
+
LANGUAGE SQL
8615
+
SECURITY DEFINER;
8616
+
REVOKE ALL ON FUNCTION ls_archive_status_dir() FROM PUBLIC;
8617
+
GRANT EXECUTE ON FUNCTION ls_archive_status_dir() to nagios;
0 commit comments