Skip to content

Privileges and pg_stat_statements for PostgreSQL

Step 4 of the setup generates a script for your provider, version, connection and authentication. Run it on the database as an administrator (on RDS and Aurora, as the master user). It creates the role wt15_monitor. No secret is ever in it: the password is the placeholder <random 32+ chars>, which you replace, and WatchTower15 never generates or sees it.

Variant For What it adds
Peer A self-managed server, over the Unix socket The role with no password, and the pg_hba.conf and pg_ident.conf lines: see Peer authentication
Password Self-managed over TCP or the socket, RDS and Aurora SET password_encryption = 'scram-sha-256'; then the role with its placeholder password and CONNECTION LIMIT 3. Self-managed over TCP also prints the hostssl … scram-sha-256 line for your collectors’ subnet, never one server’s address
IAM RDS and Aurora The role with no password, and GRANT rds_iam last: see RDS IAM authentication

On RDS and Aurora the script also notes rds.force_ssl: on by default from PostgreSQL 15, and to be set to 1 in the parameter group before 15.

CREATE ROLE wt15_monitor LOGIN PASSWORD '<random 32+ chars>' CONNECTION LIMIT 3;
GRANT pg_monitor TO wt15_monitor; -- tier A: health and workload
ALTER ROLE wt15_monitor SET default_transaction_read_only = on;
ALTER ROLE wt15_monitor SET statement_timeout = '5s';
ALTER ROLE wt15_monitor SET lock_timeout = '1s';
ALTER ROLE wt15_monitor SET idle_in_transaction_session_timeout = '10s';
-- PostgreSQL 16 and later: GRANT pg_use_reserved_connections TO wt15_monitor;
-- PostgreSQL 17 and later: ALTER ROLE wt15_monitor SET transaction_timeout = '10s';
-- Tier B, only for databases where CONNECT was revoked from PUBLIC:
-- GRANT CONNECT ON DATABASE <name> TO wt15_monitor;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  • Tier A (pg_monitor): health, workload, replication, the WAL archiver and the transaction ages that the alarms read. It is all PostgreSQL monitoring needs today.
  • Tier B (CONNECT on the databases that revoked it from PUBLIC, and pg_stat_statements): not read yet; grant it now so you grant once.
  • The role connects read-only, with a five-second statement timeout, a one-second lock timeout and at most three connections. From 16 it may use PostgreSQL’s reserved connections, so monitoring still works when the server is out of ordinary ones.

A role holding more than monitoring needs — a superuser, CREATEROLE, BYPASSRLS, a database it owns, or a broad predefined role such as pg_read_all_data — is flagged Over-privileged on the database’s page. Monitoring needs only the script’s grants.

The script ends with CREATE EXTENSION IF NOT EXISTS pg_stat_statements. The extension is readable only when pg_stat_statements is also in shared_preload_libraries:

  • RDS and Aurora: it is in the default shared_preload_libraries, so only the CREATE EXTENSION is yours.
  • Self-managed: add pg_stat_statements to shared_preload_libraries. That takes a restart of the server. Without the preload the extension is created but unreadable.

Verify has one line for it, informational for now, in three states: pg_stat_statements created and readable; pg_stat_statements created but not preloaded: add it to shared_preload_libraries and restart; and pg_stat_statements not created: run the script’s CREATE EXTENSION line. Nothing else about PostgreSQL monitoring needs it yet.