@ -211,7 +211,7 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
if ( fctx [ 0 ] < = pgstat_fetch_stat_numbackends ( ) )
if ( fctx [ 0 ] < = pgstat_fetch_stat_numbackends ( ) )
{
{
/* do when there is more left to send */
/* do when there is more left to send */
LocalPgBackendStatus * local_beentry = pgstat_fetch_stat_local_beentry ( fctx [ 0 ] ) ;
LocalPgBackendStatus * local_beentry = pgstat_get_local_beentry_by_index ( fctx [ 0 ] ) ;
SRF_RETURN_NEXT ( funcctx , Int32GetDatum ( local_beentry - > backend_id ) ) ;
SRF_RETURN_NEXT ( funcctx , Int32GetDatum ( local_beentry - > backend_id ) ) ;
}
}
@ -264,7 +264,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
bool nulls [ PG_STAT_GET_PROGRESS_COLS ] = { 0 } ;
bool nulls [ PG_STAT_GET_PROGRESS_COLS ] = { 0 } ;
int i ;
int i ;
local_beentry = pgstat_fetch_stat_local_beentry ( curr_backend ) ;
local_beentry = pgstat_get_local_beentry_by_index ( curr_backend ) ;
beentry = & local_beentry - > backendStatus ;
beentry = & local_beentry - > backendStatus ;
/*
/*
@ -325,7 +325,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
const char * wait_event = NULL ;
const char * wait_event = NULL ;
/* Get the next one in the list */
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry ( curr_backend ) ;
local_beentry = pgstat_get_local_beentry_by_index ( curr_backend ) ;
beentry = & local_beentry - > backendStatus ;
beentry = & local_beentry - > backendStatus ;
/* If looking for specific PID, ignore all the others */
/* If looking for specific PID, ignore all the others */
@ -672,7 +672,7 @@ pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
int32 beid = PG_GETARG_INT32 ( 0 ) ;
int32 beid = PG_GETARG_INT32 ( 0 ) ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
PG_RETURN_INT32 ( beentry - > st_procpid ) ;
PG_RETURN_INT32 ( beentry - > st_procpid ) ;
@ -685,7 +685,7 @@ pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
int32 beid = PG_GETARG_INT32 ( 0 ) ;
int32 beid = PG_GETARG_INT32 ( 0 ) ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
PG_RETURN_OID ( beentry - > st_databaseid ) ;
PG_RETURN_OID ( beentry - > st_databaseid ) ;
@ -698,7 +698,7 @@ pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
int32 beid = PG_GETARG_INT32 ( 0 ) ;
int32 beid = PG_GETARG_INT32 ( 0 ) ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
PG_RETURN_OID ( beentry - > st_userid ) ;
PG_RETURN_OID ( beentry - > st_userid ) ;
@ -727,7 +727,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
BlessTupleDesc ( tupdesc ) ;
BlessTupleDesc ( tupdesc ) ;
if ( ( local_beentry = pgstat_fetch_stat_local_beentry ( beid ) ) ! = NULL )
if ( ( local_beentry = pgstat_get_local_beentry_by_index ( beid ) ) ! = NULL )
{
{
/* Fill values and NULLs */
/* Fill values and NULLs */
values [ 0 ] = Int32GetDatum ( local_beentry - > backend_subxact_count ) ;
values [ 0 ] = Int32GetDatum ( local_beentry - > backend_subxact_count ) ;
@ -752,7 +752,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
char * clipped_activity ;
char * clipped_activity ;
text * ret ;
text * ret ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
activity = " <backend information not available> " ;
activity = " <backend information not available> " ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
activity = " <insufficient privilege> " ;
activity = " <insufficient privilege> " ;
@ -776,7 +776,7 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
PGPROC * proc ;
PGPROC * proc ;
const char * wait_event_type = NULL ;
const char * wait_event_type = NULL ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
wait_event_type = " <backend information not available> " ;
wait_event_type = " <backend information not available> " ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
wait_event_type = " <insufficient privilege> " ;
wait_event_type = " <insufficient privilege> " ;
@ -797,7 +797,7 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
PGPROC * proc ;
PGPROC * proc ;
const char * wait_event = NULL ;
const char * wait_event = NULL ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
wait_event = " <backend information not available> " ;
wait_event = " <backend information not available> " ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
wait_event = " <insufficient privilege> " ;
wait_event = " <insufficient privilege> " ;
@ -818,7 +818,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
TimestampTz result ;
TimestampTz result ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
@ -844,7 +844,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
TimestampTz result ;
TimestampTz result ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
@ -866,7 +866,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
TimestampTz result ;
TimestampTz result ;
PgBackendStatus * beentry ;
PgBackendStatus * beentry ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
@ -890,7 +890,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
char remote_host [ NI_MAXHOST ] ;
char remote_host [ NI_MAXHOST ] ;
int ret ;
int ret ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
@ -935,7 +935,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
char remote_port [ NI_MAXSERV ] ;
char remote_port [ NI_MAXSERV ] ;
int ret ;
int ret ;
if ( ( beentry = pgstat_fetch_stat_beentry ( beid ) ) = = NULL )
if ( ( beentry = pgstat_get_beentry_by_backend_id ( beid ) ) = = NULL )
PG_RETURN_NULL ( ) ;
PG_RETURN_NULL ( ) ;
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
else if ( ! HAS_PGSTAT_PERMISSIONS ( beentry - > st_userid ) )
@ -978,12 +978,12 @@ pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
Oid dbid = PG_GETARG_OID ( 0 ) ;
Oid dbid = PG_GETARG_OID ( 0 ) ;
int32 result ;
int32 result ;
int tot_backends = pgstat_fetch_stat_numbackends ( ) ;
int tot_backends = pgstat_fetch_stat_numbackends ( ) ;
int be id;
int idx ;
result = 0 ;
result = 0 ;
for ( be id = 1 ; be id < = tot_backends ; be id+ + )
for ( idx = 1 ; idx < = tot_backends ; idx + + )
{
{
LocalPgBackendStatus * local_beentry = pgstat_fetch_stat_local_beentry ( beid ) ;
LocalPgBackendStatus * local_beentry = pgstat_get_local_beentry_by_index ( idx ) ;
if ( local_beentry - > backendStatus . st_databaseid = = dbid )
if ( local_beentry - > backendStatus . st_databaseid = = dbid )
result + + ;
result + + ;