Build Status Gem Version Code Climate Test Coverage Dependency Status



  • bin/check-postgres-alive.rb
  • bin/check-postgres-connections.rb
  • bin/metric-postgres-dbsize.rb
  • bin/metric-postgres-statsbgwriter.rb
  • bin/metric-postgres-statstable.rb
  • bin/check-postgres-replication.rb
  • bin/metric-postgres-graphite.rb
  • bin/metric-postgres-statsdb.rb
  • bin/metric-postgres-connections.rb
  • bin/metric-postgres-locks.rb
  • bin/metric-postgres-statsio.rb
  • bin/check-postgres-query.rb
  • bin/metrics-postgres-query.rb
  • bin/metric-postgres-relation-size.rb


Use --help to see command arguments.

Sample usage

Check if PostgreSQL is alive

$ check-postgres-alive.rb -d template1 -f /var/lib/postgresql/.pgpass
CheckPostgres OK: Server version: {"version"=>"PostgreSQL 9.6.3 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit"}

Check replication status

$ check-postgres-replication.rb -m psql1.local -s psql2.local -d template1 -w 5 -c 10
CheckPostgresReplicationStatus OK: replication delayed by 0.0MB :: master:B0/B4031000 slave:B0/B4031000 m_segbytes:16777216

Check number of connections

$ export PGPASSWORD=this-is-secret-password
$ check-postgres-connections.rb -a -w 80 -c 90 -d template1 -u sensu
CheckPostgresConnections OK: PostgreSQL connections under threshold: 17%, 174 out of 997 connections

Default values

Argument Env variable Value
-f, --pgpass PGPASSFILE ~/.pgpass
-h, --hostname PGHOST localhost
-P, --port PGPORT 5432
-d, --database PGDATABASE postgres
-u, --user PGUSER postgres
-p, --password PGPASSWORD

Options precedence is following:

  1. command line arguments
  2. pgpass file
  3. env variables
  4. defaults

Pgpass file

When file ~/.pgpass is found it is used by default. You can also use -f, --pgpass command line argument or set PGPASSFILE env variable.

File format is:


Only first line is used. If database is set to * it is ommited.

You can ovveride pgpass values with command line arguments, e.g. -h for hostname.


Sensu Go Asset Installation

Assets are the best way to make use of this plugin in Sensu Go. If you're not using an asset, please consider doing so! If you're using sensuctl 5.13 or later, you can use the following command to add the asset:

sensuctl asset add sensu-plugins/sensu-plugins-postgresl

If you're using an earlier version of sensuctl, you can download the asset definition from this project's Bonsai Asset Index page.

Note: as of version 4.0.0 the plugin assets are built using the sensu-ruby26-runtime, and will also require that you have the sensu-ruby26-runtime asset and installed as part of the check configuration.

Gem Installation

If you are unable to use the provided Sensu asset package, you can install this plugin via rubygems on a system that have ruby available.

gem install sensu-plugins-postgres

See Installation and Setup for details.

Known issues

When using Sensu with EMBEDDED_RUBY=true and installing Postgres checks with /usr/bin/sensu-install -p sensu-plugins-postgres you might get following error:

ERROR:  Error installing sensu-plugins-postgres:
    ERROR: Failed to build gem native extension.
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***

The reason is that libssl library which comes with Sensu is incompatible with libpq library installed on your system. There is no easy way to fix it. You might want to install sensu-plugins-postgres globally with gem install sensu-plugins-postgres.

Checks are in /usr/local/bin directory.