|
62 | 62 | #include<unistd.h>
|
63 | 63 |
|
64 | 64 | #include"access/hash.h"
|
| 65 | +#include"catalog/pg_authid.h" |
65 | 66 | #include"executor/instrument.h"
|
66 | 67 | #include"funcapi.h"
|
67 | 68 | #include"mb/pg_wchar.h"
|
@@ -1391,14 +1392,17 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
|
1391 | 1392 | MemoryContextper_query_ctx;
|
1392 | 1393 | MemoryContextoldcontext;
|
1393 | 1394 | Oiduserid=GetUserId();
|
1394 |
| -boolis_superuser=superuser(); |
| 1395 | +boolis_allowed_role=false; |
1395 | 1396 | char*qbuffer=NULL;
|
1396 | 1397 | Sizeqbuffer_size=0;
|
1397 | 1398 | Sizeextent=0;
|
1398 | 1399 | intgc_count=0;
|
1399 | 1400 | HASH_SEQ_STATUShash_seq;
|
1400 | 1401 | pgssEntry*entry;
|
1401 | 1402 |
|
| 1403 | +/* Superusers or members of pg_read_all_stats members are allowed */ |
| 1404 | +is_allowed_role=is_member_of_role(GetUserId(),DEFAULT_ROLE_READ_ALL_STATS); |
| 1405 | + |
1402 | 1406 | /* hash table must exist already */
|
1403 | 1407 | if (!pgss|| !pgss_hash)
|
1404 | 1408 | ereport(ERROR,
|
@@ -1541,7 +1545,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
|
1541 | 1545 | values[i++]=ObjectIdGetDatum(entry->key.userid);
|
1542 | 1546 | values[i++]=ObjectIdGetDatum(entry->key.dbid);
|
1543 | 1547 |
|
1544 |
| -if (is_superuser||entry->key.userid==userid) |
| 1548 | +if (is_allowed_role||entry->key.userid==userid) |
1545 | 1549 | {
|
1546 | 1550 | if (api_version >=PGSS_V1_2)
|
1547 | 1551 | values[i++]=Int64GetDatumFast(queryid);
|
|