CREATE FUNCTION get_sa()
RETURNS SETOF pg_stat_activity LANGUAGE sql AS
$$ SELECT * FROM pg_catalog.pg_stat_activity; $$
VOLATILE
SECURITY DEFINER;
CREATE VIEW pg_stat_activity_allusers AS SELECT * FROM get_sa();
GRANT SELECT ON pg_stat_activity_allusers TO public;
CODE
CREATE FUNCTION get_querystats()
RETURNS SETOF pg_stat_statements LANGUAGE sql AS
$$ SELECT * FROM pg_stat_statements; $$
VOLATILE
SECURITY DEFINER;
CREATE VIEW pg_stat_statements_allusers AS SELECT * FROM get_querystats();
GRANT SELECT ON pg_stat_statements_allusers TO public;