Nagios exchange:

Postgres Plugin:



The Postgres database server must be up and running.

In /var/lib/pgsql/data/pg_hba.conf, the authentication method for "local" should be "ident":

# "local" is for Unix domain socket connections only
local all all ident

CentOS and Perl packages

Perl must be installed (this is the default).

To install additional Perl modules, CPAN should be installed, too:

Perl Setup
yum -y install cpan
install YAML
install Time::HiRes
install Net::SMPP


Download and install the Postgres Plugin


Check for the latest version at, scroll down to "Download".



Download and install
cd /tmp
tar -xzf check_postgres*.tar.gz
cd check_postgres-*
cp /usr/local/nagios/libexec/

Set up the Postgres user "nagios"

Create Postgres User
su - postgres
CREATE USER nagios WITH PASSWORD 'some_password';
exit # back to root

Set up OS user "nagios"

To keep the Postgres password from preying eyes, a password file is is required in the home directory of OS user "nagios":

Password file
vi ~nagios/.pgpass
# insert:
# insert end (EOF)
# save and exit vi
chown nagios:nagios ~nagios/.pgpass
chmod 600 ~nagios/.pgpass

Test locally

su - nagios
cd /usr/local/nagios/libexec/
./ -H localhost -db template1 -u nagios --action connection
./ -H localhost -db template1 -u nagios --action dbstats
./ -H localhost -db template1 -u nagios --action bloat
# in the next statement, you should set the limits as appropriate
./ -H localhost -db template1 -u nagios --action=database_size --warning='30 GB' --critical='35 GB'
exit # back to root

Amend nrpe.cfg

Add the following lines to /usr/local/nagios/etc/nrpe.cfg


vi /usr/local/nagios/etc/nrpe.cfg
command[check_pg_connection]=/usr/local/nagios/libexec/ -H localhost -db template1 -u nagios --action connection
command[check_pg_dbstats]=/usr/local/nagios/libexec/ -H localhost -db template1 -u nagios --action dbstats
command[check_pg_bloat]=/usr/local/nagios/libexec/ -H localhost -db template1 -u nagios --action bloat
# in the next line, you should set the limits as appropriate
command[check_pg_database_size]=/usr/local/nagios/libexec/ -H localhost -db template1 -u nagios  --action database_size --warning='30 GB' --critical='35 GB'

Test on Nagios server

Replace the "yourserver.yourdomain.tld" with the IP address or IP name of your MySQL server:

/usr/local/nagios/libexec/check_nrpe -H yourserver.yourdomain.tld -c check_pg_connection

If the system returns "ERROR: Could not find a suitable psql executable", your Postgres installation may not use the default location. Normally this should be solved by setting the environment variable "PGBINDIR" to the path to psql, and adding this path to the PATH variable (e.g. in /etc/profile.d/), but for some reasons this doesn't work. You have to modify ""

vi /usr/local/nagios/libexec/
... locate the line starting with "$PGBINDIR ="
... and replace it with
$PGBINDIR = '/usr/local/pgsql/bin';
... or wherever your psql binary is installed.

  • No labels