Skip to content

Commit 6354b0c

Browse files
authored
Add query for 'pg_replication_slots' (prometheus-community#465)
The existing 'pg_stat_replication' data does not include stats for inactive replication slots. This commit adds a minimal amount of metrics from 'pg_replication_slots' to know if a slot is active and its lag. This is helpful to detect if an inactive slot is causing the server to run out of storage due to an inactive slot blocking WAL flushing.
1 parent b12c8ab commit 6354b0c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/postgres_exporter/postgres_exporter.go

+20
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
315315
true,
316316
0,
317317
},
318+
"pg_replication_slots": {
319+
map[string]ColumnMapping{
320+
"slot_name": {LABEL, "Name of the replication slot", nil, nil},
321+
"database": {LABEL, "Name of the database", nil, nil},
322+
"active": {GAUGE, "Flag indicating if the slot is active", nil, nil},
323+
"pg_wal_lsn_diff": {GAUGE, "Replication lag in bytes", nil, nil},
324+
},
325+
true,
326+
0,
327+
},
318328
"pg_stat_archiver": {
319329
map[string]ColumnMapping{
320330
"archived_count": {COUNTER, "Number of WAL files that have been successfully archived", nil, nil},
@@ -407,6 +417,16 @@ var queryOverrides = map[string][]OverrideQuery{
407417
},
408418
},
409419

420+
"pg_replication_slots": {
421+
{
422+
semver.MustParseRange(">=9.4.0"),
423+
`
424+
SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
425+
FROM pg_replication_slots
426+
`,
427+
},
428+
},
429+
410430
"pg_stat_archiver": {
411431
{
412432
semver.MustParseRange(">=0.0.0"),

0 commit comments

Comments
 (0)