Rename some support functions for pgstat* views.
Presently, pgstat_fetch_stat_beentry() accepts a session's backend
ID as its argument, and pgstat_fetch_stat_local_beentry() accepts a
1-based index in an internal array as its argument. The former is
typically used wherever a user must provide a backend ID, and the
latter is usually used internally when looping over all entries in
the array. This difference was first introduced by d7e39d72ca
.
Before that commit, both functions accepted a 1-based index to the
internal array.
This commit renames these two functions to make it clear whether
they use the backend ID or the 1-based index to look up the entry.
This is preparatory work for a follow-up change that will introduce
a function for looking up a LocalPgBackendStatus using a backend
ID.
Reviewed-by: Ian Barwick, Sami Imseih, Michael Paquier, Robert Haas
Discussion: https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.com
Backpatch-through: 16
This commit is contained in:
parent
fe39f43352
commit
3d51cb5197
|
@ -849,8 +849,8 @@ pgstat_read_current_status(void)
|
||||||
/*
|
/*
|
||||||
* The BackendStatusArray index is exactly the BackendId of the
|
* The BackendStatusArray index is exactly the BackendId of the
|
||||||
* source backend. Note that this means localBackendStatusTable
|
* source backend. Note that this means localBackendStatusTable
|
||||||
* is in order by backend_id. pgstat_fetch_stat_beentry() depends
|
* is in order by backend_id. pgstat_get_beentry_by_backend_id()
|
||||||
* on that.
|
* depends on that.
|
||||||
*/
|
*/
|
||||||
localentry->backend_id = i;
|
localentry->backend_id = i;
|
||||||
BackendIdGetTransactionIds(i,
|
BackendIdGetTransactionIds(i,
|
||||||
|
@ -1073,21 +1073,21 @@ cmp_lbestatus(const void *a, const void *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
* pgstat_fetch_stat_beentry() -
|
* pgstat_get_beentry_by_backend_id() -
|
||||||
*
|
*
|
||||||
* Support function for the SQL-callable pgstat* functions. Returns
|
* Support function for the SQL-callable pgstat* functions. Returns
|
||||||
* our local copy of the current-activity entry for one backend,
|
* our local copy of the current-activity entry for one backend,
|
||||||
* or NULL if the given beid doesn't identify any known session.
|
* or NULL if the given beid doesn't identify any known session.
|
||||||
*
|
*
|
||||||
* The beid argument is the BackendId of the desired session
|
* The beid argument is the BackendId of the desired session
|
||||||
* (note that this is unlike pgstat_fetch_stat_local_beentry()).
|
* (note that this is unlike pgstat_get_local_beentry_by_index()).
|
||||||
*
|
*
|
||||||
* NB: caller is responsible for a check if the user is permitted to see
|
* NB: caller is responsible for a check if the user is permitted to see
|
||||||
* this info (especially the querystring).
|
* this info (especially the querystring).
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
PgBackendStatus *
|
PgBackendStatus *
|
||||||
pgstat_fetch_stat_beentry(BackendId beid)
|
pgstat_get_beentry_by_backend_id(BackendId beid)
|
||||||
{
|
{
|
||||||
LocalPgBackendStatus key;
|
LocalPgBackendStatus key;
|
||||||
LocalPgBackendStatus *ret;
|
LocalPgBackendStatus *ret;
|
||||||
|
@ -1111,13 +1111,13 @@ pgstat_fetch_stat_beentry(BackendId beid)
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
* pgstat_fetch_stat_local_beentry() -
|
* pgstat_get_local_beentry_by_index() -
|
||||||
*
|
*
|
||||||
* Like pgstat_fetch_stat_beentry() but with locally computed additions (like
|
* Like pgstat_get_beentry_by_backend_id() but with locally computed additions
|
||||||
* xid and xmin values of the backend)
|
* (like xid and xmin values of the backend)
|
||||||
*
|
*
|
||||||
* The beid argument is a 1-based index in the localBackendStatusTable
|
* The idx argument is a 1-based index in the localBackendStatusTable
|
||||||
* (note that this is unlike pgstat_fetch_stat_beentry()).
|
* (note that this is unlike pgstat_get_beentry_by_backend_id()).
|
||||||
* Returns NULL if the argument is out of range (no current caller does that).
|
* Returns NULL if the argument is out of range (no current caller does that).
|
||||||
*
|
*
|
||||||
* NB: caller is responsible for a check if the user is permitted to see
|
* NB: caller is responsible for a check if the user is permitted to see
|
||||||
|
@ -1125,14 +1125,14 @@ pgstat_fetch_stat_beentry(BackendId beid)
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
LocalPgBackendStatus *
|
LocalPgBackendStatus *
|
||||||
pgstat_fetch_stat_local_beentry(int beid)
|
pgstat_get_local_beentry_by_index(int idx)
|
||||||
{
|
{
|
||||||
pgstat_read_current_status();
|
pgstat_read_current_status();
|
||||||
|
|
||||||
if (beid < 1 || beid > localNumBackends)
|
if (idx < 1 || idx > localNumBackends)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return &localBackendStatusTable[beid - 1];
|
return &localBackendStatusTable[idx - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1141,7 +1141,7 @@ pgstat_fetch_stat_local_beentry(int beid)
|
||||||
*
|
*
|
||||||
* Support function for the SQL-callable pgstat* functions. Returns
|
* Support function for the SQL-callable pgstat* functions. Returns
|
||||||
* the number of sessions known in the localBackendStatusTable, i.e.
|
* the number of sessions known in the localBackendStatusTable, i.e.
|
||||||
* the maximum 1-based index to pass to pgstat_fetch_stat_local_beentry().
|
* the maximum 1-based index to pass to pgstat_get_local_beentry_by_index().
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
|
|
|
@ -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 beid;
|
int idx;
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
for (beid = 1; beid <= tot_backends; beid++)
|
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++;
|
||||||
|
|
|
@ -333,8 +333,8 @@ extern uint64 pgstat_get_my_query_id(void);
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
extern int pgstat_fetch_stat_numbackends(void);
|
extern int pgstat_fetch_stat_numbackends(void);
|
||||||
extern PgBackendStatus *pgstat_fetch_stat_beentry(BackendId beid);
|
extern PgBackendStatus *pgstat_get_beentry_by_backend_id(BackendId beid);
|
||||||
extern LocalPgBackendStatus *pgstat_fetch_stat_local_beentry(int beid);
|
extern LocalPgBackendStatus *pgstat_get_local_beentry_by_index(int idx);
|
||||||
extern char *pgstat_clip_activity(const char *raw_activity);
|
extern char *pgstat_clip_activity(const char *raw_activity);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue