33
33
34
34
#define UINT32_ACCESS_ONCE (var ) ((uint32)(*((volatile uint32 *)&(var))))
35
35
36
+ #define HAS_PGSTAT_PERMISSIONS (role ) (is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
37
+
36
38
/* Global bgwriter statistics, from bgwriter.c */
37
39
extern PgStat_MsgBgWriter bgwriterStats ;
38
40
@@ -518,7 +520,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
518
520
values [1 ] = ObjectIdGetDatum (beentry -> st_databaseid );
519
521
520
522
/* show rest of the values including relid only to role members */
521
- if (has_privs_of_role ( GetUserId (), beentry -> st_userid ))
523
+ if (HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
522
524
{
523
525
values [2 ] = ObjectIdGetDatum (beentry -> st_progress_command_target );
524
526
for (i = 0 ; i < PGSTAT_NUM_PROGRESS_PARAM ; i ++ )
@@ -651,8 +653,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
651
653
nulls [16 ] = true;
652
654
653
655
/* Values only available to role member or pg_read_all_stats */
654
- if (has_privs_of_role (GetUserId (), beentry -> st_userid ) ||
655
- is_member_of_role (GetUserId (), DEFAULT_ROLE_READ_ALL_STATS ))
656
+ if (HAS_PGSTAT_PERMISSIONS (beentry -> st_userid ))
656
657
{
657
658
SockAddr zero_clientaddr ;
658
659
char * clipped_activity ;
@@ -981,7 +982,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
981
982
982
983
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
983
984
activity = "<backend information not available>" ;
984
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
985
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
985
986
activity = "<insufficient privilege>" ;
986
987
else if (* (beentry -> st_activity_raw ) == '\0' )
987
988
activity = "<command string not enabled>" ;
@@ -1005,7 +1006,7 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
1005
1006
1006
1007
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1007
1008
wait_event_type = "<backend information not available>" ;
1008
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1009
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1009
1010
wait_event_type = "<insufficient privilege>" ;
1010
1011
else if ((proc = BackendPidGetProc (beentry -> st_procpid )) != NULL )
1011
1012
wait_event_type = pgstat_get_wait_event_type (proc -> wait_event_info );
@@ -1026,7 +1027,7 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
1026
1027
1027
1028
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1028
1029
wait_event = "<backend information not available>" ;
1029
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1030
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1030
1031
wait_event = "<insufficient privilege>" ;
1031
1032
else if ((proc = BackendPidGetProc (beentry -> st_procpid )) != NULL )
1032
1033
wait_event = pgstat_get_wait_event (proc -> wait_event_info );
@@ -1048,7 +1049,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
1048
1049
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1049
1050
PG_RETURN_NULL ();
1050
1051
1051
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1052
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1052
1053
PG_RETURN_NULL ();
1053
1054
1054
1055
result = beentry -> st_activity_start_timestamp ;
@@ -1074,7 +1075,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
1074
1075
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1075
1076
PG_RETURN_NULL ();
1076
1077
1077
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1078
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1078
1079
PG_RETURN_NULL ();
1079
1080
1080
1081
result = beentry -> st_xact_start_timestamp ;
@@ -1096,7 +1097,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
1096
1097
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1097
1098
PG_RETURN_NULL ();
1098
1099
1099
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1100
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1100
1101
PG_RETURN_NULL ();
1101
1102
1102
1103
result = beentry -> st_proc_start_timestamp ;
@@ -1120,7 +1121,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
1120
1121
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1121
1122
PG_RETURN_NULL ();
1122
1123
1123
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1124
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1124
1125
PG_RETURN_NULL ();
1125
1126
1126
1127
/* A zeroed client addr means we don't know */
@@ -1167,7 +1168,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
1167
1168
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1168
1169
PG_RETURN_NULL ();
1169
1170
1170
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1171
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1171
1172
PG_RETURN_NULL ();
1172
1173
1173
1174
/* A zeroed client addr means we don't know */
0 commit comments