Monitors

Database monitors

A database monitor signs in to your database over an encrypted connection, runs one read-only query and checks the first row. It finds what a port check cannot: a refused password, a query that fails, or a number that grows too high.

On this page

Before you start

  • The database must accept encrypted connections (TLS). Unencrypted connections are not supported.
  • Our checks must reach it from the internet, on its port. The form shows the addresses our checks come from: let them in through your database's firewall. See Let our checks through a firewall.
  • Make a user for the monitor that can only read what the query needs. The query runs read-only anyway, but a user that cannot write is safer.

For example, a user that may read one table, in PostgreSQL:

SQL
CREATE ROLE uptimezy_monitor LOGIN PASSWORD 'a-long-random-password';
GRANT CONNECT ON DATABASE shop TO uptimezy_monitor;
GRANT USAGE ON SCHEMA public TO uptimezy_monitor;
GRANT SELECT ON public.jobs TO uptimezy_monitor;

PostgreSQL must also let this user in over an encrypted connection from our addresses. That is a line in its pg_hba.conf, with one of the addresses the form shows:

pg_hba.conf
# TYPE   DATABASE  USER                      ADDRESS            METHOD
hostssl  shop      uptimezy_monitor   <address>/32       scram-sha-256

The same in MySQL or MariaDB:

SQL
CREATE USER 'uptimezy_monitor'@'%' IDENTIFIED BY 'a-long-random-password' REQUIRE SSL;
GRANT SELECT ON shop.jobs TO 'uptimezy_monitor'@'%';

Create a database monitor

  1. On Monitors, press New monitor. Under What to check, choose Database.
  2. Choose the Database type: PostgreSQL, or MySQL or MariaDB.
  3. Type the Host: a domain name or a public IP address. Type the Port only if it is not the usual one: left empty, it is 5432 for PostgreSQL and 3306 for MySQL and MariaDB.
  4. Type the Database, or leave it empty for the user's default. Type the User and its Password.
  5. Under Encryption, keep Encrypted, certificate checked, or choose Encrypted, certificate not checked for a self-signed certificate.
  6. Type the Query. At first it is SELECT 1, which only proves that signing in works.
  7. Choose the Check interval and the Timeout, add checks under Checks on the first row if you need them, and press Create monitor.

In alerts and lists, the monitor is named by its engine, host and port, such as postgres://db.example.com:5432, never by the user or the database.

Encryption and the password

  • The connection always uses TLS 1.2 or newer. With Encrypted, certificate checked, the certificate must be signed by a known authority and be for the host name you typed.
  • Encrypted, certificate not checked is still encrypted, but anyone could be at the other end. Choose it only for a self-signed certificate.
  • A server without TLS fails with Certificate or secure connection problem.
  • PostgreSQL signs in with SCRAM-SHA-256 or MD5. A server that asks for the password in clear text gets nothing, and the check fails with The database refused the user, the password or the database. For MySQL and MariaDB, clear-text passwords and the old password hashing are refused too.

The password is stored encrypted and never shown again. The monitor's page says Saved, encrypted. When you edit the monitor, leave the field empty to keep it.

Write the query

  • The query runs read-only. A query that writes fails with The query did not run and changes nothing.
  • It runs as one statement: SELECT 1; SELECT 2 fails.
  • It may span several lines, up to 2,000 characters.
  • The whole check, connecting included, has the monitor's Timeout. The database itself is told to stop the query at that moment, so nothing keeps running. A query stopped this way fails with No answer in time.
  • Only the first row is read, with up to 20 columns. Text values are cut after 500 characters.
  • What the query returns is checked and then forgotten: it is never stored.

Some examples:

SQL
-- Signing in works (the default)
SELECT 1

-- Jobs that failed in the last hour (PostgreSQL); check: failed is less than 1
SELECT count(*) AS failed FROM jobs WHERE failed_at > now() - interval '1 hour'

-- The same in MySQL or MariaDB
SELECT count(*) AS failed FROM shop.jobs WHERE failed_at > NOW() - INTERVAL 1 HOUR

-- Seconds behind on a PostgreSQL replica, 0 when it replayed all it received; check: lag_seconds is less than 60
SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE EXTRACT(EPOCH FROM now() - pg_last_xact_replay_timestamp()) END AS lag_seconds

The last one is for a PostgreSQL replica: it gives how many seconds it is behind, or 0 when it has replayed every change it received. On a primary server it gives null.

Check the first row

Without checks, the check passes when the query runs: The check passes when the query runs in time. With checks, each one reads one column of the first row by its name.

  1. Under Checks on the first row, press Add check.
  2. Type the Column, such as failed.
  3. Choose the Comparison and type the Value, such as is less than 10.
  • Type the column's name exactly as the query names it. Give it a name with AS, as in SELECT count(*) AS failed FROM jobs: without it, PostgreSQL calls the column count and MySQL calls it count(*).
  • Numbers are compared as numbers, so is less than 10 works. true and false stay those words, NULL is null, and a date is UTC text such as 2026-11-24T09:00:00Z.
  • The comparisons are the same as for API monitors, with up to 10 checks. The first one that fails is named in the alert.
  • When the query returns no row, only does not exist can pass.

Slowest allowed response (ms) works as for API monitors, but here the time covers the whole check: connecting, encryption, signing in and the query.

When a database monitor counts as down

Reason in the dashboardWhat happened
The database refused the user, the password or the databaseA wrong password, an unknown user or database, or a server that wants the password in clear text.
The query did not runThe query has a mistake, has two statements, writes, reads a table that does not exist, or the user may not read it.
No answer in timeThe check, the query included, did not end within the timeout.
Certificate or secure connection problemThe server has no TLS, or its certificate did not pass the check.
Connection refused or droppedThe server refused or dropped the connection. A firewall often causes this.
Address not found (DNS)The host name could not be looked up.
Address leads to a private networkThe host leads to an address in a private network.
A response check failedOne of your checks on the first row did not pass.
The response came too slowlyThe check was slower than your limit.

Database checks run from our main server only, so there are few addresses to let in. A failed check is checked again 30 seconds later, and the second failure in a row makes the monitor down and sends the alert. Other places do not confirm it.

More guides

All guides