Overview
OpenSRE uses PostgreSQL diagnostics to investigate database issues — checking server health, surfacing slow queries, monitoring replication status, and analyzing table statistics. All queries are read-only SELECTs.
Prerequisites
- PostgreSQL 10+ (12+ recommended for full
pg_stat_statements support)
- Network access from the OpenSRE environment to your PostgreSQL instance
- A read-only user with access to system views
Setup
Option 1: Interactive CLI
Provide your host, database, and credentials when prompted.
Option 2: Environment variables
Option 3: Persistent store
Credentials
Creating a read-only user
pg_monitor (PostgreSQL 10+) grants read access to monitoring views including pg_stat_activity, pg_stat_replication, and pg_stat_statements without superuser privileges.
Enabling slow query tracking
Add to postgresql.conf:
Restart PostgreSQL, then:
Quick local test with Docker
Verify:
Use a temporary integration-store path so saved integrations cannot override the demo environment variables:
The file does not need to exist. OpenSRE treats the missing temporary store as empty and resolves PostgreSQL from the exported variables above.
Now ask the agent about the slow query:
Ask: Does the app_db PostgreSQL instance have any slow queries?
Against this exact local instance the agent calls all 6 registered tools — slow
queries, server status, current queries, lock status, table stats, and replication
status — and correctly identifies the intentional SELECT pg_sleep($1) call
(~2016 ms average) as the only slow query, with every other health indicator normal.
Teardown:
Verify
Alias: postgres. Expected output:
Troubleshooting
Security
- Use a dedicated read-only user with
pg_monitor — avoid superuser credentials.
- Enable SSL (
POSTGRESQL_SSL_MODE=require) in production.
- Prefer
scram-sha-256 in pg_hba.conf.
- Store credentials in
.env or your secret manager — not in source control.
- Rotate credentials periodically.