pg_monitor#
What is pg_monitor?#
pg_monitor allows a role to view PostgreSQL performance, activity, and statistics β without modifying data.
Think of it as:
Read-only access to the database internals
What pg_monitor CAN do#
With pg_monitor, a role can:
- See activity
pg_stat_activity
Active queries
Long-running queries
Connection counts
Backend states (idle, active, waiting)
- See performance stats
pg_stat_database
pg_stat_user_tables
pg_stat_user_indexes
Buffer hits
I/O statistics
Index usage
- See locks & waits
pg_locks
Blocking queries
Deadlock diagnosis
- See configuration (read-only)
Some server settings via:
pg_settings
pg_stat_bgwriter
- β What pg_monitor CANNOT do
β Read table data
β Modify data
β Execute commands
β Kill backends
β Access filesystem
β Execute OS programs
It is observational only
Why PostgreSQL created pg_monitor#
- Before pg_monitor, DBAs had two bad choices:
Grant superuser β (too dangerous)
Grant nothing β (no visibility)
- pg_monitor solves this:
β Safe
β Auditable
β Least-privilege
β Perfect for dashboards & tooling
Internally, pg_monitor includes
- It automatically grants:
pg_read_all_settings
pg_read_all_stats
So you donβt need to grant those individually.
Example: Who should get pg_monitor?
- β Good candidates
Monitoring tools (Prometheus exporters)
Read-only DBA accounts
Performance dashboards (Grafana)
SRE / Ops teams
Support engineers
- β Bad candidates
Application users
Web apps
ETL users
Untrusted users
Example Queries
SELECT * FROM pg_stat_activity;
SELECT * FROM pg_stat_user_tables;
SELECT * FROM pg_locks;
All of these work with pg_monitor.
How to grant it#
GRANT pg_monitor TO monitoring_user;
β Safe
β Reversible
β No data exposure
Mental Model
Role |
Meaning |
|---|---|
pg_monitor |
π βI can see whatβs happeningβ |
pg_read_all_data |
π βI can read all dataβ |
pg_write_all_data |
βοΈ βI can change dataβ |
pg_execute_server_program |
π£ βI can run OS commandsβ |
- βοΈ Cloud & Production Notes
AWS RDS β pg_monitor is allowed
Azure PostgreSQL β allowed
GCP Cloud SQL β allowed
Kubernetes / self-hosted β recommended
Itβs the preferred monitoring role in production systems.
- Summary
pg_monitor = Read-only monitoring access
Safe
Non-destructive
Ideal for observability
Designed for modern DB operations