Skip to content

Exclude pg_dump sessions from PostgresqlSlowQueries alert - #139

Merged
ArnobKumarSaha merged 1 commit into
masterfrom
fix-postgres-slow-queries-pg-dump
Aug 14, 2026
Merged

Exclude pg_dump sessions from PostgresqlSlowQueries alert#139
ArnobKumarSaha merged 1 commit into
masterfrom
fix-postgres-slow-queries-pg-dump

Conversation

@souravbiswassanto

@souravbiswassanto souravbiswassanto commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Problem

PostgresqlSlowQueries fires on every pg_dump backup:

PostgreSQL has a transaction running longer than 60s on ace-db-2.
  VALUE = 136.308345
  LABELS = map[__name__:pg_stat_activity_max_tx_duration application_name:pg_dump backend_type:client backend container:exporter datname:ace endpoint:metrics instance:10.2.4.8:56790 job:ace-db-stats namespace:ace pod:ace-db-2 server:localhost:5432 service:ace-db-stats state:active usename:postgres]

pg_dump holds a single repeatable-read transaction open for the entire duration of the dump to get a consistent snapshot, so pg_stat_activity_max_tx_duration for that session grows to however long the backup takes. That is expected behaviour for a backup, not a slow query, so the alert is pure noise on any database large enough for a dump to exceed the threshold.

Change

Add application_name!~"pg_dump.*" to the alert expression in charts/postgres-alerts/templates/alert.yaml, which drops both pg_dump and pg_dumpall sessions. Client workloads that are genuinely slow still trigger the alert unchanged.

Rendered output:

- alert: PostgresqlSlowQueries
  expr: pg_stat_activity_max_tx_duration{job="test-stats",namespace="ace",state="active",application_name!~"pg_dump.*"} > 60

Verified with helm template.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

pg_dump takes a long-lived transaction snapshot for the whole duration
of a backup, so pg_stat_activity_max_tx_duration crosses the 60s
threshold on every backup and fires PostgresqlSlowQueries. Those are
expected long transactions, not slow queries.

Filter out backup sessions by application_name (pg_dump, pg_dumpall) so
the alert only reflects genuinely slow client workloads.

Signed-off-by: souravbiswassanto <saurov@appscode.com>
@ArnobKumarSaha
ArnobKumarSaha merged commit 062da60 into master Aug 14, 2026
25 checks passed
@ArnobKumarSaha
ArnobKumarSaha deleted the fix-postgres-slow-queries-pg-dump branch August 14, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants