Skip to main content
Databases & applications

PostgreSQL Health

Check the reachability, connect time, active sessions and database size of a PostgreSQL server.

The PostgreSQL Health check connects to a PostgreSQL server as an ordinary client and reports whether the connection works, how long connecting takes, how many sessions are currently active, and how large the connected database is. The check runs on the agent device you assign it to and connects from there over TCP to the host you enter. It runs on Windows, Linux and macOS (each in x64 and Arm64), every 5 minutes by default. The database server itself does not need to be an agent device; any agent device that can reach it over the network is enough.

Prerequisites

  • A login role and a host line in pg_hba.conf that admits this role from the agent device's address. Even with the host 127.0.0.1 the connection arrives over TCP, so local lines do not apply.
  • For a meaningful active session count, the role needs pg_monitor (or pg_read_all_stats). Without it, the role sees only its own session's state, and the check permanently reports one active session.

To create the monitoring role and the pg_hba.conf entry, see Set up the database monitoring account.

Steps

  1. Go to Devices and open the device.
  2. Click the Checks tab → Add Check → PostgreSQL Health.

Settings

FieldTypeRequiredDefaultDescription
HostTextYes—Hostname or IP address of the PostgreSQL server, as seen from the agent device
PortIntegerNo5432TCP port of the server. The check replaces values outside 1–65535 with 5432
DatabaseTextNopostgresDatabase the check connects to and whose size it reports. An empty field is treated as postgres
UsernameTextYes—Role the check signs in with. Use a read-only role
PasswordTextNo—Password of the role
SSL modeSelectNoPreferPrefer encrypts when the server offers it; Require insists on an encrypted connection; Disable connects unencrypted
Warning connect time (ms)IntegerNo1000Connection setup time at or above which a warning is reported
Error connect time (ms)IntegerNo3000Connection setup time at or above which a critical result is reported

The two connect-time fields sit under Connect-time thresholds in the check form.

Results

SituationResult
Connected, connect time below Warning connect time (ms)OK
Connect time at or above Warning connect time (ms)Warning
Connect time at or above Error connect time (ms)Critical
Sign-in rejected (Authentication failed)Critical
Server unreachable, server error or timeoutCritical
No host enteredWarning
Unexpected error in the checkFailure

Thresholds also trigger on equality. If Warning connect time (ms) is greater than Error connect time (ms), the check swaps the two values before evaluation. The active session count and database size are displayed only and never raise an alert. Connection setup and queries have a fixed 10-second timeout.

Metrics collected

  • Connected (yes/no)
  • Connect time in milliseconds
  • Active sessions: backends in pg_stat_activity with state = 'active', that is, only sessions currently running a statement
  • Size of the connected database in MB

Notes

  • The check opens a new connection on every run and closes it afterwards.
  • The host is part of the check configuration. If you assign the check to many devices through a config package, each of them connects to the same server. Assign it to a single device instead, ideally the database server itself.