31
31
32
32
#define UINT32_ACCESS_ONCE (var ) ((uint32)(*((volatile uint32 *)&(var))))
33
33
34
+ #define HAS_PGSTAT_PERMISSIONS (role ) (is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS) || has_privs_of_role(GetUserId(), role))
35
+
34
36
/* Global bgwriter statistics, from bgwriter.c */
35
37
extern PgStat_MsgBgWriter bgwriterStats ;
36
38
@@ -512,7 +514,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
512
514
values [1 ]= ObjectIdGetDatum (beentry -> st_databaseid );
513
515
514
516
/* show rest of the values including relid only to role members */
515
- if (has_privs_of_role ( GetUserId (), beentry -> st_userid ))
517
+ if (HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
516
518
{
517
519
values [2 ]= ObjectIdGetDatum (beentry -> st_progress_command_target );
518
520
for (i = 0 ;i < PGSTAT_NUM_PROGRESS_PARAM ;i ++ )
@@ -660,8 +662,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
660
662
}
661
663
662
664
/* Values only available to role member or pg_read_all_stats */
663
- if (has_privs_of_role (GetUserId (),beentry -> st_userid )||
664
- is_member_of_role (GetUserId (),DEFAULT_ROLE_READ_ALL_STATS ))
665
+ if (HAS_PGSTAT_PERMISSIONS (beentry -> st_userid ))
665
666
{
666
667
SockAddr zero_clientaddr ;
667
668
@@ -915,7 +916,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
915
916
916
917
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
917
918
activity = "<backend information not available>" ;
918
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
919
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
919
920
activity = "<insufficient privilege>" ;
920
921
else if (* (beentry -> st_activity )== '\0' )
921
922
activity = "<command string not enabled>" ;
@@ -935,7 +936,7 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
935
936
936
937
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
937
938
wait_event_type = "<backend information not available>" ;
938
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
939
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
939
940
wait_event_type = "<insufficient privilege>" ;
940
941
else if ((proc = BackendPidGetProc (beentry -> st_procpid ))!= NULL )
941
942
wait_event_type = pgstat_get_wait_event_type (proc -> wait_event_info );
@@ -956,7 +957,7 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
956
957
957
958
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
958
959
wait_event = "<backend information not available>" ;
959
- else if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
960
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
960
961
wait_event = "<insufficient privilege>" ;
961
962
else if ((proc = BackendPidGetProc (beentry -> st_procpid ))!= NULL )
962
963
wait_event = pgstat_get_wait_event (proc -> wait_event_info );
@@ -978,7 +979,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
978
979
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
979
980
PG_RETURN_NULL ();
980
981
981
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
982
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
982
983
PG_RETURN_NULL ();
983
984
984
985
result = beentry -> st_activity_start_timestamp ;
@@ -1004,7 +1005,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
1004
1005
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
1005
1006
PG_RETURN_NULL ();
1006
1007
1007
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1008
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1008
1009
PG_RETURN_NULL ();
1009
1010
1010
1011
result = beentry -> st_xact_start_timestamp ;
@@ -1026,7 +1027,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
1026
1027
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
1027
1028
PG_RETURN_NULL ();
1028
1029
1029
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1030
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1030
1031
PG_RETURN_NULL ();
1031
1032
1032
1033
result = beentry -> st_proc_start_timestamp ;
@@ -1050,7 +1051,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
1050
1051
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
1051
1052
PG_RETURN_NULL ();
1052
1053
1053
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1054
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1054
1055
PG_RETURN_NULL ();
1055
1056
1056
1057
/* A zeroed client addr means we don't know */
@@ -1097,7 +1098,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
1097
1098
if ((beentry = pgstat_fetch_stat_beentry (beid ))== NULL )
1098
1099
PG_RETURN_NULL ();
1099
1100
1100
- if (!has_privs_of_role ( GetUserId (), beentry -> st_userid ))
1101
+ else if (!HAS_PGSTAT_PERMISSIONS ( beentry -> st_userid ))
1101
1102
PG_RETURN_NULL ();
1102
1103
1103
1104
/* A zeroed client addr means we don't know */