Skip to content

Commit 98f75c7

Browse files
authored
stop logging errors on replicas, fixes #547 (#1048)
Signed-off-by: Steffen Zieger <[email protected]>
1 parent 3c5ef40 commit 98f75c7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cmd/postgres_exporter/queries.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,26 @@ var queryOverrides = map[string][]OverrideQuery{
5151
semver.MustParseRange(">=10.0.0"),
5252
`
5353
SELECT *,
54-
(case pg_is_in_recovery() when 't' then null else pg_current_wal_lsn() end) AS pg_current_wal_lsn,
55-
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), pg_lsn('0/0'))::float end) AS pg_current_wal_lsn_bytes,
56-
(case pg_is_in_recovery() when 't' then null else pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)::float end) AS pg_wal_lsn_diff
54+
(case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end) AS pg_current_wal_lsn,
55+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), pg_lsn('0/0'))::float else pg_wal_lsn_diff(pg_current_wal_lsn(), pg_lsn('0/0'))::float end) AS pg_current_wal_lsn_bytes,
56+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), replay_lsn)::float else pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)::float end) AS pg_wal_lsn_diff
5757
FROM pg_stat_replication
5858
`,
5959
},
6060
{
6161
semver.MustParseRange(">=9.2.0 <10.0.0"),
6262
`
6363
SELECT *,
64-
(case pg_is_in_recovery() when 't' then null else pg_current_xlog_location() end) AS pg_current_xlog_location,
65-
(case pg_is_in_recovery() when 't' then null else pg_xlog_location_diff(pg_current_xlog_location(), replay_location)::float end) AS pg_xlog_location_diff
64+
(case pg_is_in_recovery() when 't' then pg_last_xlog_receive_location() else pg_current_xlog_location() end) AS pg_current_xlog_location,
65+
(case pg_is_in_recovery() when 't' then pg_xlog_location_diff(pg_last_xlog_receive_location(), replay_location)::float else pg_xlog_location_diff(pg_current_xlog_location(), replay_location)::float end) AS pg_xlog_location_diff
6666
FROM pg_stat_replication
6767
`,
6868
},
6969
{
7070
semver.MustParseRange("<9.2.0"),
7171
`
7272
SELECT *,
73-
(case pg_is_in_recovery() when 't' then null else pg_current_xlog_location() end) AS pg_current_xlog_location
73+
(case pg_is_in_recovery() when 't' then pg_last_xlog_receive_location() else pg_current_xlog_location() end) AS pg_current_xlog_location
7474
FROM pg_stat_replication
7575
`,
7676
},
@@ -80,14 +80,16 @@ var queryOverrides = map[string][]OverrideQuery{
8080
{
8181
semver.MustParseRange(">=9.4.0 <10.0.0"),
8282
`
83-
SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn)
83+
SELECT slot_name, database, active,
84+
(case pg_is_in_recovery() when 't' then pg_xlog_location_diff(pg_last_xlog_receive_location(), restart_lsn) else pg_xlog_location_diff(pg_current_xlog_location(), restart_lsn) end) as pg_xlog_location_diff
8485
FROM pg_replication_slots
8586
`,
8687
},
8788
{
8889
semver.MustParseRange(">=10.0.0"),
8990
`
90-
SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
91+
SELECT slot_name, database, active,
92+
(case pg_is_in_recovery() when 't' then pg_wal_lsn_diff(pg_last_wal_receive_lsn(), restart_lsn) else pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) end) as pg_wal_lsn_diff
9193
FROM pg_replication_slots
9294
`,
9395
},

0 commit comments

Comments
 (0)