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.

CloudNativePG logoCloudNativePG Prometheus Alert Rules

9 Prometheus alerting rules for CloudNativePG.Exported via Embedded 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. 😉

2.7.CloudNativePG logoEmbedded exporter(9 rules)

Each instance pod exposes its metrics on port 9187 (enable `spec.monitoring.enablePodMonitor` or add your own PodMonitor).
The `cnpg_pg_*` series come from the default monitoring queries (`cnpg-default-monitoring` ConfigMap), the `cnpg_collector_*` ones from the instance manager.
wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/refs/heads/master/dist/rules/cloudnativepg/embedded-exporter.yml
critical

2.7.1.CloudNativePG instance down

PostgreSQL of cluster {{ $labels.cluster }} is not accepting connections on {{ $labels.instance }}.

  # 1m delay allows a restart without triggering an alert.
- alert: CloudnativepgInstanceDown
  expr: 'cnpg_collector_up == 0'
  for: 1m
  labels:
    severity: critical
  annotations:
    summary: CloudNativePG instance down (instance {{ $labels.instance }})
    description: "PostgreSQL of cluster {{ $labels.cluster }} is not accepting connections on {{ $labels.instance }}.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.7.2.CloudNativePG instance flapping

CloudNativePG instance on {{ $labels.instance }} changed state {{ $value | printf "%.0f" }} times in the last 10 minutes.

  # Catches a crash-looping service, which the down rule misses because each successful scrape resets its for: timer.
  # 4 changes means at least 2 down/up cycles in 10m; one outage followed by a recovery counts only 2.
- alert: CloudnativepgInstanceFlapping
  expr: 'changes(cnpg_collector_up[10m]) >= 4'
  for: 0m
  labels:
    severity: critical
  annotations:
    summary: CloudNativePG instance flapping (instance {{ $labels.instance }})
    description: "CloudNativePG instance on {{ $labels.instance }} changed state {{ $value | printf \"%.0f\" }} times in the last 10 minutes.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.7.3.CloudNativePG replica not streaming

Replica {{ $labels.instance }} is in recovery but its WAL receiver is not running. It no longer receives changes from the primary.

  # The designated primary of a replica cluster that only restores WAL from an object store has no WAL receiver either.
- alert: CloudnativepgReplicaNotStreaming
  expr: 'cnpg_pg_replication_in_recovery == 1 and cnpg_pg_replication_is_wal_receiver_up == 0'
  for: 5m
  labels:
    severity: critical
  annotations:
    summary: CloudNativePG replica not streaming (instance {{ $labels.instance }})
    description: "Replica {{ $labels.instance }} is in recovery but its WAL receiver is not running. It no longer receives changes from the primary.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.7.4.CloudNativePG replication lag (> 5m)

Replica {{ $labels.instance }} replays WAL {{ $value | humanizeDuration }} behind the primary.

  # The query reports 0 when the replica has replayed everything it received, so an idle primary does not raise the lag.
  # Threshold of 5m is arbitrary. Adjust it to your workload.
- alert: CloudnativepgReplicationLag(>5m)
  expr: 'cnpg_pg_replication_lag > 300'
  for: 5m
  labels:
    severity: warning
  annotations:
    summary: CloudNativePG replication lag (> 5m) (instance {{ $labels.instance }})
    description: "Replica {{ $labels.instance }} replays WAL {{ $value | humanizeDuration }} behind the primary.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.7.5.CloudNativePG inactive replication slot

Replication slot {{ $labels.slot_name }} on {{ $labels.instance }} has been inactive for 30 minutes and holds back {{ $value | humanize1024 }}B of WAL. The WAL volume keeps growing until the slot is used or dropped.

- alert: CloudnativepgInactiveReplicationSlot
  expr: 'cnpg_pg_replication_slots_pg_wal_lsn_diff and on (instance, slot_name) cnpg_pg_replication_slots_active == 0'
  for: 30m
  labels:
    severity: warning
  annotations:
    summary: CloudNativePG inactive replication slot (instance {{ $labels.instance }})
    description: "Replication slot {{ $labels.slot_name }} on {{ $labels.instance }} has been inactive for 30 minutes and holds back {{ $value | humanize1024 }}B of WAL. The WAL volume keeps growing until the slot is used or dropped.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
critical

2.7.6.CloudNativePG WAL archiving failing

The last WAL archiving attempt on {{ $labels.instance }} failed and no segment was archived since. Point-in-time recovery stops at the last archived segment and pg_wal keeps growing.

- alert: CloudnativepgWalArchivingFailing
  expr: 'cnpg_pg_stat_archiver_last_failed_time > cnpg_pg_stat_archiver_last_archived_time'
  for: 5m
  labels:
    severity: critical
  annotations:
    summary: CloudNativePG WAL archiving failing (instance {{ $labels.instance }})
    description: "The last WAL archiving attempt on {{ $labels.instance }} failed and no segment was archived since. Point-in-time recovery stops at the last archived segment and pg_wal keeps growing.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
warning

2.7.7.CloudNativePG WAL segments waiting for archive (> 10)

{{ $value | printf "%.0f" }} WAL segments on {{ $labels.instance }} are waiting to be archived.

  # Threshold of 10 segments is arbitrary. Adjust it to your write rate.
- alert: CloudnativepgWalSegmentsWaitingForArchive(>10)
  expr: 'cnpg_collector_pg_wal_archive_status{value="ready"} > 10'
  for: 10m
  labels:
    severity: warning
  annotations:
    summary: CloudNativePG WAL segments waiting for archive (> 10) (instance {{ $labels.instance }})
    description: "{{ $value | printf \"%.0f\" }} WAL segments on {{ $labels.instance }} are waiting to be archived.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
info

2.7.8.CloudNativePG instance fenced

Instance {{ $labels.instance }} has been fenced for 15 minutes. PostgreSQL is stopped on it until the fencing annotation is removed.

- alert: CloudnativepgInstanceFenced
  expr: 'cnpg_collector_fencing_on == 1'
  for: 15m
  labels:
    severity: info
  annotations:
    summary: CloudNativePG instance fenced (instance {{ $labels.instance }})
    description: "Instance {{ $labels.instance }} has been fenced for 15 minutes. PostgreSQL is stopped on it until the fencing annotation is removed.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"
info

2.7.9.CloudNativePG metrics collection errors

The last metrics collection on {{ $labels.instance }} failed. Some cnpg_* series may be missing or stale.

- alert: CloudnativepgMetricsCollectionErrors
  expr: 'cnpg_collector_last_collection_error == 1'
  for: 10m
  labels:
    severity: info
  annotations:
    summary: CloudNativePG metrics collection errors (instance {{ $labels.instance }})
    description: "The last metrics collection on {{ $labels.instance }} failed. Some cnpg_* series may be missing or stale.\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

Share your alerting rules

Your production alerts can make this collection better. Share your rule files in one command: only Prometheus rule files and PrometheusRule resources are uploaded, while prometheus.yml, alertmanager.yml and other configurations are skipped, as they often contain credentials.

npx awesome-prometheus-alerts share /etc/prometheus/rules

Add --dry-run to preview what would be sent.