Skip to main content
APA
Sponsored byCAST AI — Kubernetes cost optimizationBetter Stack — Uptime monitoring and log managementVictoriaMetrics — Fast, open-source time series database and drop-in Prometheus replacement.

PGBouncer logoPGBouncer Prometheus Alert Rules

6 Prometheus alerting rules for PGBouncer.Exported via spreaker/prometheus-pgbouncer-exporter.These rules cover critical and warning conditions — copy and paste the YAML into your Prometheus configuration.

⚠️

Alert thresholds depend on the nature of your applications. Some queries may have arbitrary tolerance thresholds. Building an efficient monitoring platform takes time. 😉

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/pgbouncer/spreaker-pgbouncer-exporter.yml
critical

2.6.1.PGBouncer max connections

The number of PGBouncer client connections has reached max_client_conn.

- alert: PGBouncerMaxConnections
  expr: sum(pgbouncer_pools_client_active_connections + pgbouncer_pools_client_waiting_connections) >= pgbouncer_config_max_client_conn
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: PGBouncer max connections (instance {{ $labels.instance }})
    description: "The number of PGBouncer client connections has reached max_client_conn.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.6.2.PGBouncer server connection saturation critical

User connection capacity on {{ $labels.instance }} is above 90% ({{ $value | printf "%.2f" }}%), meaning PGBouncer is about to exhaust its configured max_user_connections limit.

- alert: PGBouncerServerConnectionSaturationCritical
  expr: 100 * (sum without (database, user) (pgbouncer_pools_server_active_connections + pgbouncer_pools_server_idle_connections + pgbouncer_pools_server_used_connections) / clamp_min(pgbouncer_config_max_user_connections,1)) > 90
  for: 2m
  labels:
    severity: critical
  annotations:
    summary: PGBouncer server connection saturation critical (instance {{ $labels.instance }})
    description: "User connection capacity on {{ $labels.instance }} is above 90% ({{ $value | printf \"%.2f\" }}%), meaning PGBouncer is about to exhaust its configured max_user_connections limit.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.6.3.PGBouncer active connections

PGBouncer pools are filling up

  # 200 is a rough default; adjust based on your configured pgbouncer pool_size and backend database capacity.
- alert: PGBouncerActiveConnections
  expr: pgbouncer_pools_server_active_connections > 200
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: PGBouncer active connections (instance {{ $labels.instance }})
    description: "PGBouncer pools are filling up\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.6.4.PGBouncer clients waiting for connection

{{ $value }} client connections are queued in pool {{ $labels.database }}/{{ $labels.user }} waiting for a server connection, indicating pool exhaustion.

  # 20 is a rough default; queue depth depends on your traffic volume relative to configured pool_size — adjust based on your workload.
- alert: PGBouncerClientsWaitingForConnection
  expr: pgbouncer_pools_client_waiting_connections > 20
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: PGBouncer clients waiting for connection (instance {{ $labels.instance }})
    description: "{{ $value }} client connections are queued in pool {{ $labels.database }}/{{ $labels.user }} waiting for a server connection, indicating pool exhaustion.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.6.5.PGBouncer server connection saturation warning

User connection capacity on {{ $labels.instance }} is above 80% ({{ $value | printf "%.2f" }}%), meaning PGBouncer is nearing its configured max_user_connections limit.

- alert: PGBouncerServerConnectionSaturationWarning
  expr: 100 * (sum without (database, user) (pgbouncer_pools_server_active_connections + pgbouncer_pools_server_idle_connections + pgbouncer_pools_server_used_connections) / clamp_min(pgbouncer_config_max_user_connections,1)) > 80
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: PGBouncer server connection saturation warning (instance {{ $labels.instance }})
    description: "User connection capacity on {{ $labels.instance }} is above 80% ({{ $value | printf \"%.2f\" }}%), meaning PGBouncer is nearing its configured max_user_connections limit.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.6.6.PGBouncer high client wait time

The oldest queued client in pool {{ $labels.database }}/{{ $labels.user }} has been waiting {{ $value }}s for a server connection, which may indicate pool saturation or slow backend performance.

  # 15s threshold is a rough default; depends on your configured pool_size and backend database capacity — adjust based on your workload.
- alert: PGBouncerHighClientWaitTime
  expr: pgbouncer_pools_client_maxwait_seconds > 15
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: PGBouncer high client wait time (instance {{ $labels.instance }})
    description: "The oldest queued client in pool {{ $labels.database }}/{{ $labels.user }} has been waiting {{ $value }}s for a server connection, which may indicate pool saturation or slow backend performance.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"