--PBA
do $$
begin
begin
create or replace view "pg-exporter-bss".pg_stat_activity
(datid, datname, pid, usesysid, usename, application_name, client_addr, client_hostname, client_port,
backend_start, xact_start, query_start, state_change, wait_event_type, wait_event, state, backend_xid,
backend_xmin, query, backend_type)
as
SELECT get_pg_stat_activity.datid,
get_pg_stat_activity.datname,
get_pg_stat_activity.pid,
get_pg_stat_activity.usesysid,
get_pg_stat_activity.usename,
get_pg_stat_activity.application_name,
get_pg_stat_activity.client_addr,
get_pg_stat_activity.client_hostname,
get_pg_stat_activity.client_port,
get_pg_stat_activity.backend_start,
get_pg_stat_activity.xact_start,
get_pg_stat_activity.query_start,
get_pg_stat_activity.state_change,
get_pg_stat_activity.wait_event_type,
get_pg_stat_activity.wait_event,
get_pg_stat_activity.state,
get_pg_stat_activity.backend_xid,
get_pg_stat_activity.backend_xmin,
get_pg_stat_activity.query,
get_pg_stat_activity.backend_type
FROM get_pg_stat_activity() get_pg_stat_activity;
alter view "pg-exporter-bss".pg_stat_activity owner to pba;
begin
grant select on "pg-exporter-bss".pg_stat_activity to "pg-exporter-bss";
exception
when undefined_object then
raise warning 'no "pg-exporter-bss" role exists!';
end;
begin
grant select on "pg-exporter-bss".pg_stat_activity to readonlyall;
exception
when undefined_object then
raise notice 'no readonlyall role - nothing additional is granted';
end;
exception
when invalid_schema_name then
raise notice 'no "pg-exporter-bss" exists, no view is created';
end;
end;
$$;