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
@@ -537,7 +539,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
537
539
values [1 ] = ObjectIdGetDatum (beentry -> st_databaseid );
538
540
539
541
/* show rest of the values including relid only to role members */
540
- if (has_privs_of_role ( GetUserId (), beentry -> st_userid ))
542
+ if (HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
541
543
{
542
544
values [2 ] = ObjectIdGetDatum (beentry -> st_progress_command_target );
543
545
for (i = 0 ; i < PGSTAT_NUM_PROGRESS_PARAM ; i ++ )
@@ -669,8 +671,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
669
671
nulls [16 ] = true;
670
672
671
673
/* Values only available to role member or pg_read_all_stats */
672
- if (has_privs_of_role (GetUserId (), beentry -> st_userid ) ||
673
- is_member_of_role (GetUserId (), DEFAULT_ROLE_READ_ALL_STATS ))
674
+ if (HAS_PGSTAT_PERMISSIONS (beentry -> st_userid ))
674
675
{
675
676
SockAddr zero_clientaddr ;
676
677
char * clipped_activity ;
@@ -1007,7 +1008,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
1007
1008
1008
1009
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1009
1010
activity = "<backend information not available>" ;
1010
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1011
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1011
1012
activity = "<insufficient privilege>" ;
1012
1013
else if (* (beentry -> st_activity_raw ) == '\0' )
1013
1014
activity = "<command string not enabled>" ;
@@ -1031,7 +1032,7 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
1031
1032
1032
1033
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1033
1034
wait_event_type = "<backend information not available>" ;
1034
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1035
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1035
1036
wait_event_type = "<insufficient privilege>" ;
1036
1037
else if ((proc = BackendPidGetProc (beentry -> st_procpid )) != NULL )
1037
1038
wait_event_type = pgstat_get_wait_event_type (proc -> wait_event_info );
@@ -1052,7 +1053,7 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
1052
1053
1053
1054
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1054
1055
wait_event = "<backend information not available>" ;
1055
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1056
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1056
1057
wait_event = "<insufficient privilege>" ;
1057
1058
else if ((proc = BackendPidGetProc (beentry -> st_procpid )) != NULL )
1058
1059
wait_event = pgstat_get_wait_event (proc -> wait_event_info );
@@ -1074,7 +1075,7 @@ pg_stat_get_backend_activity_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_activity_start_timestamp ;
@@ -1100,7 +1101,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
1100
1101
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1101
1102
PG_RETURN_NULL ();
1102
1103
1103
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1104
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1104
1105
PG_RETURN_NULL ();
1105
1106
1106
1107
result = beentry -> st_xact_start_timestamp ;
@@ -1122,7 +1123,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
1122
1123
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1123
1124
PG_RETURN_NULL ();
1124
1125
1125
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1126
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1126
1127
PG_RETURN_NULL ();
1127
1128
1128
1129
result = beentry -> st_proc_start_timestamp ;
@@ -1146,7 +1147,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
1146
1147
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1147
1148
PG_RETURN_NULL ();
1148
1149
1149
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1150
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1150
1151
PG_RETURN_NULL ();
1151
1152
1152
1153
/* A zeroed client addr means we don't know */
@@ -1193,7 +1194,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
1193
1194
if ((beentry = pgstat_fetch_stat_beentry (beid )) == NULL )
1194
1195
PG_RETURN_NULL ();
1195
1196
1196
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1197
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1197
1198
PG_RETURN_NULL ();
1198
1199
1199
1200
/* A zeroed client addr means we don't know */
0 commit comments