mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-06 03:53:59 +02:00
ae258f604e
The copy command was converting \n to a linefeed, which the json conversion did not like. In a healthy repository there won't be any linefeeds but certain errors can contain them. Fix by loading into a text field and then replacing the linefeed when converting to jsonb.
31 lines
871 B
PL/PgSQL
31 lines
871 B
PL/PgSQL
-- An example of monitoring pgBackRest from within PostgreSQL
|
|
--
|
|
-- Use copy to export data from the pgBackRest info command into the jsonb
|
|
-- type so it can be queried directly by PostgreSQL.
|
|
|
|
-- 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 text);
|
|
|
|
-- Copy data into the table directly from the pgBackRest info command
|
|
copy temp_pgbackrest_data (data)
|
|
from program
|
|
'pgbackrest --output=json info' (format text);
|
|
|
|
select replace(temp_pgbackrest_data.data, E'\n', '\n')::jsonb
|
|
into data
|
|
from temp_pgbackrest_data;
|
|
|
|
drop table temp_pgbackrest_data;
|
|
|
|
return data;
|
|
end $$ language plpgsql;
|