Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function for pgbackrest-data #61

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion pkg/cluster/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,40 @@ const (
CREATE EXTENSION IF NOT EXISTS pgnodemx with SCHEMA exporter;
alter extension pgnodemx UPDATE;
CREATE TABLE IF NOT EXISTS exporter.pgbackrestbackupinfo (
name text NOT NULL,
data jsonb NOT NULL,
data_time timestamp with time zone DEFAULT now() NOT NULL
)
WITH (autovacuum_analyze_scale_factor='0', autovacuum_vacuum_scale_factor='0', autovacuum_vacuum_threshold='2', autovacuum_analyze_threshold='2');
ALTER TABLE exporter.pgbackrestbackupinfo OWNER TO cpo_exporter;
CREATE OR REPLACE FUNCTION exporter.update_pgbackrest_info()
RETURNS VOID AS $$
DECLARE
last_entry_timestamp TIMESTAMP;
record_count INT;
BEGIN
SELECT COUNT(*) INTO record_count
FROM exporter.pgbackrestbackupinfo;
IF record_count > 0 THEN
SELECT data_time INTO last_entry_timestamp
FROM exporter.pgbackrestbackupinfo
ORDER BY data_time DESC
LIMIT 1;
IF last_entry_timestamp < NOW() - INTERVAL '5 minutes' THEN
DELETE FROM exporter.pgbackrestbackupinfo;
ELSE
RETURN;
END IF;
END IF;
EXECUTE format(
'COPY exporter.pgbackrestbackupinfo (data) FROM program ''pgbackrest info --output=json'' WITH (FORMAT text, DELIMITER ''|'')'
);
END;
$$ LANGUAGE plpgsql;
`
)

Expand Down
Loading