Skip to content

Commit 496edc0

Browse files
authored
Merge pull request #92 from cybertec-postgresql/FixpgBackRestMonitoring
fix for pgBackRest Monitoring on Replicas
2 parents 6568409 + ed2abae commit 496edc0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/cluster/database.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ const (
113113
last_entry_timestamp TIMESTAMP;
114114
record_count INT;
115115
BEGIN
116+
IF pg_is_in_recovery() THEN
117+
RAISE NOTICE 'Skipping pgbackrest_info update: running on a replica.';
118+
RETURN;
119+
END IF;
120+
116121
SELECT COUNT(*) INTO record_count
117122
FROM exporter.pgbackrestbackupinfo;
118123
@@ -122,18 +127,20 @@ const (
122127
ORDER BY data_time DESC
123128
LIMIT 1;
124129
125-
IF last_entry_timestamp < NOW() - INTERVAL '5 minutes' THEN
126-
DELETE FROM exporter.pgbackrestbackupinfo;
127-
ELSE
130+
IF last_entry_timestamp >= NOW() - INTERVAL '5 minutes' THEN
131+
RAISE NOTICE 'Skipping pgbackrest_info update: data does not need an update (last update at %).', last_entry_timestamp;
128132
RETURN;
129133
END IF;
134+
135+
DELETE FROM exporter.pgbackrestbackupinfo;
130136
END IF;
131137
132138
EXECUTE format(
133139
'COPY exporter.pgbackrestbackupinfo (data) FROM program ''pgbackrest info --output=json'' WITH (FORMAT text, DELIMITER ''|'')'
134140
);
135141
END;
136142
$$ LANGUAGE plpgsql;
143+
137144
`
138145
)
139146

0 commit comments

Comments
 (0)