2 -- Only superusers and roles with privileges of the pg_read_all_stats role
3 -- are allowed to see the SQL text and queryid of queries executed by
4 -- other users. Other users can see the statistics.
7 SET pg_stat_statements.track_utility = FALSE;
8 CREATE ROLE regress_stats_superuser SUPERUSER;
9 CREATE ROLE regress_stats_user1;
10 CREATE ROLE regress_stats_user2;
11 GRANT pg_read_all_stats TO regress_stats_user2;
13 SET ROLE regress_stats_superuser;
14 SELECT pg_stat_statements_reset() IS NOT NULL AS t;
17 SET ROLE regress_stats_user1;
21 -- A superuser can read all columns of queries executed by others,
22 -- including query text and queryid.
25 SET ROLE regress_stats_superuser;
26 SELECT r.rolname, ss.queryid <> 0 AS queryid_bool, ss.query, ss.calls, ss.rows
27 FROM pg_stat_statements ss JOIN pg_roles r ON ss.userid = r.oid
28 ORDER BY r.rolname, ss.query COLLATE "C", ss.calls, ss.rows;
31 -- regress_stats_user1 has no privileges to read the query text or
32 -- queryid of queries executed by others but can see statistics
33 -- like calls and rows.
36 SET ROLE regress_stats_user1;
37 SELECT r.rolname, ss.queryid <> 0 AS queryid_bool, ss.query, ss.calls, ss.rows
38 FROM pg_stat_statements ss JOIN pg_roles r ON ss.userid = r.oid
39 ORDER BY r.rolname, ss.query COLLATE "C", ss.calls, ss.rows;
42 -- regress_stats_user2, with pg_read_all_stats role privileges, can
43 -- read all columns, including query text and queryid, of queries
44 -- executed by others.
47 SET ROLE regress_stats_user2;
48 SELECT r.rolname, ss.queryid <> 0 AS queryid_bool, ss.query, ss.calls, ss.rows
49 FROM pg_stat_statements ss JOIN pg_roles r ON ss.userid = r.oid
50 ORDER BY r.rolname, ss.query COLLATE "C", ss.calls, ss.rows;
57 DROP ROLE regress_stats_superuser;
58 DROP ROLE regress_stats_user1;
59 DROP ROLE regress_stats_user2;
60 SELECT pg_stat_statements_reset() IS NOT NULL AS t;