2019-01-09 19:20:38 +02:00
|
|
|
-- An example of monitoring pgBackRest from within PostgreSQL
|
2018-04-13 20:31:33 +02:00
|
|
|
--
|
|
|
|
-- Use copy to export data from the pgBackRest info command into the jsonb
|
2019-01-09 19:20:38 +02:00
|
|
|
-- type so it can be queried directly by PostgreSQL.
|
2018-04-13 20:31:33 +02:00
|
|
|
|
|
|
|
-- Create monitor schema
|
|
|
|
create schema monitor;
|
|
|
|
|
|
|
|
-- Get pgBackRest info in JSON format
|
|
|
|
create function monitor.pgbackrest_info()
|
|
|
|
returns jsonb AS $$
|
|
|
|
declare
|
|
|
|
data jsonb;
|
|
|
|
begin
|
|
|
|
-- Create a temp table to hold the JSON data
|
|
|
|
create temp table temp_pgbackrest_data (data jsonb);
|
|
|
|
|
2019-10-11 18:56:03 +02:00
|
|
|
-- Copy data into the table directly from the pgBackRest info command
|
2018-04-13 20:31:33 +02:00
|
|
|
copy temp_pgbackrest_data (data)
|
|
|
|
from program
|
2019-10-11 18:56:03 +02:00
|
|
|
'pgbackrest --output=json info' (format text);
|
2018-04-13 20:31:33 +02:00
|
|
|
|
|
|
|
select temp_pgbackrest_data.data
|
|
|
|
into data
|
|
|
|
from temp_pgbackrest_data;
|
|
|
|
|
|
|
|
drop table temp_pgbackrest_data;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end $$ language plpgsql;
|