File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,41 @@ const (
134134 );
135135 END;
136136 $$ LANGUAGE plpgsql;
137+
138+ CREATE OR REPLACE FUNCTION exporter.update_pgbackrest_info()
139+ RETURNS VOID AS $$
140+ DECLARE
141+ last_entry_timestamp TIMESTAMP;
142+ record_count INT;
143+ BEGIN
144+ IF pg_is_in_recovery() THEN
145+ RAISE NOTICE 'Skipping pgbackrest_info update: running on a replica.';
146+ RETURN;
147+ END IF;
148+
149+ SELECT COUNT(*) INTO record_count
150+ FROM exporter.pgbackrestbackupinfo;
151+
152+ IF record_count > 0 THEN
153+ SELECT data_time INTO last_entry_timestamp
154+ FROM exporter.pgbackrestbackupinfo
155+ ORDER BY data_time DESC
156+ LIMIT 1;
157+
158+ IF last_entry_timestamp >= NOW() - INTERVAL '5 minutes' THEN
159+ RAISE NOTICE 'Skipping pgbackrest_info update: data does not need an update (last update at %).', last_entry_timestamp;
160+ RETURN;
161+ END IF;
162+
163+ DELETE FROM exporter.pgbackrestbackupinfo;
164+ END IF;
165+
166+ EXECUTE format(
167+ 'COPY exporter.pgbackrestbackupinfo (data) FROM program ''pgbackrest info --output=json'' WITH (FORMAT text, DELIMITER ''|'')'
168+ );
169+ END;
170+ $$ LANGUAGE plpgsql;
171+
137172 `
138173)
139174
You can’t perform that action at this time.
0 commit comments