PostgreSQL Query
Run your own SELECT query on a PostgreSQL server and get alerted on its row count or execution time.
The PostgreSQL Query check runs your own SQL query on a PostgreSQL server and evaluates either the number of rows returned or the execution time. Use it, for example, to watch for failed jobs, stuck orders or slow queries. 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
hostline inpg_hba.confthat admits this role from the agent device's address. CONNECTon the database,USAGEon the schema andSELECTon the tables your query reads.
To create the monitoring role, its read rights and the pg_hba.conf entry, see Set up the database monitoring account.
Steps
- Go to Devices and open the device.
- Click the Checks tab → Add Check → PostgreSQL Query.
Settings
The check counts rows, not values. SELECT count(*) FROM jobs WHERE failed always returns exactly one row and is therefore always evaluated as 1, no matter how many jobs failed. Write the query so that it returns one row per problem, for example SELECT id FROM jobs WHERE failed.
Results
The check compares the chosen value (row count or execution time) with both thresholds. Thresholds also trigger on equality.
With the defaults (both thresholds 1, mode Row count), the check is therefore Critical as soon as the query returns at least one row, and OK otherwise. If the two thresholds are in the wrong order, the check swaps them before evaluation. Connection setup and query have a fixed 15-second timeout.
Metrics collected
- Number of rows returned
- Query execution time in milliseconds (excluding connection setup)
Notes
- The
READ ONLYtransaction is a safety net, not a replacement for a read-only role. Grant the monitoring roleSELECTonly. - The host is part of the check configuration. If you assign the check to many devices through a config package, each of them runs the same query against the same server. Assign it to a single device instead.
Was this helpful?
More in Databases & applications
Set up the database monitoring accountDATEVDFSR BacklogDHCP Scope UtilizationStill need help? Ask the team