-
-
Save lfittl/9ee78ac200e4e7ebe33d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE SCHEMA monitoring; | |
CREATE OR REPLACE FUNCTION monitoring.get_stat_statements() RETURNS SETOF pg_stat_statements AS | |
$$ | |
SELECT * FROM public.pg_stat_statements | |
WHERE dbid IN (SELECT oid FROM pg_database WHERE datname = current_database()); | |
$$ LANGUAGE sql VOLATILE SECURITY DEFINER; | |
CREATE USER monitoring PASSWORD 'mypassword'; | |
REVOKE ALL ON SCHEMA public FROM monitoring; | |
GRANT USAGE ON SCHEMA monitoring TO monitoring; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After creating this with a super user, use
SELECT * FROM monitoring.get_stat_statements();
for querying as the monitoring user.