CHECK_POSTGRES(1)

πŸ“¦
version 2.26.0 Β· 4 versions
, in opensuse-leap 16.0

πŸ’– CHECK_POSTGRES(1) πŸ’–

okay bestie, gather round β€” this is the manual page for check_postgres.pl, from User Contributed Perl Documentation, and it covers version 2.26.0. It’s a Postgres monitoring script for Nagios, MRTG, Cacti, and others. Yes, it’s giving main character energy in your monitoring stack. πŸ’…


✨ NAME ✨

check_postgres.pl β€” a Postgres monitoring script for Nagios, MRTG, Cacti, and others.

This page documents check_postgres.pl version 2.26.0. Periodt.


🌸 SYNOPSIS 🌸

## Create all symlinks
check_postgres.pl --symlinks

## Check connection to Postgres database 'pluto':
check_postgres.pl --action=connection --db=pluto

## Same things, but using the symlink
check_postgres_connection --db=pluto

## Warn if > 100 locks, critical if > 200, or > 20 exclusive
check_postgres_locks --warning=100 --critical="total=200:exclusive=20"

## Show the current number of idle connections on port 6543:
check_postgres_txn_idle --port=6543 --output=simple

## There are many other actions and options, please keep reading.

The latest news and documentation can always be found at: https://bucardo.org/check_postgres/


πŸ¦‹ DESCRIPTION πŸ¦‹

check_postgres.pl is a Perl script that runs many different tests against one or more Postgres databases. It uses the psql program to gather the information, and outputs the results in one of three formats: Nagios, MRTG, or simple. Lowkey iconic. ✨

πŸŽ€ Output Modes πŸŽ€

The output can be changed by use of the --output option. The default output is nagios, although this can be changed at the top of the script if you wish. The current option choices are nagios, mrtg, and simple. To avoid having to enter the output argument each time, the type of output is automatically set if no --output argument is given, and if the current directory has one of the output options in its name. For example, creating a directory named mrtg and populating it with symlinks via the --symlinks argument would ensure that any actions run from that directory will always default to an output of β€œmrtg”. As a shortcut for --output=simple, you can enter --simple, which also overrides the directory naming trick.

πŸ’… Nagios output πŸ’…

The default output format is for Nagios, which is a single line of information, along with four specific exit codes:

  • 0 (OK)
  • 1 (WARNING)
  • 2 (CRITICAL)
  • 3 (UNKNOWN)

The output line is one of the words above, a colon, and then a short description of what was measured. Additional statistics information, as well as the total time the command took, can be output as well: see the documentation on the arguments --showperf, --perflimit, and --showtime.

πŸ’€ MRTG output πŸ’€

The MRTG output is four lines, with the first line always giving a single number of importance. When possible, this number represents an actual value such as a number of bytes, but it may also be a 1 or a 0 for actions that only return β€œtrue” or β€œfalse”, such as check_postgres_version. The second line is an additional stat and is only used for some actions. The third line indicates an β€œuptime” and is not used. The fourth line is a description and usually indicates the name of the database the stat from the first line was pulled from, but may be different depending on the action.

Some actions accept an optional --mrtg argument to further control the output.

See the documentation on each action for details on the exact MRTG output for each one.

πŸ“ Simple output πŸ“

The simple output is simply a truncated version of the MRTG one, and simply returns the first number and nothing else. This is very useful when you just want to check the state of something, regardless of any threshold. You can transform the numeric output by appending KB, MB, GB, TB, or EB to the output argument, for example:

--output=simple,MB

🧚 Cacti output 🧚

The Cacti output consists of one or more items on the same line, with a simple name, a colon, and then a number. At the moment, the only action with explicit Cacti output is dbstats, and using the --output option is not needed in this case, as Cacti is the only output for this action. For many other actions, using --simple is enough to make Cacti happy.


πŸ‘‘ DATABASE CONNECTION OPTIONS πŸ‘‘

All actions accept a common set of database options. Obsessed with consistency, honestly.

  • -H NAME / --host=NAME β€” Connect to the host indicated by NAME. Can be a comma-separated list of names. Multiple host arguments are allowed. If no host is given, defaults to the PGHOST environment variable or no host at all (which indicates using a local Unix socket). You may also use --dbhost.
  • -p PORT / --port=PORT β€” Connects using the specified PORT number. Can be a comma-separated list of port numbers, and multiple port arguments are allowed. If no port number is given, defaults to the PGPORT environment variable. If that is not set, it defaults to 5432. You may also use --dbport.
  • -db NAME / --dbname=NAME β€” Specifies which database to connect to. Can be a comma-separated list of names, and multiple dbname arguments are allowed. If no dbname option is provided, defaults to the PGDATABASE environment variable. If that is not set, it defaults to postgres if psql is version 8 or greater, and template1 otherwise.
  • -u USERNAME / --dbuser=USERNAME β€” The name of the database user to connect as. Can be a comma-separated list of usernames, and multiple dbuser arguments are allowed. If this is not provided, it defaults to the PGUSER environment variable, otherwise it defaults to postgres.
  • --dbpass=PASSWORD β€” Provides the password to connect to the database with. Use of this option is highly discouraged. Instead, one should use a .pgpass or pg_service.conf file. No cap, please don’t put passwords on the command line. 😭
  • --dbservice=NAME β€” The name of a service inside of the pg_service.conf file. Before version 9.0 of Postgres, this is a global file, usually found in /etc/pg_service.conf. If you are using version 9.0 or higher of Postgres, you can use the file .pg_service.conf in the home directory of the user running the script, e.g. nagios.

This file contains a simple list of connection options. You can also pass additional information when using this option such as --dbservice="maindatabase sslmode=require"

The documentation for this file can be found at https://www.postgresql.org/docs/current/static/libpq-pgservice.html

  • --role=ROLE β€” Provides the role to switch to after connecting to the database but before running the given check. This provides the ability to have superuser privileges assigned to a role without LOGIN access for the purposes of audit and other security considerations. Requires a local psql version 9.6 or higher.

The database connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344 would connect to a-1234, b-1234, and c-3344. Note that once set, an option carries over until it is changed again.

Examples:

--host=a,b --port=5433 --db=c
Connects twice to port 5433, using database c, to hosts a and b: a-5433-c b-5433-c

--host=a,b --port=5433 --db=c,d
Connects four times: a-5433-c a-5433-d b-5433-c b-5433-d

--host=a,b --host=foo --port=1234 --port=5433 --db=e,f
Connects six times: a-1234-e a-1234-f b-1234-e b-1234-f foo-5433-e foo-5433-f

--host=a,b --host=x --port=5432,5433 --dbuser=alice --dbuser=bob -db=baz
Connects three times: a-5432-alice-baz b-5433-alice-baz x-5433-bob-baz

--dbservice="foo" --port=5433
Connects using the named service 'foo' in the pg_service.conf file, but overrides the port

✨ OTHER OPTIONS ✨

okay so there's a whole pile of other options too β€” here's the full rundown, bestie:

  • --action=NAME β€” tells the script which action we're running. It's required … unless you're using a symlinked file, in which case the name of the file itself is used to figure out the action. sneaky but cute πŸ’…
  • --warning=VAL or -w VAL β€” sets the threshold where a warning alert fires. The valid values for this one depend on which action you're using.
  • --critical=VAL or -c VAL β€” sets the threshold where a critical alert fires. Again, valid values depend on the action.
  • -t VAL or --timeout=VAL β€” sets the timeout in seconds, after which the script will abort whatever it's doing and return an UNKNOWN status. Heads up: the timeout is per Postgres cluster, not for the entire script. Default value is 10, and the units are always in seconds.
  • --assume-standby-mode β€” if you specify this, first the check for whether the server is in standby mode gets performed (--datadir is required). If it is in standby, then all checks that require SQL queries get ignored, and "Server in standby mode" with OK status is returned instead. iconic lazy-girl behavior honestly πŸ¦‹

Example:

postgres@db$./check_postgres.pl --action=version --warning=8.1 --datadir /var/lib/postgresql/8.3/main/ --assume-standby-mode
POSTGRES_VERSION OK:  Server in standby mode | time=0.00
  • --assume-prod β€” if specified, a check for whether the server is in production mode gets performed (--datadir is required). This option is only relevant for check_postgres_checkpoint.

Example:

postgres@db$./check_postgres.pl --action=checkpoint --datadir /var/lib/postgresql/8.3/main/ --assume-prod
POSTGRES_CHECKPOINT OK: Last checkpoint was 72 seconds ago | age=72;;300 mode=MASTER
  • --assume-async β€” if specified, indicates that any replication between servers is asynchronous. This option is only relevant for check_postgres_same_schema.

Example:

postgres@db$./check_postgres.pl --action=same_schema --assume-async --dbhost=star,line
  • -h or --help β€” shows a help screen with a summary of all the actions and options. your lil cheat sheet 🫢
  • --man β€” shows the entire manual. like, the whole thing. yes, all of it.
  • -V or --version β€” shows the current version.
  • -v or --verbose β€” sets the verbosity level. You can call it more than once to boost the level. Setting it to three or higher (in other words, issuing -v -v -v) turns on debugging information for this program, which gets sent to stderr. go off, detective πŸ”
  • --showperf=VAL β€” decides whether we output additional performance data in standard Nagios format (at the end of the string, after a pipe symbol, using name=value). VAL should be 0 or 1. The default is 1. Only takes effect if you're using Nagios output mode.
  • --perflimit=i β€” sets a limit on how many items of interest get reported back when using the showperf option. This only has an effect for actions that return a large number of items, like table_size. The default is 0, meaning no limit. ⚠️ Be careful using this with the --include or --exclude options β€” those restrictions happen after the query has been run, so your limit might not include the items you actually want. Only takes effect if using Nagios output mode.
  • --showtime=VAL β€” decides whether the time taken to run each query gets shown in the output. VAL should be 0 or 1. The default is 1. No effect unless showperf is on. Only takes effect if using Nagios output mode.
  • --test β€” enables test mode. See the "TEST MODE" section below. yes queen, go read it πŸ’–
  • --PGBINDIR=PATH β€” tells the script where to find the psql binaries. Super useful if you've got more than one version of the PostgreSQL executables on your system, or if they're just not in your path. Note that this option is in all uppercase. By default, this option is not allowed β€” to enable it, you have to change the $NO_PSQL_OPTION near the top of the script to 0. Avoid using this option if you can, and instead use the environment variable PGBINDIR or the hard-coded $PGBINDIR variable, also near the top of the script, to set the path to the PostgreSQL to use.
  • --PSQL=PATH β€” (deprecated, this option may be removed in a future release! πŸ’€) Tells the script where to find the psql program. Useful if you have more than one version of the psql executable on your system, or if there's no psql program in your path. Note that this option is in all uppercase. By default, this option is not allowed β€” to enable it, you must change the $NO_PSQL_OPTION near the top of the script to 0. Avoid using this option if you can, and instead hard-code your psql location into the $PSQL variable, also near the top of the script.
  • --symlinks β€” creates symlinks to the main program for each action. cute lil copies 🌸
  • --output=VAL β€” determines the format of the output, for use in various programs. The default is 'nagios'. Available options are 'nagios', 'mrtg', 'simple' and 'cacti'.
  • --mrtg=VAL β€” used only for the MRTG or simple output, for a few specific actions.
  • --debugoutput=VAL β€” outputs the exact string returned by psql, for use in debugging. The value is one or more letters, which determine whether the output is displayed or not, where 'a' = all, 'c' = critical, 'w' = warning, 'o' = ok, and 'u' = unknown. Letters can be combined. mix and match bestie πŸŽ€
  • --get_method=VAL β€” lets you specify the method used to fetch information for the "new_version_cp", "new_version_pg", "new_version_bc", "new_version_box", and "new_version_tnm" checks. The following programs get tried, in order, to grab the information from the web: GET, wget, fetch, curl, lynx, links. To force the use of just one (and thus remove the overhead of trying all the others until one of those works), enter one of the names as the argument to get_method. For example, a BSD box might enter the following line in their .check_postgresrc file:
get_method=fetch
  • --language=VAL β€” sets the language to use for all output messages. Normally this is detected by examining the environment variables LC_ALL, LC_MESSAGES, and LANG, but setting this option overrides any such detection. multilingual icon ✨

πŸ‘‘ ACTIONS πŸ‘‘

The action to be run is selected using the --action flag, or by using a symlink to the main file that contains the name of the action inside of it. For example, to run the action "timesync", you may either issue:

check_postgres.pl --action=timesync

or use a program named:

check_postgres_timesync

All the symlinks get created for you in the current directory if you use the option --symlinks:

perl check_postgres.pl --symlinks

If the file name already exists, it will not be overwritten. If the file exists and is a symlink, you can force it to overwrite by using --action=build_symlinks_force. lowkey stubborn, but okay πŸ™ˆ

Most actions take a --warning and a --critical option, indicating at what point we change from OK to WARNING, and at what point we go to CRITICAL. Note that because criticals are always checked first, setting the warning equal to the critical is an effective way to turn warnings off and always give a critical. big brain move fr fr 🧠✨

The current supported actions are:

archive_ready

("symlink: check_postgres_archive_ready") Checks how many WAL files with extension .ready exist in the pg_xlog/archive_status directory (PostgreSQL 10 and later: pg_wal/archive_status), which is found off of your data_directory. If the --lsfunc option is not used, then this action must be run as a superuser, in order to access the contents of the pg_xlog/archive_status directory. The minimum version to use this action is Postgres 8.1. The --warning and --critical options are simply the number of .ready files in the pg_xlog/archive_status directory. Usually these values should be low β€” when we turn on the archive mechanism, we usually want it to archive WAL files as fast as possible.

If the archive command fails, the number of WAL files in your pg_xlog directory will grow until it exhausts all the disk space and forces PostgreSQL to stop immediately. 😭 so maybe don't let that happen

To avoid running as a database superuser, a wrapper function around pg_ls_dir() should be defined as a superuser with SECURITY DEFINER, and the --lsfunc option used. This example function, if defined by a superuser, will allow the script to connect as a normal user nagios with --lsfunc=ls_archive_status_dir

BEGIN;
CREATE FUNCTION ls_archive_status_dir()
    RETURNS SETOF TEXT
    AS $$ SELECT pg_ls_dir('pg_xlog/archive_status') $$
    LANGUAGE SQL
    SECURITY DEFINER;
REVOKE ALL ON FUNCTION ls_archive_status_dir() FROM PUBLIC;
GRANT EXECUTE ON FUNCTION ls_archive_status_dir() to nagios;
COMMIT;

Example 1: Check that the number of ready WAL files is 10 or less on host "pluto", using a wrapper function "ls_archive_status_dir" to avoid the need for superuser permissions

check_postgres_archive_ready --host=pluto --critical=10 --lsfunc=ls_archive_status_dir

For MRTG output, reports the number of ready WAL files on line 1.

autovac_freeze

("symlink: check_postgres_autovac_freeze") Checks how close each database is to the Postgres autovacuum_freeze_max_age setting. This action will only work for databases version 8.2 or higher. The --warning and --critical options should be expressed as percentages. The 'age' of the transactions in each database is compared to the autovacuum_freeze_max_age setting (200 million by default) to generate a rounded percentage. The default values are 90% for the warning and 95% for the critical. Databases can be filtered by use of the --include and --exclude options. See the "BASIC FILTERING" section for more details.

Example 1: Give a warning when any databases on port 5432 are above 97%

check_postgres_autovac_freeze --port=5432 --warning="97%"

For MRTG output, the highest overall percentage is reported on the first line, and the highest age is reported on the second line. All databases which have the percentage from the first line are reported on the fourth line, separated by a pipe symbol. πŸ“Š

backends πŸ”Œ

("symlink: check_postgres_backends") Okay bestie, this one counts how many connections you've got going on for one or more databases, and if you want, it'll compare that to the maximum allowed β€” which it figures out from the Postgres config variable max_connections. Slay.

The --warning and --critical options are flexible like that, and can take one of three forms:

  1. A plain number β€” that's literally the number of connections at which the alert fires. This choice does not use the max_connections setting, so it's fully your call.
  2. A percentage of available connections.
  3. A negative number β€” which means "the number of connections left until max_connections is reached."

Defaults for --warning and --critical are '90%' and '95%', iykyk.

You can also filter the databases with the --include and --exclude options β€” see the "BASIC FILTERING" section for the deets. ✨

Wanna see only non-idle processes? Use the --noidle argument. Small catch though: the user you're running as (either connecting directly or switching via --role) must be a superuser for this to work properly. No cap.

Example 1: warning when the number of connections on host quirm hits 120, critical at 150.

check_postgres_backends --host=quirm --warning=120 --critical=150

Example 2: critical when we hit 75% of our max_connections setting on hosts lancre or lancre2.

check_postgres_backends --warning='75%' --critical='75%' --host=lancre,lancre2

Example 3: warning when there are only 10 more connection slots left on host plasmid, critical when only 5 are left.

check_postgres_backends --warning=-10 --critical=-5 --host=plasmid

Example 4: check all databases except the ones with "test" in their name, but allow the ones named "pg_greatest". Connect as port 5432 on the first two hosts, and port 5433 on the third one. And we want to always throw a critical when we reach 30 or more connections.

check_postgres_backends --dbhost=hong,kong --dbhost=fooey --dbport=5432 --dbport=5433 --warning=30 --critical=30 --exclude="~test" --include="pg_greatest,~prod"

For MRTG output, the number of connections is reported on the first line, and the fourth line gives the name of the database plus the current maximum_connections. And if more than one database got queried? You get the one with the highest number of connections. πŸ’…


bloat 🎈

("symlink: check_postgres_bloat") This one checks the amount of bloat in tables and indexes. (Bloat is generally the amount of dead unused space taken up in a table or index β€” and that space usually gets reclaimed by use of the VACUUM command, in case you were wondering.) Heads up: this action requires that stats collection be enabled on the target databases, and it requires that ANALYZE is run frequently. Not optional, bestie.

The --include and --exclude options can filter out which tables to look at β€” see "BASIC FILTERING" for more.

The --warning and --critical options can be specified as sizes, percents, or both. Valid size units are bytes, kilobytes, megabytes, gigabytes, terabytes, exabytes, petabytes, and zettabytes β€” and you can abbreviate all of those with the first letter. Items without units are assumed to be 'bytes'. Defaults are '1 GB' and '5 GB'. The value represents the number of "wasted bytes" β€” aka the difference between what is actually used by the table and index, and what we compute that it should be.

Okay so there's a thing: this action has two hard-coded values to avoid false alarms on smaller relations. Tables must have at least 10 pages, and indexes at least 15, before they can even be considered by this test. If you really want to adjust these, go look for the variables $MINPAGES and $MINIPAGES at the top of the "check_bloat" subroutine. These values are ignored if either --exclude or --include is used.

Only the top 10 most bloated relations are shown. Want more? Use the --perflimit option to set your own limit. 🌈

The schema named 'information_schema' is excluded from this test, because the only tables it contains are small and do not change.

Also please note: the values computed by this action are not precise, and should be used as a guideline only. Great effort was made to estimate the correct size of a table, but in the end it's only an estimate. The correct index size is even more of a guess than the correct table size β€” but both should give you a rough idea of how bloated things are. πŸ™ˆ

Example 1: warn if any table on port 5432 is over 100 MB bloated, critical if over 200 MB.

check_postgres_bloat --port=5432 --warning='100 M' --critical='200 M'

Example 2: critical if table 'orders' on host 'sami' has more than 10 megs of bloat.

check_postgres_bloat --host=sami --include=orders --critical='10 MB'

Example 3: critical if table 'q4' on database 'sales' is over 50% bloated.

check_postgres_bloat --db=sales --include=q4 --critical='50%'

Example 4: critical if any table is over 20% bloated and has over 150 MB of bloat:

check_postgres_bloat --port=5432 --critical='20% and 150 M'

Example 5: critical if any table is over 40% bloated or has over 500 MB of bloat:

check_postgres_bloat --port=5432 --warning='500 M or 40%'

For MRTG output: the first line gives the highest number of wasted bytes for the tables, and the second line gives the highest number of wasted bytes for the indexes. The fourth line gives the database name, table name, and index name information. And if you'd rather output the bloat ratio instead (how many times larger the relation is compared to how large it should be), just pass in "--mrtg=ratio". πŸ¦‹


checkpoint ⏱️

("symlink: check_postgres_checkpoint") Determines how long since the last checkpoint has been run. Big thing: this must run on the same server as the database being checked (so like, the -h flag will not work, sorry). This check is meant to run on a "warm standby" server that's actively processing shipped WAL files, and it's meant to check that your warm standby is truly 'warm'. πŸ”₯

The data directory must be set β€” either by the environment variable "PGDATA", or by passing the "--datadir" argument. It returns the number of seconds since the last checkpoint was run, as determined by parsing the call to "pg_controldata". Because of that, the pg_controldata executable must be available in the current path. Alternatively, you can specify "PGBINDIR" as the directory it lives in. ✨

It's also possible to use the special options --assume-prod or --assume-standby-mode β€” and if the mode found is not the one expected, a CRITICAL is emitted. 😭

At least one warning or critical argument must be set.

This action requires the Date::Parse module.

For MRTG or simple output, it returns the number of seconds. πŸŽ€


cluster_id πŸ†”

("symlink: check_postgres_cluster-id") Checks that the Database System Identifier provided by pg_controldata is the same as the last time you checked. Same deal as before: this must run on the same server as the database being checked (the -h flag will not work).

Either the --warning or the --critical option should be given, but not both. The value of each one is the cluster identifier, an integer value. And you can run with the special "--critical=0" option to find out an existing cluster identifier. πŸ‘‘

Example 1: find the initial identifier.

check_postgres_cluster_id --critical=0 --datadir=/var//lib/postgresql/9.0/main

Example 2: make sure the cluster is the same and warn if not, using the result from above.

check_postgres_cluster_id  --critical=5633695740047915135

For MRTG output, it returns a 1 or 0 indicating success or failure of the identifier to match. An identifier must be provided as the "--mrtg" argument. The fourth line always gives the current identifier. πŸ’–


commitratio πŸ“Š

("symlink: check_postgres_commitratio") Checks the commit ratio of all databases and complains when they're too low. Good news: there's no need to run this command more than once per database cluster. Databases can be filtered with the --include and --exclude options β€” see "BASIC FILTERING". They can also be filtered by the owner of the database with the --includeuser and --excludeuser options β€” see "USER NAME FILTERING". ✨

The warning and critical options should be specified as percentages. There are no defaults for this action: the warning and critical must be specified. Also, the warning value cannot be greater than the critical value. The output returns all databases sorted by commitratio, smallest first.

Example: warn if any database on host flagg is less than 90% in commitratio, and critical if less than 80%.

check_postgres_database_commitratio --host=flagg --warning='90%' --critical='80%'

For MRTG output, it returns the percentage of the database with the smallest commitratio on the first line, and the name of the database on the fourth line. πŸ“


connection πŸ”—

("symlink: check_postgres_connection") Literally the simplest one: it connects, issues a 'SELECT version()', and leaves. That's it. It takes no --warning or --critical options. πŸ’…

For MRTG output, it simply outputs a 1 (good connection) or a 0 (bad connection) on the first line.


custom_query 🧚

("symlink: check_postgres_custom_query") Runs a custom query of your choosing and parses the results. The query itself is passed in through the "query" argument, and should be kept as simple as possible β€” if at all possible, wrap it in a view or a function to keep things easier to manage. πŸ’œ

The query should return one or two columns. It is required that one of the columns be named "result", and that's the item that gets checked against your warning and critical values. The second column is for the performance data and any name can be used: this will be the 'value' inside the performance data section.

At least one warning or critical argument must be specified. What these are set to depends on the type of query you're running. There are four types of custom_queries that can be run, specified by the "valtype" argument. If none is specified, this action defaults to 'integer'. The four types are:

  • integer: does a simple integer comparison. The first column should be a simple integer, and the warning and critical values should be the same.
  • string: the warning and critical are strings, and are triggered only if the value in the first column matches it exactly. This is case-sensitive, so watch that lowercase, bestie.
  • time: the warning and the critical are times, and can have units of seconds, minutes, hours, or days. Each may be written singular or abbreviated to just the first letter. If no units are given, seconds are assumed. The first column should be an integer representing the number of seconds to check.
  • size β€” the warning and the critical are straight-up sizes, bestie, and they can carry units of bytes, kilobytes, megabytes, gigabytes, terabytes, or exabytes. Each one can be abbreviated to just its first letter ✨. If you give no units at all, bytes are assumed (rude, but okay). The first column should be an integer representing the number of bytes to check.

Normal vibe: an alert fires when the values come back greater than or equal to the critical or warning value. But she's flexible 😌 β€” if you pass <purple>--reverse</purple>, the alert triggers when the returned value is lower than or equal to the critical or warning value instead. Flip it, reverse it, slay.

Example 1: Warn if any relation over 100 pages is named "rad", and put the number of pages inside the performance data section.

check_postgres_custom_query --valtype=string -w "rad" --query=
  "SELECT relname AS result, relpages AS pages FROM pg_class WHERE relpages > 100"

Example 2: Give a critical if the "foobar" function returns a number over 5MB:

check_postgres_custom_query --critical='5MB'--valtype=size --query="SELECT foobar() AS result"

Example 2: (yes bestie there are two Example 2s in the source, not me, I don't make the rules πŸ’…) Warn if the function "snazzo" returns less than 42:

check_postgres_custom_query --critical=42 --query="SELECT snazzo() AS result" --reverse
If you come up with a useful custom_query, consider sending in a patch to this program to make it into a standard action that other people can use. Be the main character who upstreams 🫢

This action does not support MRTG or simple output yet. We're manifesting it though πŸ•―οΈ


πŸ—„οΈ database_size

(symlink: check_postgres_database_size) Checks the size of all databases and complains when they are too big. There is no need to run this command more than once per database cluster, okay? It's per-cluster energy ✨ Databases can be filtered with the <purple>--include</purple> and <purple>--exclude</purple> options β€” see the "BASIC FILTERING" section for more details. They can also be filtered by the owner of the database with the <purple>--includeuser</purple> and <purple>--excludeuser</purple> options β€” see the "USER NAME FILTERING" section for more details.

The warning and critical options can be specified as bytes, kilobytes, megabytes, gigabytes, terabytes, or exabytes. Each may be abbreviated to the first letter as well 🌸. If no unit is given, the units are assumed to be bytes. There are no defaults for this action: the warning and the critical must be specified. The warning value cannot be greater than the critical value (that's not a vibe check anyone passes 🚩). The output returns all databases sorted by size largest first, showing both raw bytes and a "pretty" version of the size.

Example 1: Warn if any database on host flagg is over 1 TB in size, and critical if over 1.1 TB.

check_postgres_database_size --host=flagg --warning='1 TB' --critical='1.1 t'

Example 2: Give a critical if the database template1 on port 5432 is over 10 MB.

check_postgres_database_size --port=5432 --include=template1 --warning='10MB' --critical='10MB'

Example 3: Give a warning if any database on host 'tardis' owned by the user 'tom' is over 5 GB

check_postgres_database_size --host=tardis --includeuser=tom --warning='5 GB' --critical='10 GB'

For MRTG output, returns the size in bytes of the largest database on the first line, and the name of the database on the fourth line πŸ“Š


πŸ“ˆ dbstats

(symlink: check_postgres_dbstats) Reports information from the pg_stat_database view, and outputs it in a Cacti-friendly manner. No other output is supported, because the output is informational and does not lend itself to alerts like the ones used with Nagios. If no options are given, all databases are returned, one per line. You can include a specific database by use of the <purple>--include</purple> option, or you can use the <purple>--dbname</purple> option ✨

Eleven items are returned on each line, in the format name:value, separated by a single space. Iconic format honestly. The items are:

  • backends β€” the number of currently running backends for this database.
  • commits β€” the total number of commits for this database since it was created or reset.
  • rollbacks β€” the total number of rollbacks for this database since it was created or reset.
  • read β€” the total number of disk blocks read.
  • hit β€” the total number of buffer hits.
  • ret β€” the total number of rows returned.
  • fetch β€” the total number of rows fetched.
  • ins β€” the total number of rows inserted.
  • upd β€” the total number of rows updated.
  • del β€” the total number of rows deleted.
  • dbname β€” the name of the database.
Heads up bestie: the ret, fetch, ins, upd, and del items will always be 0 if Postgres is version 8.2 or lower, because those stats were simply not available in those versions 😭

If the dbname argument is given, seven additional items are returned:

  • idxscan β€” total number of user index scans.
  • idxtupread β€” total number of user index entries returned.
  • idxtupfetch β€” total number of rows fetched by simple user index scans.
  • idxblksread β€” total number of disk blocks read for all user indexes.
  • idxblkshit β€” total number of buffer hits for all user indexes.
  • seqscan β€” total number of sequential scans against all user tables.
  • seqtupread β€” total number of tuples returned from all user tables.

Example 1: Grab the stats for a database named "products" on host "willow":

check_postgres_dbstats --dbhost willow --dbname products

The output returned will be like this (all on one line, not wrapped):

backends:82 commits:58374408 rollbacks:1651 read:268435543 hit:2920381758 idxscan:310931294 idxtupread:2777040927
idxtupfetch:1840241349 idxblksread:62860110 idxblkshit:1107812216 seqscan:5085305 seqtupread:5370500520
ret:0 fetch:0 ins:0 upd:0 del:0 dbname:willow

🚫 disabled_triggers

(symlink: check_postgres_disabled_triggers) Checks on the number of disabled triggers inside the database. The <purple>--warning</purple> and <purple>--critical</purple> options are the number of such triggers found, and both default to "1", because in normal usage having disabled triggers is a dangerous event 🚨 If the database being checked is 8.3 or higher, the check is for the number of triggers that are in a 'disabled' status (as opposed to being 'always' or 'replica'). The output will show the name of the table and the name of the trigger for each disabled trigger.

Example 1: Make sure that there are no disabled triggers

check_postgres_disabled_triggers

For MRTG output, returns the number of disabled triggers on the first line.


πŸ’Ύ disk_space

(symlink: check_postgres_disk_space) Checks on the available physical disk space used by Postgres. This action requires that you have the executable /bin/df available to report on disk sizes 😀, and it also needs to be run as a superuser (either connecting directly or switching via <purple>--role</purple>), so it can examine the data_directory setting inside of Postgres. The <purple>--warning</purple> and <purple>--critical</purple> options are given in either sizes or percentages or both. If using sizes, the standard unit types are allowed: bytes, kilobytes, gigabytes, megabytes, gigabytes, terabytes, or exabytes. Each may be abbreviated to the first letter only; no units at all indicates 'bytes'. The default values are '90%' and '95%' ✨

This command checks the following things to determine all of the different physical disks being used by Postgres:

  • data_directory β€” the disk that the main data directory is on.
  • log directory β€” the disk that the log files are on.
  • WAL file directory β€” the disk that the write-ahead logs are on (e.g. symlinked pg_xlog or pg_wal).
  • tablespaces β€” each tablespace that is on a separate disk.

The output shows the total size used and available on each disk, as well as the percentage, ordered by highest to lowest percentage used. Each item above maps to a file system: these can be included or excluded. See the "BASIC FILTERING" section for more details.

Example 1: Make sure that no file system is over 90% for the database on port 5432.

check_postgres_disk_space --port=5432 --warning='90%' --critical='90%'

Example 2: Check that all file systems starting with /dev/sda are smaller than 10 GB and 11 GB (warning and critical)

check_postgres_disk_space --port=5432 --warning='10 GB' --critical='11 GB' --include="~^/dev/sda"

Example 4: (no, there's no Example 3 in the source, and no, I will not be explaining that πŸ’€) Make sure that no file system is both over 50% and has over 15 GB

check_postgres_disk_space --critical='50% and 15 GB'

Example 5: Issue a warning if any file system is either over 70% full or has more than 1T

check_postgres_disk_space --warning='1T or 75'

For MRTG output, returns the size in bytes of the file system on the first line, and the name of the file system on the fourth line.


🧚 fsm_pages

(symlink: check_postgres_fsm_pages) Checks how close a cluster is to the Postgres max_fsm_pages setting. This action will only work for databases of 8.2 or higher, and it requires the contrib module pg_freespacemap be installed πŸ‘‘. The <purple>--warning</purple> and <purple>--critical</purple> options should be expressed as percentages. The number of used pages in the free-space-map is determined by looking in the pg_freespacemap_relations view, and running a formula based on the formula used for outputting free-space-map pageslots in the vacuum verbose command. The default values are 85% for the warning and 95% for the critical.

Example 1: Give a warning when our cluster has used up 76% of the free-space pageslots, with pg_freespacemap installed in database robert

check_postgres_fsm_pages --dbname=robert --warning="76%"

While you need to pass in the name of the database where pg_freespacemap is installed, you only need to run this check once per cluster πŸ¦‹. Also, checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not run this check with short intervals, bestie. Short intervals are not the move here πŸ™ˆ

For MRTG output, returns the percent of free-space-map on the first line, and the number of pages currently used on the second line.


πŸŽ€ fsm_relations

(symlink: check_postgres_fsm_relations) Checks how close a cluster is to the Postgres max_fsm_relations setting. This action will only work for databases of 8.2 or higher, and it requires the contrib module pg_freespacemap be installed ✨. The <purple>--warning</purple> and <purple>--critical</purple> options should be expressed as percentages. The number of used relations in the free-space-map is determined by looking in the pg_freespacemap_relations view. The default values are 85% for the warning and 95% for the critical.

Example 1: Give a warning when our cluster has used up 80% of the free-space relations, with pg_freespacemap installed in database dylan

check_postgres_fsm_relations --dbname=dylan --warning="75%"

While you need to pass in the name of the database where pg_freespacemap is installed, you only need to run this check once per cluster 🌸. Also, checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not run this check with short intervals. Same warning as her sister action above, and it still stands πŸ’…

For MRTG output, returns the percent of free-space-map on the first line, the number of relations currently used on the second line.

hitratio 🌸

ok so hitratio (symlink: check_postgres_hitratio) checks the hit ratio across, like, all the databases and gets loud when they're too low. and bestie, there is literally no need to run this more than once per database cluster β€” it's giving "one and done" energy πŸ’…

you can filter databases with --include and --exclude (peep the "BASIC FILTERING" section for the deets), and you can also filter by who owns the database using --includeuser and --excludeuser β€” see "USER NAME FILTERING" for more.

the --warning and --critical options get specified as percentages. and ngl there are no defaults for this action β€” you must specify the warning and the critical. also the warning value cannot be greater than the critical value (the math would simply not math πŸ™ˆ). the output returns all databases sorted by hitratio, smallest first, so the worst one is right up top where you can see it.

Example: warn if any database on host flagg is less than 90% in hitratio, and critical if less then 80%.

check_postgres_hitratio --host=flagg --warning='90%' --critical='80%'

For MRTG output, it returns the percentage of the database with the smallest hitratio on the first line, and the name of the database on the fourth line. πŸŽ€


hot_standby_delay πŸ¦‹

hot_standby_delay (symlink: check_hot_standby_delay) checks the streaming replication lag by computing the delta between the current xlog position of a master server and the replay location of a slave connected to it. the slave server must be in hot_standby (e.g. read only) mode, which is why the minimum version to use this action is Postgres 9.0 β€” no cap.

the --warning and --critical options are the delta between the xlog locations. and since these values are byte offsets in the WAL, they should match the expected transaction volume of your application β€” otherwise you get false positives or negatives and you'll be sad 😭

so here's the vibe: the first --dbname, --host, and --port, etc. options are considered the master; the second belongs to the slave.

byte values should be based on the volume of transactions needed to have the streaming replication disconnect from the master because of too much lag, determined by the Postgres configuration variable wal_keep_segments. for units of time, valid units are seconds, minutes, hours, or days β€” each may be written singular or abbreviated to just the first letter. when specifying both, in the form bytes and time, both conditions must be true for the threshold to be met. both. like a package deal 🫢

you must provide info on how to reach the databases by providing a comma separated list to the --dbhost and --dbport parameters, such as --dbport=5432,5543. if not given, the action fails. so don't forget, bestie.

Example 1: Warn a database with a local replica on port 5433 is behind on any xlog replay at all

check_hot_standby_delay --dbport=5432,5433 --warning='1'

Example 2: Give a critical if the last transaction replica1 receives is more than 10 minutes ago

check_hot_standby_delay --dbhost=master,replica1 --critical='10 min'

Example 3: Allow replica1 to be 1 WAL segment behind, if the master is momentarily seeing more activity than the streaming replication connection can handle, or 10 minutes behind, if the master is seeing very little activity and not processing any transactions, but not both, which would indicate a lasting problem with the replication connection.

check_hot_standby_delay --dbhost=master,replica1 --warning='1048576 and 2 min' --critical='16777216 and 10 min'

relation_size Β· index_size Β· table_size Β· indexes_size Β· total_relation_size πŸ‘‘

(symlinks: check_postgres_relation_size, check_postgres_index_size, check_postgres_table_size, check_postgres_indexes_size, and check_postgres_total_relation_size) β€” yes that's five symlinks, they're a whole friend group πŸ’œ

the actions relation_size and index_size check for a relation (table, index, materialized view), respectively an index that has grown too big, using the pg_relation_size() function.

the action table_size checks tables and materialized views using pg_table_size(), i.e. including relation forks and TOAST table.

the action indexes_size checks tables and materialized views for the size of the attached indexes using pg_indexes_size().

the action total_relation_size checks relations using pg_total_relation_size(), i.e. including relation forks, indexes and TOAST table.

relations can be filtered with the --include and --exclude options β€” see "BASIC FILTERING". relations can also be filtered by the user that owns them, by using --includeuser and --excludeuser β€” see "USER NAME FILTERING".

the values for --warning and --critical are file sizes, and may have units of bytes, kilobytes, megabytes, gigabytes, terabytes, or exabytes. each can be abbreviated to the first letter. if no units are given, bytes are assumed. there are no default values: both the warning and the critical option must be given. the return text shows the size of the largest relation found.

if --showperf is enabled, all of the relations with their sizes will be given. to prevent that (because that's a lot of output, respectfully πŸ’€), it's recommended you set the --perflimit option, which will cause the query to do a ORDER BY size DESC LIMIT (perflimit).

Example 1: Give a critical if any table is larger than 600MB on host burrick.

check_postgres_table_size --critical='600 MB' --warning='600 MB' --host=burrick

Example 2: Warn if the table products is over 4 GB in size, and give a critical at 4.5 GB.

check_postgres_table_size --host=burrick --warning='4 GB' --critical='4.5 GB' --include=products

Example 3: Warn if any index not owned by postgres goes over 500 MB.

check_postgres_index_size --port=5432 --excludeuser=postgres -w 500MB -c 600MB

For MRTG output, it returns the size in bytes of the largest relation, and the name of the database and relation as the fourth line. ✨


last_analyze · last_vacuum · last_autoanalyze · last_autovacuum 🧹

(symlinks: check_postgres_last_analyze, check_postgres_last_vacuum, check_postgres_last_autoanalyze, and check_postgres_last_autovacuum)

this one checks how long it's been since vacuum (or analyze) was last run on each table in one or more databases. using these actions requires that the target database is version 8.3 or greater, or that the version is 8.2 and the configuration variable stats_row_level has been enabled. tables can be filtered with --include and --exclude β€” see "BASIC FILTERING". tables can also be filtered by their owner by use of --includeuser and --excludeuser β€” see "USER NAME FILTERING".

the units for --warning and --critical are specified as times. valid units are seconds, minutes, hours, and days; all can be abbreviated to the first letter. if no units are given, seconds are assumed. the default values are 1 day and 2 days. ⭐

heads up bestie: there are cases in which this field does not get automatically populated. if certain tables are giving you problems, make sure that they have dead rows to vacuum, or just exclude them from the test. do not come for the check, it's doing its best.

the schema named information_schema is excluded from this test, as the only tables it contains are small and do not change.

also note: the non-auto versions will also check on the auto versions as well. in other words, using last_vacuum will report on the last vacuum, whether it was a normal vacuum, or one run by the autovacuum daemon. so it's giving overachiever, in a good way πŸ’…

Example 1: Warn if any table has not been vacuumed in 3 days, and give a critical at a week, for host wormwood

check_postgres_last_vacuum --host=wormwood --warning='3d' --critical='7d'

Example 2: Same as above, but skip tables belonging to the users 'eve' or 'mallory'

check_postgres_last_vacuum --host=wormwood --warning='3d' --critical='7d' --excludeuser=eve,mallory

For MRTG output, it returns (on the first line) the LEAST amount of time in seconds since a table was last vacuumed or analyzed. the fourth line returns the name of the database and name of the table.


listener πŸ“‘

listener (symlink: check_postgres_listener) confirms that someone is listening for one or more specific strings (using the LISTEN/NOTIFY system), by looking at the pg_listener table. only one of warning or critical is needed. the format is a simple string representing the LISTEN target, or a tilde character followed by a string for a regular expression check.

🚨 real talk: this check will not work on versions of Postgres 9.0 or higher. periodt.

Example 1: Give a warning if nobody is listening for the string bucardo_mcp_ping on ports 5555 and 5556

check_postgres_listener --port=5555,5556 --warning=bucardo_mcp_ping

Example 2: Give a critical if there are no active LISTEN requests matching 'grimm' on database oskar

check_postgres_listener --db oskar --critical=~grimm

For MRTG output, it returns a 1 or a 0 on the first, indicating success or failure. the name of the notice must be provided via the --mrtg option. πŸŽ€


locks πŸ”’

locks (symlink: check_postgres_locks) checks the total number of locks on one or more databases. again, no need to run this more than once per database cluster β€” one run, all the tea. databases can be filtered with --include and --exclude β€” see "BASIC FILTERING".

the --warning and --critical options can be specified as simple numbers, which represent the total number of locks, or they can be broken down by type of lock. valid lock names are total, waiting, or the name of a lock type used by Postgres. these names are case-insensitive and do not need the lock part on the end β€” so exclusive will match 'ExclusiveLock', iykyk. the format is name=number, with different items separated by colons or semicolons (or any other symbol, we're not the format police πŸ’…).

Example 1: Warn if the number of locks is 100 or more, and critical if 200 or more, on host garrett

check_postgres_locks --host=garrett --warning=100 --critical=200

Example 2: On the host artemus, warn if 200 or more locks exist, and give a critical if over 250 total locks exist, or if over 20 exclusive locks exist, or if over 5 connections are waiting for a lock.

check_postgres_locks --host=artemus --warning=200 --critical="total=250:waiting=5:exclusive=20"

For MRTG output, it returns the number of locks on the first line, and the name of the database on the fourth line. πŸ”₯

πŸ’… logfile

(β€œsymlink: check_postgres_logfile”) Okay so bestie, this one makes sure your logfile is actually where it's supposed to be and that stuff is genuinely getting logged to it. How? It issues a command that throws an error on each database it's checking, then makes sure that message actually shows up in the logs. Iconic detective work. πŸ•΅οΈ

It scans the various log_* settings inside of Postgres to figure out where the logs should be. And if you're using syslog, it does a rough (but not foolproof) scan of /etc/syslog.conf β€” ngl, "rough but not foolproof" is doing some heavy lifting there, so don't @ me if it gets confused. πŸ™ˆ

Alternatively, you can just hand it the name of the logfile yourself with the --logfile option. This is especially useful if the logs have a custom rotation scheme driven by an external program. The --logfile option supports the following escape characters: "%Y %m %d %H", which represent the current year, month, date, and hour respectively. ✨

An error is always reported as critical unless the warning option has been passed in as a non-zero value. Other than that specific usage, the --warning and --critical options should not be used. Like, at all. Periodt.

πŸ’€ Heads up: those two options have exactly one job here (flipping critical β†’ warning), so please don't go inventing thresholds with them.

Example 1: On port 5432, ensure the logfile is being written to the file /home/greg/pg8.2.log

check_postgres_logfile --port=5432 --logfile=/home/greg/pg8.2.log

Example 2: Same as above, but raise a warning, not a critical

check_postgres_logfile --port=5432 --logfile=/home/greg/pg8.2.log -w 1

For MRTG output, returns a 1 or 0 on the first line, indicating success or failure. In case of a failure, the fourth line will provide more detail on the failure encountered. πŸŽ€


🌈 new_version_bc

(β€œsymlink: check_postgres_new_version_bc”) Checks if a newer version of the Bucardo program is available. The current version is obtained by running bucardo_ctl --version. If a major upgrade is available, a warning is returned. If a revision upgrade is available, a critical is returned. (Bucardo is a master to slave, and master to master replication system for Postgres: see <https://bucardo.org/> for more information). See also the information on the --get_method option.


πŸ¦‹ new_version_box

(β€œsymlink: check_postgres_new_version_box”) Checks if a newer version of the boxinfo program is available. The current version is obtained by running boxinfo.pl --version. If a major upgrade is available, a warning is returned. If a revision upgrade is available, a critical is returned. (boxinfo is a program for grabbing important information from a server and putting it into a HTML format: see <https://bucardo.org/Boxinfo/> for more information). See also the information on the --get_method option.


πŸŽ€ new_version_cp

(β€œsymlink: check_postgres_new_version_cp”) Checks if a newer version of this program (check_postgres.pl) is available, by grabbing the version from a small text file on the main page of the home page for the project. Returns a warning if the returned version does not match the one you are running. Recommended interval to check is once a day. See also the information on the --get_method option. πŸ‘‘


⭐ new_version_pg

(β€œsymlink: check_postgres_new_version_pg”) Checks if a newer revision of Postgres exists for each database connected to. Note that this only checks for revision, e.g. going from 8.3.6 to 8.3.7. Revisions are always 100% binary compatible and involve no dump and restore to upgrade. Revisions are made to address bugs, so upgrading as soon as possible is always recommended. Returns a warning if you do not have the latest revision. It is recommended this check is run at least once a day. See also the information on the --get_method option. πŸ”₯


🌸 new_version_tnm

(β€œsymlink: check_postgres_new_version_tnm”) Checks if a newer version of the tail_n_mail program is available. The current version is obtained by running tail_n_mail --version. If a major upgrade is available, a warning is returned. If a revision upgrade is available, a critical is returned. (tail_n_mail is a log monitoring tool that can send mail when interesting events appear in your Postgres logs. See: <https://bucardo.org/tail_n_mail/> for more information). See also the information on the --get_method option. πŸ’œ


🫢 the pgb_pool_* girlies

  • pgb_pool_cl_active
  • pgb_pool_cl_waiting
  • pgb_pool_sv_active
  • pgb_pool_sv_idle
  • pgb_pool_sv_used
  • pgb_pool_sv_tested
  • pgb_pool_sv_login
  • pgb_pool_maxwait

(symlinks: check_postgres_pgb_pool_cl_active, check_postgres_pgb_pool_cl_waiting, check_postgres_pgb_pool_sv_active, check_postgres_pgb_pool_sv_idle, check_postgres_pgb_pool_sv_used, check_postgres_pgb_pool_sv_tested, check_postgres_pgb_pool_sv_login, and check_postgres_pgb_pool_maxwait)

Okay so this whole squad examines pgbouncer's pool statistics. Each pool has a set of β€œclient” connections, referring to connections from external clients, and β€œserver” connections, referring to connections to PostgreSQL itself. The related check_postgres actions are prefixed by cl_ and sv_, respectively. Cute, right? πŸ’…

  • Active client connections are those connections currently linked with an active server connection.
  • Client connections may also be β€œwaiting”, meaning they have not yet been allocated a server connection.
  • Server connections are:
    • β€œactive” β€” linked to a client
    • β€œidle” β€” standing by for a client connection to link with
    • β€œused” β€” just unlinked from a client, and not yet returned to the idle pool
    • β€œtested” β€” currently being tested
    • β€œlogin” β€” in the process of logging in

The maxwait value shows how long in seconds the oldest waiting client connection has been waiting. ⏳


🧚 pgbouncer_backends

(β€œsymlink: check_postgres_pgbouncer_backends”) Checks the current number of connections for one or more databases through pgbouncer, and optionally compares it to the maximum allowed, which is determined by the pgbouncer configuration variable max_client_conn.

The --warning and --critical options can take one of three forms:

  1. A simple number can be given, which represents the number of connections at which the alert will be given. This choice does not use the max_connections setting.
  2. The percentage of available connections can be given.
  3. A negative number can be given which represents the number of connections left until max_connections is reached.

The default values for --warning and --critical are '90%' and '95%'. You can also filter the databases by use of the --include and --exclude options. See the β€œBASIC FILTERING” section for more details.

To view only non-idle processes, you can use the --noidle argument. Note that the user you are running as (either connecting directly or switching via --role) must be a superuser for this to work properly. πŸ‘€

Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 150.

check_postgres_pgbouncer_backends --host=quirm --warning=120 --critical=150 -p 6432 -u pgbouncer

Example 2: Give a critical when we reach 75% of our max_connections setting on hosts lancre or lancre2.

check_postgres_pgbouncer_backends --warning='75%' --critical='75%' --host=lancre,lancre2 -p 6432 -u pgbouncer

Example 3: Give a warning when there are only 10 more connection slots left on host plasmid, and a critical when we have only 5 left.

check_postgres_pgbouncer_backends --warning=-10 --critical=-5 --host=plasmid -p 6432 -u pgbouncer

For MRTG output, the number of connections is reported on the first line, and the fourth line gives the name of the database, plus the current max_client_conn. If more than one database has been queried, the one with the highest number of connections is output. πŸ“Š


πŸ“ pgbouncer_checksum

(β€œsymlink: check_postgres_pgbouncer_checksum”) Checks that all the pgBouncer settings are the same as last time you checked. This is done by generating a checksum of a sorted list of setting names and their values. Note that you shouldn't specify the database name β€” it will automatically default to pgbouncer. Either the --warning or the --critical option should be given, but not both. The value of each one is the checksum, a 32-character hexadecimal value. You can run with the special --critical=0 option to find out an existing checksum. πŸ•΅οΈβ€β™€οΈ

This action requires the Digest::MD5 module.

Example 1: Find the initial checksum for pgbouncer configuration on port 6432 using the default user (usually postgres)

check_postgres_pgbouncer_checksum --port=6432 --critical=0

Example 2: Make sure no settings have changed and warn if so, using the checksum from above.

check_postgres_pgbouncer_checksum --port=6432 --warning=cd2f3b5e129dc2b4f5c0f6d8d2e64231

For MRTG output, returns a 1 or 0 indicating success of failure of the checksum to match. A checksum must be provided as the --mrtg argument. The fourth line always gives the current checksum. ✨


πŸ’€ pgbouncer_maxwait

(β€œsymlink: check_postgres_pgbouncer_maxwait”) Checks how long the first (oldest) client in the queue has been waiting, in seconds. If this starts increasing, then the current pool of servers does not handle requests quick enough. Reason may be either overloaded server or just too small of a pool_size setting in pbouncer config file. 😭

Databases can be filtered by use of the --include and --exclude options. See the β€œBASIC FILTERING” section for more details.

The values or the --warning and --critical options are units of time, and must be provided (no default). Valid units are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. If no units are given, the units are assumed to be seconds.

This action requires Postgres 8.3 or better.

Example 1: Give a critical if any transaction has been open for more than 10 minutes:

check_postgres_pgbouncer_maxwait -p 6432 -u pgbouncer --critical='10 minutes'

For MRTG output, returns the maximum time in seconds a transaction has been open on the first line. The fourth line gives the name of the database. πŸŽ€


🌟 pgagent_jobs

(β€œsymlink: check_postgres_pgagent_jobs”) Checks that all the pgAgent jobs that have executed in the preceding interval of time have succeeded. This is done by checking for any steps that have a non-zero result. fr fr, that's the whole vibe check. βœ…

Either --warning or --critical, or both, may be specified as times, and jobs will be checked for failures withing the specified periods of time before the current time. (Yes, that typo is copy-pasted straight from the original β€” we keep it πŸ’…) Valid units are seconds, minutes, hours, and days; all can be abbreviated to the first letter. If no units are given, 'seconds' are assumed.

Example 1: Give a critical when any jobs executed in the last day have failed.

check_postgres_pgagent_jobs --critical=1d

Example 2: Give a warning when any jobs executed in the last week have failed.

check_postgres_pgagent_jobs --warning=7d

Example 3: Give a critical for jobs that have failed in the last 2 hours and a warning for jobs that have failed in the last 4 hours:

check_postgres_pgagent_jobs --critical=2h --warning=4h

πŸŽ€ prepared_txns πŸŽ€

(also answers to: check_postgres_prepared_txns β€” it's a symlink bestie, they're the same icon)

Okay so this one peeks at any prepared transactions that already exist and checks their age. Real talk though: most people will NOT use prepared transactions, periodt. They're part of two-part commit and they're genuinely complicated to maintain. And no, do not confuse them with prepared STATEMENTS β€” that's what everyone actually means when they hear "prepare", iykyk. Different thing entirely, don't mix them up πŸ’€

The default warning value is 1 second β€” literally one second, because detecting any use of prepared transactions is the whole point (it's probably a mistake on most systems, ngl). Warning and critical are both the number of seconds a prepared transaction has been open before an alert fires.

Example 1: warn the moment any prepared transaction exists at all:

check_postgres_prepared_txns -w 0

Example 2: critical if any prepared transaction has been open longer than 10 seconds, but let the database 'shrike' have up to 360 seconds:

check_postgres_prepared_txns --critical=10 --exclude=shrike
check_postgres_prepared_txns --critical=360 --include=shrike

For MRTG output, the first line is the number of seconds the oldest transaction has been open, and the final line tells you which database it came from πŸ¦‹


🧚 query_runtime 🧚

(symlink squad: check_postgres_query_runtime)

This one measures how long a specific query takes to run by executing an EXPLAIN ANALYZE against it. The --warning and --critical options are the maximum amount of time the query should take. Valid units are seconds, minutes, and hours β€” any of them can be abbreviated to the first letter. If you give no units at all, 'seconds' are assumed. Both the warning and the critical option must be given (no half-efforts here, bestie 🫢).

The name of the view or function to be run goes in the --queryname option. It must be a single word (or schema.word), with optional parens at the end.

Example 1: critical if the function named "speedtest" fails to run in 10 seconds or less:

check_postgres_query_runtime --queryname='speedtest()' --critical=10 --warning=10

For MRTG output, the first line reports the time in seconds for the query to complete. The fourth line lists the database πŸ‘‘


πŸ’… query_time πŸ’…

(symlink: check_postgres_query_time)

Checks the length of running queries across one or more databases. And listen β€” there's literally no need to run this more than once on the same database cluster, so don't be extra. Note that this already excludes queries that are "idle in transaction" (we see you, lazy queries, and we're not counting you πŸ™ˆ).

Databases can be filtered with the --include and --exclude options β€” see the "BASIC FILTERING" section for the full tea. You can also filter on the user running the query using --includeuser and --excludeuser; the "USER NAME FILTERING" section has the details.

The values for --warning and --critical are amounts of time, and at least one must be provided (no defaults, sorry!). Valid units are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. No units given? It's seconds, always seconds.

This action requires Postgres 8.1 or better. Old Postgres girlies, this one's not for you 😭

Example 1: warn if any query has been running longer than 3 minutes, critical if longer than 5 minutes:

check_postgres_query_time --port=5432 --warning='3 minutes' --critical='5 minutes'

Example 2: using the default values (2 and 5 minutes), check every database except the ones starting with 'template':

check_postgres_query_time --port=5432 --exclude=~^template

Example 3: warn if user 'don' has a query running over 20 seconds:

check_postgres_query_time --port=5432 --includeuser=don --warning=20s

For MRTG output, the first line returns the length in seconds of the longest running query. The fourth line gives the name of the database 🌸


🌈 replicate_row 🌈

(symlink: check_postgres_replicate_row)

Checks that master-slave replication is actually working, to one or more slaves. Main character energy: this action does the work and the slaves better keep up ✨

The first --dbname, --host, and --port, etc. options are considered the master; every subsequent use of them is a slave. The values of the --warning and --critical options are units of time, and at least one must be provided (no defaults, bestie). Valid units are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. If no units are given, the units are assumed to be seconds.

Here's how it works: this check updates a single row on the master, then measures how long it takes to be applied to the slaves. To pull that off you need to pick a table that's being replicated, then find a row that can be changed and isn't going to be changed by any other process. A specific column of that row gets changed from one value to another. All of that gets fed to the "repinfo" option and should contain the following, separated by commas: table name, primary key, key id, column, first value, second value.

Example 1: Slony is replicating a table named 'orders' from host 'alpha' to host 'beta', in the database 'sales'. The primary key of the table is named id, and we're going to test the row with an id of 3 (which is historical and never changed). There's a column named 'salesrep' that we're going to toggle from a value of 'slon' to 'nols' to check on the replication. We want a warning if the replication does not happen within 10 seconds.

check_postgres_replicate_row --host=alpha --dbname=sales --host=beta
--dbname=sales --warning=10 --repinfo=orders,id,3,salesrep,slon,nols

Example 2: Bucardo is replicating a table named 'receipt' from host 'green' to hosts 'red', 'blue', and 'yellow'. The database for both sides is 'public'. The slave databases are running on port 5455. The primary key is named 'receipt_id', the row we want to use has a value of 9, and the column we want to change for the test is called 'zone'. We'll toggle between 'north' and 'south' for the value of this column, and throw a critical if the change is not on all three slaves within 5 seconds.

check_postgres_replicate_row --host=green --port=5455 --host=red,blue,yellow
 --critical=5 --repinfo=receipt,receipt_id,9,zone,north,south

For MRTG output, the first line returns the time in seconds the replication takes to finish. The maximum time is set to 4 minutes 30 seconds β€” if no replication has taken place in that long a time, an error is thrown πŸ’€


πŸ¦‹ replication_slots πŸ¦‹

(symlink: check_postgres_replication_slots)

Checks the quantity of WAL retained for any replication slots in the target database cluster. This one's super handy for monitoring environments where all WAL archiving and replication is happening over replication slots. Obsessed, honestly πŸŽ€

Warning and critical are the total bytes retained for the slot. E.g:

check_postgres_replication_slots --port=5432 --host=yellow -warning=32M -critical=64M

Specific named slots can be monitored using --include/--exclude πŸ‘‘


⭐ same_schema ⭐

(symlink: check_postgres_same_schema)

Verifies that two or more databases are identical as far as their schema goes (but not the data inside, bestie β€” schema only). Unlike most other actions, this one has no warning or critical criteria at all. The databases are either in sync, or they're not. That's it, that's the vibe check. If they're different, you get a detailed list of the differences.

You may want to exclude or filter out certain differences. The way to do that is to add strings to the --filter option. To exclude a type of object, use "noname", where 'name' is the type of object β€” for example, "noschema". To exclude objects of a certain type by a regular expression against their name, use "noname=regex". The examples below make it click, promise 🫢

The types of objects that can be filtered include:

  • user
  • schema
  • table
  • view
  • index
  • sequence
  • constraint
  • trigger
  • function

The filter option "noposition" prevents verification of the position of columns within a table.

The filter option "nofuncbody" prevents comparison of the bodies of all functions.

The filter option "noperm" prevents comparison of object permissions.

To provide the second database, just append the differences to the first one by calling the appropriate connection argument. For example, to compare databases on hosts alpha and bravo, use --dbhost=alpha,bravo. Also see the examples below, they're iconic.

If only a single host is given, it's assumed we're doing a "time-based" report. The first time this is run, a snapshot of all the items in the database is saved to a local file. When you run it again, that snapshot is read in and becomes "database #2", and gets compared to the current database.

To replace the old stored file with the new version, use the --replace argument.

If you need to write the stored file to a specific directory, use the --audit-file-dir argument.

To avoid false positives on value based checks caused by replication lag on asynchronous replicas, use the --assume-async option.

To enable snapshots at various points in time, you can use the --suffix argument to make the filenames unique to each run. See the examples below πŸ’œ

Example 1: verify that two databases on hosts star and line are the same:

check_postgres_same_schema --dbhost=star,line

Example 2: same as before, but exclude any triggers with "slony" in their name:

check_postgres_same_schema --dbhost=star,line --filter="notrigger=slony"

Example 3: same as before, but also exclude all indexes:

check_postgres_same_schema --dbhost=star,line --filter="notrigger=slony noindexes"

Example 4: check differences for the database "battlestar" on different ports:

check_postgres_same_schema --dbname=battlestar --dbport=5432,5544

Example 5: create a daily and weekly snapshot file:

check_postgres_same_schema --dbname=cylon --suffix=daily
check_postgres_same_schema --dbname=cylon --suffix=weekly

Example 6: run a historical comparison, then replace the file:

check_postgres_same_schema --dbname=cylon --suffix=daily --replace

Example 7: verify that two databases on hosts star and line are the same, excluding value data (i.e. sequence last_val):

check_postgres_same_schema --dbhost=star,line --assume-async

πŸ’– sequence πŸ’–

(symlink: check_postgres_sequence)

Checks how much room is left on all the sequences in the database. This is measured as the percent of total possible values that have been used for each sequence. The --warning and --critical options should be expressed as percentages, and the defaults are 85% for the warning and 95% for the critical πŸ“

You may use --include and --exclude to control which sequences get checked. Note that this check does account for unusual minvalue and increment by values β€” it's not just vibes, it's math. By default it does not care whether the sequence is set to cycle or not, and by passing --skipcycled, sequences set to cycle are reported with 0% usage.

The output for Nagios gives the name of the sequence, the percentage used, and the number of 'calls' left β€” which tells you how many more times nextval can be called on that sequence before it runs into the maximum value πŸ”₯

For MRTG output, line one is the highest percentage across all sequences. Line four names every sequence that's at that percentage, separated by a "|" (pipe) when more than one sequence hits that percentage. Slay, data delivered.

Example 1: Give a warning if any sequences are approaching 95% full.

check_postgres_sequence --dbport=5432 --warning=95%

Example 2: Check that the sequence named orders_id_seq is not more than half full.

check_postgres_sequence --dbport=5432 --critical=50% --include=orders_id_seq

πŸ’– settings_checksum πŸ’–

("symlink: check_postgres_settings_checksum") This one checks that all the Postgres settings are the same as the last time you checked. Obsessed with consistency, honestly. It does this by generating a checksum of a sorted list of setting names and their values.

Heads up: different users in the same database may have different checksums, because of ALTER USER usage, and because superusers see more settings than ordinary users. Not a bug, just privilege reality.

Either the --warning or the --critical option should be given, but not both. The value of each one is the checksum, a 32-character hexadecimal value. You can run with the special "--critical=0" option to find out an existing checksum.

This action requires the Digest::MD5 module. Module check: mandatory, bestie.

Example 1: Find the initial checksum for the database on port 5555 using the default user (usually postgres).

check_postgres_settings_checksum --port=5555 --critical=0

Example 2: Make sure no settings have changed and warn if so, using the checksum from above.

check_postgres_settings_checksum --port=5555 --warning=cd2f3b5e129dc2b4f5c0f6d8d2e64231

For MRTG output, it returns a 1 or 0 showing whether the checksum matched or failed. A checksum must be provided as the "--mrtg" argument. The fourth line always gives the current checksum. Receipts, always.


πŸ¦‹ slony_status πŸ¦‹

("symlink: check_postgres_slony_status") This checks the status of a Slony cluster by looking at the results of Slony's sl_status view. It comes back as the number of seconds of "lag time". The --warning and --critical options should be expressed as times. The default values are 60 seconds for the warning and 300 seconds for the critical.

The optional argument --schema indicates the schema that Slony is installed under. If it is not given, the schema will be determined automatically each time this check is run. Automatic detective work, iconic.

Example 1: Give a warning if any Slony is lagged by more than 20 seconds.

check_postgres_slony_status --warning 20

Example 2: Give a critical if Slony, installed under the schema "_slony", is over 10 minutes lagged.

check_postgres_slony_status --schema=_slony --critical=600

🌈 timesync 🌈

("symlink: check_postgres_timesync") Compares the local system time with the time reported by one or more databases. The --warning and --critical options represent the number of seconds between the two systems before an alert is given. If neither is specified, the default values are used, which are '2' and '5'. The warning value cannot be greater than the critical value. Due to the non-exact nature of this test, values of '0' or '1' are not recommended. Like, don't set yourself up, bestie.

The string returned shows the time difference as well as the time on each side written out.

Example 1: Check that databases on hosts ankh, morpork, and klatch are no more than 3 seconds off from the local time:

check_postgres_timesync --host=ankh,morpork,klatch --critical=3

For MRTG output, the first line returns the number of seconds difference between the local time and the database time. The fourth line returns the name of the database. Clock check complete.


πŸŽ€ txn_idle πŸŽ€

("symlink: check_postgres_txn_idle") Checks the number and duration of "idle in transaction" queries on one or more databases. There is no need to run this more than once on the same database cluster. Databases can be filtered by using the --include and --exclude options. See the "BASIC FILTERING" section below for more details.

The --warning and --critical options are given as units of time, signed integers, or integers for units of time, and at least one must be provided (there are no defaults). Valid units are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. If no units are given and the numbers are unsigned, the units are assumed to be seconds.

This action requires Postgres 8.3 or better.

As of PostgreSQL 10, you can just GRANT pg_read_all_stats to an unprivileged user account. In all earlier versions, superuser privileges are required to see the queries of all users in the system; UNKNOWN is returned if queries cannot be checked. To only include queries by the connecting user, use --includeuser. Permissions lore, iykyk.

Example 1: Give a warning if any connection has been idle in transaction for more than 15 seconds:

check_postgres_txn_idle --port=5432 --warning='15 seconds'

Example 2: Give a warning if there are 50 or more transactions:

check_postgres_txn_idle --port=5432 --warning='+50'

Example 3: Give a critical if 5 or more connections have been idle in transaction for more than 10 seconds:

check_postgres_txn_idle --port=5432 --critical='5 for 10 seconds'

For MRTG output, it returns the time in seconds the longest idle transaction has been running. The fourth line returns the name of the database and other information about the longest transaction. Longest-idle main character energy.


🫢 txn_time 🫢

("symlink: check_postgres_txn_time") Checks the length of open transactions on one or more databases. There is no need to run this command more than once per database cluster. Databases can be filtered by use of the --include and --exclude options. See the "BASIC FILTERING" section for more details. The owner of the transaction can also be filtered, by use of the --includeuser and --excludeuser options. See the "USER NAME FILTERING" section for more details.

The values of the --warning and --critical options are units of time, and at least one must be provided (no default). Valid units are 'seconds', 'minutes', 'hours', or 'days'. Each may be written singular or abbreviated to just the first letter. If no units are given, the units are assumed to be seconds.

This action requires Postgres 8.3 or better.

Example 1: Give a critical if any transaction has been open for more than 10 minutes:

check_postgres_txn_time --port=5432 --critical='10 minutes'

Example 1: Warn if user 'warehouse' has a transaction open over 30 seconds.

check_postgres_txn_time --port-5432 --warning=30s --includeuser=warehouse

For MRTG output, it returns the maximum time in seconds a transaction has been open on the first line. The fourth line gives the name of the database. Transaction timer says what it says.


πŸ’œ txn_wraparound πŸ’œ

("symlink: check_postgres_txn_wraparound") Checks how close to transaction wraparound one or more databases are getting. The --warning and --critical options indicate the number of transactions done, and must be a positive integer. If either option is not given, the default values of 1.3 and 1.4 billion are used. There is no need to run this command more than once per database cluster. For a more detailed discussion of what this number represents and what to do about it, please visit the page https://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND.

The warning and critical values can have underscores in the number for legibility, as Perl does. Underscores for readability? We love a thoughtful icon.

Example 1: Check the default values for the localhost database:

check_postgres_txn_wraparound --host=localhost

Example 2: Check port 6000 and give a critical when 1.7 billion transactions are hit:

check_postgres_txn_wraparound --port=6000 --critical=1_700_000_000

For MRTG output, it returns the highest number of transactions for all databases on line one, while line 4 indicates which database it is.


⭐ version ⭐

("symlink: check_postgres_version") Checks that the required version of Postgres is running. The --warning and --critical options (only one is required) must be of the format X.Y or X.Y.Z where X is the major version number, Y is the minor version number, and Z is the revision.

Example 1: Give a warning if the database on port 5678 is not version 8.4.10:

check_postgres_version --port=5678 -w=8.4.10

Example 2: Give a warning if any databases on hosts valley,grain,sunshine is not 8.3:

check_postgres_version -H valley,grain,sunshine --critical=8.3

For MRTG output, it reports a 1 or a 0 indicating success or failure on the first line. The fourth line indicates the current version. The version must be provided via the "--mrtg" option. Version check, no cap.


🧚 wal_files 🧚

("symlink: check_postgres_wal_files") Checks how many WAL files exist in the pg_xlog directory (PostgreSQL 10 and later pg_wal), which is found off of your data_directory, sometimes as a symlink to another physical disk for performance reasons. If the --lsfunc option is not used, then this action must be run as a superuser, in order to access the contents of the pg_xlog directory. The minimum version to use this action is Postgres 8.1. The --warning and --critical options are simply the number of files in the pg_xlog directory. What number to set this to will vary, but a general guideline is to put a number slightly higher than what is normally there, to catch problems early. Early warning system, slay.

Normally, WAL files are closed and then re-used, but a long-running open transaction, or a faulty archive_command script, may cause Postgres to create too many files. Ultimately, this will cause the disk they are on to run out of space, at which point Postgres will shut down.

That's the dramatic part. Too many WAL files can fill the disk, and then Postgres goes down. Keep an eye on it.

To avoid connecting as a database superuser, a wrapper function around pg_ls_dir() should be defined as a superuser with SECURITY DEFINER, and the --lsfunc option used. This example function, if defined by a superuser, will allow the script to connect as a normal user nagios with --lsfunc=ls_xlog_dir:

BEGIN;
CREATE FUNCTION ls_xlog_dir()
    RETURNS SETOF TEXT
    AS $$ SELECT pg_ls_dir('pg_xlog') $$
    LANGUAGE SQL
    SECURITY DEFINER;
REVOKE ALL ON FUNCTION ls_xlog_dir() FROM PUBLIC;
GRANT EXECUTE ON FUNCTION ls_xlog_dir() to nagios;
COMMIT;

Example 1: Check that the number of ready WAL files is 10 or less on host "pluto", using a wrapper function "ls_xlog_dir" to avoid the need for superuser permissions:

check_postgres_archive_ready --host=pluto --critical=10 --lsfunc=ls_xlog_dir

For MRTG output, it reports the number of WAL files on line 1.


This action requires no other arguments, and does not connect to any databases, but simply creates symlinks in the current directory for each action, in the form check_postgres_<action_name>. If the file already exists, it will not be overwritten. If the action is rebuild_symlinks_force, then symlinks will be overwritten. The option --symlinks is a shorter way of saying --action=rebuild_symlinks. Symlink admin, no database required.

🌸 BASIC FILTERING 🌸

okay so bestie, this is where it gets fun β€” you can tell check_postgres exactly what to look at and what to skip. The options --include and --exclude team up to limit which things get checked, and what gets filtered depends on the action you're running. Let me break it down πŸ’…

  • πŸ—„οΈ database name can be filtered when you're using these actions: backends, database_size, locks, query_time, txn_idle, and txn_time
  • πŸ“¦ relation name can be filtered with these actions: bloat, index_size, table_size, relation_size, last_vacuum, last_autovacuum, last_analyze, and last_autoanalyze
  • βš™οΈ setting name can be filtered when you're using the settings_checksum action
  • πŸ’Ύ file system name can be filtered when you're using the disk_space action

Here's the tea on how include/exclude actually behave, because the order matters, no cap:

If you only hand it an include option, then ONLY the entries that match get checked β€” periodt. But if you give it both exclude and include, the exclusion happens first, and the inclusion happens after β€” that's so things that got excluded can be reinstated πŸ’–. Both --include and --exclude can be given multiple times, and/or as comma-separated lists. A leading tilde will match the following word as a regular expression. 🧚

To match a schema, end the search term with a single period. Leading tildes work for schemas too, bestie ✨

⚠️ Be careful when using filtering: an inclusion rule on the backends, for example, may report no problems not only because the matching database had no backends, but because you misspelled the name of the database! 😭 Like, don't do that to yourself.

Examples, because we love a demo πŸ‘‘

Only checks items named pg_class:

--include=pg_class

Only checks items containing the letters 'pg_':

--include=~pg_

Only check items beginning with 'pg_':

--include=~^pg_

Exclude the item named 'test':

--exclude=test

Exclude all items containing the letters 'test:

--exclude=~test

Exclude all items in the schema 'pg_catalog':

--exclude='pg_catalog.'

Exclude all items in the 'pg_temp_nnn' per-session temporary schemas:

--exclude=~^pg_temp_.

Exclude all items containing the letters 'ace', but allow the item 'faceoff':

--exclude=~ace --include=faceoff

Exclude all items which start with the letters 'pg_', which contain the letters 'slon', or which are named 'sql_settings' or 'green'. Specifically check items with the letters 'prod' in their names, and always check the item named 'pg_relname':

--exclude=~^pg_,~slon,sql_settings --exclude=green --include=~prod,pg_relname

πŸ¦‹ USER NAME FILTERING πŸ¦‹

So the options --includeuser and --excludeuser let you peek at only those database objects owned by (or not owned by) one or more users β€” on some actions. And here's the rule: an --includeuser option always trumps an --excludeuser option. πŸ‘‘ You can give each option more than once for multiple users, or you can give a comma-separated list. The actions that currently use these options are:

  • database_size
  • last_analyze
  • last_autoanalyze
  • last_vacuum
  • last_autovacuum
  • query_time
  • relation_size
  • txn_time

Examples, bestie 🌸

Only check items owned by the user named greg:

--includeuser=greg

Only check items owned by either watson or crick:

--includeuser=watson,crick

Only check items owned by crick,franklin, watson, or wilkins:

--includeuser=watson --includeuser=franklin --includeuser=crick,wilkins

Check all items except for those belonging to the user scott:

--excludeuser=scott

✨ TEST MODE ✨

To help in setting things up, this program can be run in a "test mode" by specifying the --test option. Think of it as the vibe check before the actual party πŸŽ€ It performs some basic tests to make sure the databases can be contacted, and that certain per-action prerequisites are met β€” like whether the user is a superuser, if the version of Postgres is new enough, and if stats_row_level is enabled. Lowkey essential, ngl.


πŸŽ€ FILES πŸŽ€

In addition to command-line configurations, you can put any options inside of a file. So cozy 🫢 Here's the search order:

  1. The file .check_postgresrc in the current directory will be used if found.
  2. If not found, then the file ~/.check_postgresrc will be used.
  3. Finally, the file /etc/check_postgresrc will be used if available.

The format of the file is option = value, one per line. Any line starting with a # will be skipped. Any values loaded from a check_postgresrc file will be overwritten by command-line options. And if you want none of that energy, all check_postgresrc files can be ignored by supplying a --no-checkpostgresrc argument. πŸ’…


⭐ ENVIRONMENT VARIABLES ⭐

  • 🏠 The environment variable $ENV{HOME} is used to look for a .check_postgresrc file.
  • 🐘 The environment variable $ENV{PGBINDIR} is used to look for PostgreSQL binaries.

πŸ’œ TIPS AND TRICKS πŸ’œ

Since this program uses the psql program, make sure it is accessible to the user running the script. If run as a cronjob, this often means modifying the PATH environment variable. Don't forget β€” it's giving "where did my binary go" energy otherwise πŸ™ˆ

If you are using Nagios in embedded Perl mode, use the --action argument instead of symlinks, so that the plugin only gets compiled one time. Efficiency slay πŸ’…


🌈 DEPENDENCIES 🌈

Access to a working version of psql, and the following very standard Perl modules:

  • Cwd
  • Getopt::Long
  • File::Basename
  • File::Temp
  • Time::HiRes (if $opt{showtime} is set to true, which is the default)

The settings_checksum action requires the Digest::MD5 module.

The checkpoint action requires the Date::Parse module.

Some actions require access to external programs. If psql is not explicitly specified, the command which is used to find it. The program /bin/df is needed by the disk_space action.


🧚 DEVELOPMENT 🧚

Development happens using the git system. You can clone the latest version by doing:

https://github.com/bucardo/check_postgres
git clone https://github.com/bucardo/check_postgres.git

πŸ’Œ MAILING LIST πŸ’Œ

Three mailing lists are available. For discussions about the program, bug reports, feature requests, and commit notices, send email to check_postgres@bucardo.org

<https://mail.endcrypt.com/mailman/listinfo/check_postgres>

A low-volume list for announcement of new versions and important notices is the 'check_postgres-announce' list:

<https://mail.endcrypt.com/mailman/listinfo/check_postgres-announce>

Source code changes (via git-commit) are sent to the 'check_postgres-commit' list:

<https://mail.endcrypt.com/mailman/listinfo/check_postgres-commit>


πŸ‘‘ HISTORY πŸ‘‘

Items not specifically attributed are by GSM (Greg Sabino Mullane).

🌟 Version 2.26.0 Released April 3, 2023

  • Add new action "pgbouncer_maxwait" (Ruslan Kabalin) [Github pull #59]
  • For the bloat check, add option to populate all known databases, as well as includsion and exclusion regexes. (Giles Westwood) [Github pull #86]
  • Add Partman premake check (Jens Wilke) [Github pull #196]
  • Add --role flag to explicitly set the role of the user after connecting (David Christensen)
  • Fix check_replication_slots on recently promoted servers (Christoph Berg)
  • Allow the check_disk_space action to handle relative log_directory paths (jacksonfoz) [Github pull #174]
  • Fix MINPAGES and MINIPAGES in the "check_bloat" action (Christoph Moench-Tegeder) [Github pull #82]
  • Replace 'which' with 'command -v' (Christoph Berg)
  • Fix check_replication_slots on recently promoted servers (Christoph Berg)
  • Fix undefined variable warning (Michael van Bracht) [Github pull #158]
  • In the tests, force log_destination to stderr (Christoph Moench-Tegeder) [Github pull #185]
  • Add to docs how to exclude all items in the 'pg_temp_nnn' per-session temporary schemas (Michael Banck)
  • Various fixes for the CI system (Emre Hasegeli) [Github pull #181]
  • Various improvements to the tests (Christoph Berg, Emre Hasegeli)

🌟 Version 2.25.0 Released February 3, 2020

  • Allow same_schema objects to be included or excluded with --object and --skipobject (Greg Sabino Mullane)
  • Fix to allow mixing service names and other connection parameters for same_schema (Greg Sabino Mullane)

🌟 Version 2.24.0 Released May 30, 2018

  • Support new_version_pg for PG10 (Michael Pirogov)
  • Option to skip CYCLE sequences in action sequence (Christoph Moench-Tegeder)
  • Output per-database perfdata for pgbouncer pool checks (George Hansper)
  • German message translations (Holger Jacobs)
  • Consider only client backends in query_time and friends (David Christensen)

🌟 Version 2.23.0 Released October 31, 2017

  • Support PostgreSQL 10. (David Christensen, Christoph Berg)
  • Change table_size to use pg_table_size() on 9.0+, i.e. include the TOAST table size in the numbers reported. Add new actions indexes_size and total_relation_size, using the respective pg_indexes_size() and pg_total_relation_size() functions. All size checks will now also check materialized views where applicable. (Christoph Berg)
  • Connection errors are now always critical, not unknown. (Christoph Berg)
  • New action replication_slots checking if logical or physical replication slots have accumulated too much data (Glyn Astill)
  • Multiple same_schema improvements (Glyn Astill)
  • Add Spanish message translations (Luis Vazquez)
  • Allow a wrapper function to run wal_files and archive_ready actions as non-superuser (Joshua Elsasser)
  • Add some defensive casting to the bloat query (Greg Sabino Mullane)
  • Invoke psql with option -X (Peter Eisentraut)
  • Update postgresql.org URLs to use https. (Magnus Hagander)
  • check_txn_idle: Don't fail when query contains 'disabled' word (Marco Nenciarini)
  • check_txn_idle: Use state_change instead of query_start. (Sebastian Webber)
  • check_hot_standby_delay: Correct extra space in perfdata (Adrien Nayrat)
  • Remove \r from psql output as it can confuse some regexes (Greg Sabino Mullane)
  • Sort failed jobs in check_pgagent_jobs for stable output. (Christoph Berg)

🌟 Version 2.22.0 June 30, 2015

  • Add xact timestamp support to hot_standby_delay. Allow the hot_standby_delay check to accept xlog byte position or timestamp lag intervals as thresholds, or even both at the same time. (Josh Williams)
  • Query all sequences per DB in parallel for action=sequence. (Christoph Berg)
  • Fix bloat check to use correct SQL depending on the server version. (Adrian Vondendriesch)
  • Show actual long-running query in query_time output (Peter Eisentraut)
  • Add explicit ORDER BY to the slony_status check to get the most lagged server. (Jeff Frost)
  • Improved multi-slave support in replicate_row. (Andrew Yochum)
  • Change the way tables are quoted in replicate_row. (Glyn Astill)
  • Don't swallow space before the -c flag when reporting errors (Jeff Janes)
  • Fix and extend hot_standby_delay documentation (Michael Renner) β€” yes bestie, the docs got ✨glowed up✨ too
  • Declare POD encoding to be utf8. (Christoph Berg) β€” so the emoji-adjacent characters don't get cursed πŸ’€

Version 2.21.0 β€” September 24, 2013 πŸŽ€

  • Fix issue with SQL steps in check_pgagent_jobs for sql steps which perform deletes (Rob Emery via github pull) β€” deletes were out here breaking stuff, not anymore 🫢
  • Install man page in section 1. (Peter Eisentraut, bug 53, github issue 26) β€” that's literally the page you're reading rn, meta much? πŸ’…
  • Order lock types in check_locks output to make the ordering predictable; setting SKIP_NETWORK_TESTS will skip the new_version tests; other minor test suite fixes. (Christoph Berg) β€” predictable ordering is the vibe, chaos is cancelled 🌸
  • Fix same_schema check on 9.3 by ignoring relminmxid differences in pg_class (Christoph Berg) β€” 9.3 said "new column" and we said "not today" ✨

Version 2.20.1 β€” June 24, 2013 πŸ¦‹

  • Make connection check failures return CRITICAL not UNKNOWN (Dominic Hargreaves) β€” if it's broken it's broken broken, let's be honest with Nagios 😭
  • Fix --reverse option when using string comparisons in custom queries (Nathaniel Waisbrot)
  • Compute correct totalwastedbytes in the bloat query (Michael Renner) β€” the math was mathing wrong, now it's mathing right πŸ”₯
  • Do not use pg_stats "inherited" column in bloat query, if the database is 8.4 or older. (Greg Sabino Mullane, per bug 121) β€” old servers get the gentler treatment 🧚
  • Remove host reordering in hot_standby_delay check (Josh Williams, with help from Jacobo Blasco)
  • Better output for the "simple" flag (Greg Sabino Mullane)
  • Force same_schema to ignore the relallvisible column (Greg Sabino Mullane) β€” we simply do not perceive it πŸ‘‘πŸ™ˆ

Version 2.20.0 β€” March 13, 2013 ⭐

  • Add check for pgagent jobs (David E. Wheeler) β€” new action just dropped
  • Force STDOUT to use utf8 for proper output (Greg Sabino Mullane; reported by Emmanuel Lesouef)
  • Fixes for Postgres 9.2: new pg_stat_activity view, and use pg_tablespace_location (Josh Williams)
  • Allow for spaces in item lists when doing same_schema.
  • Allow txn_idle to work again for < 8.3 servers by switching to query_time.
  • Fix the check_bloat SQL to take inherited tables into account, and assume 2k for non-analyzed columns. (Geert Pante)
  • Cache sequence information to speed up same_schema runs. β€” we love a cache, we love a speedrun πŸ’¨
  • Fix --excludeuser in check_txn_idle (Mika Eloranta)
  • Fix user clause handling in check_txn_idle (Michael van Bracht)
  • Adjust docs to show colon as a better separator inside args for locks (Charles Sprickman) β€” colon > comma, iykyk
  • Fix undefined $SQL2 error in check_txn_idle [github issue 16] (Patric Bechtel)
  • Prevent "uninitialized value" warnings when showing the port (Henrik Ahlgren) β€” no more scary red text 🫢
  • Do not assume everyone has a HOME [github issue 23] β€” literally not everyone does, be respectful 🌈

Version 2.19.0 β€” January 17, 2012 πŸ’œ

  • Add the --assume-prod option (CΓ©dric Villemain)
  • Add the cluster_id check (CΓ©dric Villemain)
  • Improve settings_checksum and checkpoint tests (CΓ©dric Villemain)
  • Do not do an inner join to pg_user when checking database size (Greg Sabino Mullane; reported by Emmanuel Lesouef)
  • Use the full path when getting sequence information for same_schema. (Greg Sabino Mullane; reported by Cindy Wise)
  • Fix the formula for calculating xlog positions (Euler Taveira de Oliveira) β€” the formula was giving "made it up" energy πŸ’€
  • Better ordering of output for bloat check - make indexes as important as tables (Greg Sabino Mullane; reported by Jens Wilke) β€” index main character energy πŸ‘‘
  • Show the dbservice if it was used at top of same_schema output (Mike Blackwell)
  • Better installation paths (Greg Sabino Mullane, per bug 53)

Version 2.18.0 β€” October 2, 2011 πŸ”₯

  • Redo the same_schema action. Use new --filter argument for all filtering. Allow comparisons between any number of databases. Remove the dbname2, dbport2, etc. arguments. Allow comparison of the same db over time. β€” whole action got a glow-up, it's giving rebrand πŸ’…
  • Swap db1 and db2 if the slave is 1 for the hot standby check (David E. Wheeler)
  • Allow multiple --schema arguments for the slony_status action (GSM and Jehan-Guillaume de Rorthais)
  • Fix ORDER BY in the last vacuum/analyze action (Nicolas Thauvin)
  • Fix check_hot_standby_delay perfdata output (Nicolas Thauvin)
  • Look in the correct place for the .ready files with the archive_ready action (Nicolas Thauvin)
  • New action: commitratio (Guillaume Lelarge)
  • New action: hitratio (Guillaume Lelarge)
  • Make sure --action overrides the symlink naming trick. β€” the explicit flag wins, periodt ✨
  • Set defaults for archive_ready and wal_files (Thomas Guettler, GSM)
  • Better output for wal_files and archive_ready (GSM)
  • Fix warning when client_port set to empty string (bug #79)
  • Account for "empty row" in -x output (i.e. source of functions).
  • Fix some incorrectly named data fields (Andy Lester)
  • Expand the number of pgbouncer actions (Ruslan Kabalin)
  • Give detailed information and refactor txn_idle, txn_time, and query_time (Per request from bug #61) β€” they got the full makeover πŸŽ€
  • Set maxalign to 8 in the bloat check if box identified as '64-bit' (Michel Sijmons, bug #66)
  • Support non-standard version strings in the bloat check. (Michel Sijmons and Gurjeet Singh, bug #66)
  • Do not show excluded databases in some output (Ruslan Kabalin)
  • Allow "and", "or" inside arguments (David E. Wheeler)
  • Add the new_version_box action.
  • Fix psql version regex (Peter Eisentraut, bug #69)
  • Add the --assume-standby-mode option (Ruslan Kabalin)
  • Note that txn_idle and query_time require 8.3 (Thomas Guettler) β€” fr fr, check your version first
  • Standardize and clean up all perfdata output (bug #52) β€” consistency is the aesthetic 🌸
  • Exclude "idle in transaction" from the query_time check (bug #43)
  • Fix the perflimit for the bloat action (bug #50)
  • Clean up the custom_query action a bit.
  • Fix space in perfdata for hot_standby_delay action (Nicolas Thauvin)
  • Handle undef percents in check_fsm_relations (Andy Lester)
  • Fix typo in dbstats action (Stas Vitkovsky)
  • Fix MRTG for last vacuum and last_analyze actions.

Version 2.17.0 β€” no public release πŸ™ˆ

Yeah. Nothing. It's giving mystery. Moving on πŸ’…

Version 2.16.0 β€” January 20, 2011 🧚

  • Add new action 'hot_standby_delay' (Nicolas Thauvin)
  • Add cache-busting for the version-grabbing utilities.
  • Fix problem with going to next method for new_version_pg (Greg Sabino Mullane, reported by Hywel Mallett in bug #65)
  • Allow /usr/local/etc as an alternative location for the check_postgresrc file (Hywel Mallett)
  • Do not use tgisconstraint in same_schema if Postgres >= 9 (Guillaume Lelarge)

Version 2.15.4 β€” January 3, 2011 πŸ“

  • Fix warning when using symlinks (Greg Sabino Mullane, reported by Peter Eisentraut in bug #63)

Version 2.15.3 β€” December 30, 2010 πŸ’«

  • Show OK for no matching txn_idle entries. β€” nothing happening is still a result, bestie

Version 2.15.2 β€” December 28, 2010 πŸŽ€

  • Better formatting of sizes in the bloat action output.
  • Remove duplicate perfs in bloat action output.

Version 2.15.1 β€” December 27, 2010 πŸ”₯

  • Fix problem when examining items in pg_settings (Greg Sabino Mullane)
  • For connection test, return critical, not unknown, on FATAL errors (Greg Sabino Mullane, reported by Peter Eisentraut in bug #62)

Version 2.15.0 β€” November 8, 2010 πŸ‘‘

  • Add --quiet argument to suppress output on OK Nagios results
  • Add index comparison for same_schema (Norman Yamada and Greg Sabino Mullane)
  • Use $ENV{PGSERVICE} instead of "service=" to prevent problems (Guillaume Lelarge)
  • Add --man option to show the entire manual. (Andy Lester)
  • Redo the internal run_command() sub to use -x and hashes instead of regexes.
  • Fix error in custom logic (Andreas Mager)
  • Add the "pgbouncer_checksum" action (Guillaume Lelarge)
  • Fix regex to work on WIN32 for check_fsm_relations and check_fsm_pages (Luke Koops)
  • Don't apply a LIMIT when using --exclude on the bloat action (Marti Raudsepp)
  • Change the output of query_time to show pid,user,port, and address (Giles Westwood)
  • Fix to show database properly when using slony_status (Guillaume Lelarge)
  • Allow warning items for same_schema to be comma-separated (Guillaume Lelarge)
  • Constraint definitions across Postgres versions match better in same_schema.
  • Work against "EnterpriseDB" databases (Sivakumar Krishnamurthy and Greg Sabino Mullane)
  • Separate perfdata with spaces (Jehan-Guillaume (ioguix) de Rorthais)
  • Add new action "archive_ready" (Jehan-Guillaume (ioguix) de Rorthais)

Version 2.14.3 β€” (March 1, 2010) 🌈

  • Allow slony_status action to handle more than one slave.
  • Use commas to separate function args in same_schema output (Robert Treat)

Version 2.14.2 β€” (February 18, 2010) ⭐

  • Change autovac_freeze default warn/critical back to 90%/95% (Robert Treat) β€” we tried something, we came back, no shame 🫢
  • Put all items one-per-line for relation size actions if --verbose=1

Version 2.14.1 β€” (February 17, 2010) πŸ¦‹

  • Don't use $^T in logfile check, as script may be long-running
  • Change the error string for the logfile action for easier exclusion by programs like tail_n_mail

Version 2.14.0 β€” (February 11, 2010) πŸ’œ

  • Added the 'slony_status' action.
  • Changed the logfile sleep from 0.5 to 1, as 0.5 gets rounded to 0 on some boxes! β€” literally math betrayal, that's why 😭

Version 2.13.2 β€” (February 4, 2010) 🌸

  • Allow timeout option to be used for logtime 'sleep' time.

Version 2.13.2 β€” (February 4, 2010) 🌸

Yep. Same version number, same date, twice. Not a typo on my end bestie, we keep the receipts exactly as they are πŸ’€

  • Show offending database for query_time action.
  • Apply perflimit to main output for sequence action.
  • Add 'noowner' option to same_schema action.
  • Raise sleep timeout for logfile check to 15 seconds.

Version 2.13.1 β€” (February 2, 2010) πŸŽ€

  • Fix bug preventing column constraint differences from 2 > 1 for same_schema from being shown.
  • Allow aliases 'dbname1', 'dbhost1', 'dbport1',etc.
  • Added "nolanguage" as a filter for the same_schema option.
  • Don't track "generic" table constraints (e.. $1, $2) using same_schema

Version 2.13.0 β€” (January 29, 2010) ✨

  • Allow "nofunctions" as a filter for the same_schema option.
  • Added "noperm" as a filter for the same_schema option.
  • Ignore dropped columns when considered positions for same_schema (Guillaume Lelarge)

Version 2.12.1 β€” (December 3, 2009) πŸ“

  • Change autovac_freeze default warn/critical from 90%/95% to 105%/120% (Marti Raudsepp)

Version 2.12.0 β€” (December 3, 2009) πŸ”₯

  • Allow the temporary directory to be specified via the "tempdir" argument, for systems that need it (e.g. /tmp is not owned by root).
  • Fix so old versions of Postgres (< 8.0) use the correct default database (Giles Westwood)
  • For "same_schema" trigger mismatches, show the attached table.
  • Add the new_version_bc check for Bucardo version checking.
  • Add database name to perf output for last_vacuum|analyze (Guillaume Lelarge)
  • Fix for bloat action against old versions of Postgres without the 'block_size' param.

Version 2.11.1 (August 27, 2009)

  • Nagios output for the last_vacuum|analyze actions is actually proper now, no cap. (CΓ©dric Villemain)
  • Same glow-up for the locks action β€” proper Nagios output, finally. (CΓ©dric Villemain)
  • And the txn_wraparound action too, proper Nagios output era. (CΓ©dric Villemain)
  • Bestie, constraints with embedded newlines in same_schema were lowkey broken and now they're fixed.
  • You can use --exclude for all items when you're running same_schema now. Slay.

Version 2.11.0 (August 23, 2009)

  • The wal_files check got Nagios perf output added ✨ (CΓ©dric Villemain)
  • Support for .check_postgresrc dropped, per request from Albe Laurenz β€” very much requested.
  • The list of web fetch methods is now changeable with the --get_method option. iykyk.
  • Support for the --language argument, which overrides any ENV. Your ENV could never.
  • The --no-check_postgresrc flag exists now, icon.
  • check_postgresrc options get completely overridden by command-line options. Command line stays main character.
  • Fixed the incorrect warning > critical logic in replicate_rows (Glyn Astill) πŸ’€

Version 2.10.0 (August 3, 2009)

  • For same_schema, it now compares view definitions and compares languages. Comparison era.
  • The script is now a global executable via the Makefile.PL file. Go little script go.
  • Better output when comparing two databases 🫢
  • Proper Nagios output syntax for the autovac_freeze and backends checks (CΓ©dric Villemain)

Version 2.9.5 (July 24, 2009)

  • No LIMIT in check_bloat if --include is used. Per complaint from Jeff Frost, we listened.

Version 2.9.4 (July 21, 2009)

  • More French translations, merci beaucoup (Guillaume Lelarge) πŸŽ€

Version 2.9.3 (July 14, 2009)

  • Quote dbname in perf output for the backends check, bestie. (Davide Abrigo)
  • Added fetch as an alternative method for new_version checks, because it comes by default with FreeBSD. Convenient king. (Hywel Mallett)

Version 2.9.2 (July 12, 2009)

  • Dots and dashes are allowed in the database name for the backends check now (Davide Abrigo) β€” periods and dashes are, in fact, iconic.
  • The bloat check checks and displays the database for each match (CΓ©dric Villemain)
  • The backends check handles the too many connections FATAL error with a critical, rather than a generic error (Greg, idea by JΓΌrgen Schulz-BrΓΌssel)
  • perflimit is not allowed to interfere with exclusion rules in the vacuum and analyze tests anymore. (Greg, bug reported by Jeff Frost) πŸ’…

Version 2.9.1 (June 12, 2009)

  • Fix for multiple databases with the check_bloat action (Mark Kirkwood)
  • Fixes and improvements to the same_schema action (Jeff Boes)
  • Tests written for same_schema, plus other minor test fixes (Jeff Boes) πŸ’–

Version 2.9.0 (May 28, 2009)

  • Added the same_schema action, shoutout Greg. ✨

Version 2.8.1 (May 15, 2009)

  • Added timeout via statement_timeout in addition to perl alarm (Greg) β€” double the safety, double the vibe.

Version 2.8.0 (May 4, 2009)

  • Added internationalization support (Greg) 🌈
  • Added the 'disabled_triggers' check (Greg)
  • Added the 'prepared_txns' check (Greg)
  • Added the 'new_version_cp' and 'new_version_pg' checks (Greg)
  • French translations (Guillaume Lelarge)
  • The backends search now returns ok if there are no matches due to inclusion rules, per report by Guillaume Lelarge (Greg)
  • Added comprehensive unit tests (Greg, Jeff Boes, Selena Deckelmann) πŸ‘‘
  • fsm_pages and fsm_relations handle 8.4 servers smoothly now (Greg)
  • Fixed the missing 'upd' field in show_dbstats (Andras Fabian)
  • ENV{PGCONTROLDATA} and ENV{PGBINDIR} are allowed now (Greg)
  • Added various Perl module infrastructure (e.g. Makefile.PL) (Greg)
  • Fixed the incorrect regex in txn_wraparound (Greg)
  • For txn_wraparound: consistent ordering, and duplicates fixed in perf output (Andras Fabian)
  • Added in the missing exabyte regex check (Selena Deckelmann)
  • Stats are set to zero if we bail early due to USERWHERECLAUSE (Andras Fabian)
  • Added additional items to dbstats output (Andras Fabian)
  • Removed the --schema option from the fsm_ checks. (Greg Mullane and Robert Treat)
  • Handles the case when ENV{PGUSER} is set. (Andy Lester)
  • Many various fixes. (Jeff Boes)
  • Fixed --dbservice: check version and use ENV{PGSERVICE} for old versions (CΓ©dric Villemain)

Version 2.7.3 (February 10, 2009)

  • The sequence action now checks if the sequence is being used for a int4 column and reacts appropriately. (Michael Glaesemann)

Version 2.7.2 (February 9, 2009)

  • Fix to prevent multiple groupings if db arguments are given. πŸ™ˆ

Version 2.7.1 (February 6, 2009)

  • The -p argument for port works again. She's back.

Version 2.7.0 (February 4, 2009)

  • A connection argument is no longer required β€” it uses defaults and ENV variables when possible: PGHOST, PGPORT, PGUSER, PGDATABASE. πŸ’œ

Version 2.6.1 (February 4, 2009)

  • Date::Parse is only required to be loaded if you're using the checkpoint action.

Version 2.6.0 (January 26, 2009)

  • Added the 'checkpoint' action. πŸŽ€

Version 2.5.4 (January 7, 2009)

  • Better checking of $opt{dbservice} structure (CΓ©dric Villemain)
  • Fixed time display in timesync action output (Selena Deckelmann)
  • Fixed documentation typos (Josh Tolley)

Version 2.5.3 (December 17, 2008)

  • Minor fix to regex in verify_version (Lee Jensen)

Version 2.5.2 (December 16, 2008)

  • Minor documentation tweak.

Version 2.5.1 (December 11, 2008)

  • Added support for the --noidle flag to prevent the backends action from counting idle processes. Patch by Selena Deckelmann.
  • Fixed a small undefined warning when not using --dbservice.

Version 2.5.0 (December 4, 2008)

  • Added support for the pg_Service.conf file with the --dbservice option. πŸ¦‹

Version 2.4.3 (November 7, 2008)

  • Fixed options for the replicate_row action, per report from Jason Gordon.

Version 2.4.2 (November 6, 2008)

  • File::Temp::cleanup() calls are wrapped in eval, in case File::Temp is an older version. Patch by Chris Butler.

Version 2.4.1 (November 5, 2008)

  • Numbers are cast to numeric to support sequence ranges > bigint in the check_sequence action. Thanks to Scott Marlowe for reporting this. 😭

Version 2.4.0 (October 26, 2008)

  • Added Cacti support with the dbstats action.
  • Prettied up the time output for the last vacuum and analyze actions.
  • Shows the percentage of backends on the check_backends action. ✨

Version 2.3.10 (October 23, 2008)

  • Fixed a minor warning in the check_bloat action with multiple databases.
  • Warning is allowed to be greater than critical when using the --reverse option.
  • Support for the --perflimit option for the check_sequence action.

Version 2.3.9 (October 23, 2008)

  • Minor tweak to the way we store the default port.

Version 2.3.8 (October 21, 2008)

  • The default port can be changed easily now.
  • Simple output can be transformed by MB, GB, etc. πŸ’…

Version 2.3.7 (October 14, 2008)

  • Multiple databases allowed in the 'sequence' action. Reported by Christoph Zwerschke.

Version 2.3.6 (October 13, 2008)

  • Added the missing $schema to check_fsm_pages. (Robert Treat)

Version 2.3.5 (October 9, 2008)

  • Changed the option 'checktype' to 'valtype' to prevent collisions with -c[ritical]. No collisions allowed, periodt.
  • Better handling of errors.

Version 2.3.4 (October 9, 2008)

  • Explicit cleanups of the temp directory, per problems reported by sb@nnx.com. 🧚

Version 2.3.3 (October 8, 2008)

  • Accounts for cases where some rounding queries give -0 instead of 0. Thanks to Glyn Astill for helping to track this down. Not the negative zero 😭

Version 2.3.2 (October 8, 2008)

  • Always quote identifiers in the check_replicate_row action.

Version 2.3.1 (October 7, 2008)

  • Gives a better error if one of the databases cannot be reached.

Version 2.3.0 (October 4, 2008)

  • Added the "sequence" action, thanks to Gavin M. Roy for the idea. πŸ”₯
  • Fixed a minor problem with the autovac_freeze action when using MRTG output.
  • The output argument is allowed to be case-insensitive now.
  • Documentation fixes.

Version 2.2.4 (October 3, 2008)

  • Fixed some minor typos.

Version 2.2.3 (October 1, 2008)

  • Expanded the range of allowed names for the --repinfo argument (Glyn Astill)
  • Documentation tweaks.

Version 2.2.2 (September 30, 2008)

  • Fixes for minor output and scoping problems.

Version 2.2.1 (September 28, 2008)

  • Added MRTG output to fsm_pages and fsm_relations.
  • Error messages are forced to one-line for proper Nagios output. One line only, bestie.
  • Checks for invalid prereqs on a failed command. From conversations with Euler Taveira de Oliveira.
  • Tweaked the fsm_pages formula a little.

Version 2.2.0 (September 25, 2008)

  • Added the fsm_pages and fsm_relations actions. (Robert Treat) 🌸

Version 2.1.4 (September 22, 2008)

  • Fix for a race condition in the txn_time action.
  • Added the --debugoutput option.

Version 2.1.3 (September 22, 2008)

  • Alternate arguments allowed: "dbhost" for "host" and "dbport" for "port". Synonyms slay.
  • Outputs a zero as the default value for the second line of MRTG output.

Version 2.1.2 (July 28, 2008)

  • Fixed a sorting error in the "disk_space" action for non-Nagios output.
  • --simple is allowed as a shortcut for --output=simple. πŸ’–

Version 2.1.1 (July 22, 2008)

  • Databases with datallowconn false are not checked for the "autovac_freeze" action.

Version 2.1.0 (July 18, 2008)

  • Added the "autovac_freeze" action, thanks to Robert Treat for the idea and design.
  • Put an ORDER BY on the "txn_wraparound" action. Order matters, always.

Version 2.0.1 (July 16, 2008)

  • Optimizations to speed up the "bloat" action quite a bit. Zoom zoom.
  • Fixed the "version" action to not always output in mrtg mode.

Version 2.0.0 (July 15, 2008)

  • Added support for MRTG and "simple" output options. ✨
  • Many small improvements to nearly all actions.

Version 1.9.1 (June 24, 2008)

  • Fixed an error in the bloat SQL in 1.9.0
  • Percentage arguments are allowed to be over 99%
  • Percentages are allowed in the bloat --warning and --critical (thanks to Robert Treat for the idea) πŸ‘‘

Version 1.9.0 (June 22, 2008)

  • information_schema is not included in certain checks. (Jeff Frost)
  • --include and --exclude can use schemas by using a trailing period.

Version 1.8.5 (June 22, 2008)

  • Outputs the schema name before the table name where appropriate. Thanks to Jeff Frost. 🫢

Version 1.8.4 (June 19, 2008)

  • Better detection of problems in --replicate_row.

Version 1.8.3 (June 18, 2008)

  • Fixed the 'backends' action: there may be no rows in pg_stat_activity, so it runs a second query if needed to find the max_connections setting. Thanks to Jeff Frost for the bug report. πŸ’€

Version 1.8.2 (June 10, 2008)

  • Changes to allow working under Nagios' embedded Perl mode. (Ioannis Tambouras)

Version 1.8.1 (June 9, 2008)

  • The 'bloat' action is allowed to work on Postgres version 8.0.
  • Different commands can be run for each action depending on the server version.
  • Better warnings when running actions not available on older Postgres servers. πŸŽ€

Version 1.8.0 (June 3, 2008)

  • Added the --reverse option to the custom_query action.
  • Version 1.7.1 (June 2, 2008) β€” fixed the query_time action so it accounts for that cursed race condition where zero rows show up in pg_stat_activity. Shoutout to Dustin Black for the bug report 🫢
  • Version 1.7.0 (May 11, 2008) β€” added the --replicate_row action ✨
  • Version 1.6.1 (May 11, 2008) β€” added the --symlinks option, which is literally just a shortcut for --action=rebuild_symlinks
  • Version 1.6.0 (May 11, 2008) β€” added the custom_query action πŸ’…
  • Version 1.5.2 (May 2, 2008) β€” fixed a problem where the custom pgpass file was being created way too eagerly (chill bestie)
  • Version 1.5.1 (April 17, 2008) β€” added example Nagios configuration settings (ty Brian A. Seklecki πŸŽ€)
  • Version 1.5.0 (April 16, 2008) β€” added the --includeuser and --excludeuser options, plus documentation cleanup
  • Version 1.4.3 (April 16, 2008) β€” added the 'output' concept for future support of non-Nagios programs
  • Version 1.4.2 (April 8, 2008) β€” fixed the bug that was blocking the --dbpass argument from working (Robert Treat πŸ‘‘)
  • Version 1.4.1 (April 4, 2008) β€” minor documentation fixes
  • Version 1.4.0 (April 2, 2008) β€” made the 'wal_files' action use pg_ls_dir (idea by Robert Treat). Also, for last_vacuum and last_analyze, it now respects autovacuum effects and added separate autovacuum checks (ideas by Robert Treat)
  • Version 1.3.1 (April 2, 2008) β€” made txn_idle use query_start, not xact_start
  • Version 1.3.0 (March 23, 2008) β€” added the txn_idle and txn_time actions
  • Version 1.2.0 (February 21, 2008) β€” added the 'wal_files' action, which counts the number of WAL files in your pg_xlog directory. Fixed some typos in the docs. Explicitly allows -v as an argument. Allows for a null syslog_facility in the 'logfile' action
  • Version 1.1.2 (February 5, 2008) β€” fixed the error that was stopping --action=rebuild_symlinks from working
  • Version 1.1.1 (February 3, 2008) β€” switched vacuum and analyze date output to use 'DD', not 'D' (Glyn Astill)
  • Version 1.1.0 (December 16, 2008) β€” fixes, enhancements, and performance tracking. Added performance data tracking via --showperf and --perflimit. Lots of refactoring and cleanup of how actions handle arguments. Does basic checks to figure out the syslog file for the 'logfile' action. Allows for exact matching of beta versions with the 'version' action. Redid the default arguments to only populate when neither 'warning' nor 'critical' is provided. Allows just warning OR critical to be given for the 'timesync' action. Removed the redirect_stderr requirement from 'logfile' due to 8.3 changes. The 'last_vacuum' and 'last_analyze' actions are 8.2 only (Robert Treat)
  • Version 1.0.16 (December 7, 2007) β€” first public release, December 2007 πŸŽ‰

πŸ’€ BUGS AND LIMITATIONS πŸ’€

Okay so it's not perfect, and we're being honest about it:

  • The index bloat size optimization is rough. Like, rough rough. It's giving "first draft".
  • Some actions may not work on older versions of Postgres (before 8.0). Ancient history bestie, but fair warning.
  • Please report any problems to check_postgres@bucardo.org β€” fr fr, they want to hear it πŸ™ˆ

πŸ‘‘ AUTHOR πŸ‘‘

Greg Sabino Mullane <greg@turnstep.com>


🌈 NAGIOS EXAMPLES 🌈

Some example Nagios configuration settings using this script β€” steal these, they're iconic:

 define command {
     command_name    check_postgres_size
     command_line    $USER2$/check_postgres.pl -H $HOSTADDRESS$ -u pgsql -db postgres --action database_size -w $ARG1$ -c $ARG2$
 }

 define command {
     command_name    check_postgres_locks
     command_line    $USER2$/check_postgres.pl -H $HOSTADDRESS$ -u pgsql -db postgres --action locks -w $ARG1$ -c $ARG2$
 }

 define service {
     use                    generic-other
     host_name              dbhost.gtld
     service_description    dbhost PostgreSQL Service Database Usage Size
     check_command          check_postgres_size!256000000!512000000
 }

 define service {
     use                    generic-other
     host_name              dbhost.gtld
     service_description    dbhost PostgreSQL Service Database Locks
     check_command          check_postgres_locks!2!3
 }

Copyright 2007 - 2023 Greg Sabino Mullane <greg@turnstep.com>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

And now the part where everyone yells in caps (it's legally required, don't shoot the messenger):

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

And that's the whole page bestie!! πŸ’– You made it to the end β€” you're officially a check_postgres girlie now, no cap. Just so you know exactly which edition of this masterpiece you're holding: it's version 2.26.0, dated 2023-04-07, and yes it's still filed under CHECK_POSTGRES(1) like the legend it is. Go forth and monitor responsibly πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from