Configure PostgreSQL exporter to generate Prometheus metrics
To enable PostgreSQL for the Prometheus metrics, use the Prometheus exporter for PostgreSQL.
To configure PostgreSQL exporter to generate Prometheus metrics, perform the following steps:
Run the following command on a running instance of PostgreSQL to enable exporter using Docker.
1docker run \ 2 --net=host \ 3 -e DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" \ 4 quay.io/prometheuscommunity/postgres-exporter
To confirm that the exporter is attached to the database instance, ensure the following metrics are available in Prometheus.
pg_stat_database_numbackends
pg_stat_database_xact_commit
Request and error metrics
Resource metrics
Alerts
Failure alerts
PostgresIsDown: Postgresql is not running
pg_up != 1
PostgresGotRestarted: Postgresql server restarted
time() - pg_postmaster_start_time_seconds < 60
PostgresHasHighDeadLocks: Postgresql is having too many deadlocks
rate(pg_stat_database_deadlocks[1m]) * 60 > 5
PostgresHasExporterErrors: Exporter is not running properly
pg_exporter_last_scrape_error > 0
Dashboards
The following dashboard shows key metrics such as:
- Uptime
- Transactions
- Active Session
- Max Connection
You can configure a custom dashboard if you require detailed information for each PostgreSQL Prometheus metric.