1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

Replace BackendIds with 0-based ProcNumbers

Now that BackendId was just another index into the proc array, it was
redundant with the 0-based proc numbers used in other places. Replace
all usage of backend IDs with proc numbers.

The only place where the term "backend id" remains is in a few pgstat
functions that expose backend IDs at the SQL level. Those IDs are now
in fact 0-based ProcNumbers too, but the documentation still calls
them "backend ids". That term still seems appropriate to describe what
the numbers are, so I let it be.

One user-visible effect is that pg_temp_0 is now a valid temp schema
name, for backend with ProcNumber 0.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
This commit is contained in:
Heikki Linnakangas
2024-03-03 19:38:22 +02:00
parent ab355e3a88
commit 024c521117
71 changed files with 571 additions and 579 deletions

View File

@@ -306,7 +306,7 @@ pg_tablespace_size_name(PG_FUNCTION_ARGS)
* is no check here or at the call sites for that.
*/
static int64
calculate_relation_size(RelFileLocator *rfn, BackendId backend, ForkNumber forknum)
calculate_relation_size(RelFileLocator *rfn, ProcNumber backend, ForkNumber forknum)
{
int64 totalsize = 0;
char *relationpath;
@@ -951,7 +951,7 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
HeapTuple tuple;
Form_pg_class relform;
RelFileLocator rlocator;
BackendId backend;
ProcNumber backend;
char *path;
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
@@ -996,21 +996,21 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
{
case RELPERSISTENCE_UNLOGGED:
case RELPERSISTENCE_PERMANENT:
backend = InvalidBackendId;
backend = INVALID_PROC_NUMBER;
break;
case RELPERSISTENCE_TEMP:
if (isTempOrTempToastNamespace(relform->relnamespace))
backend = BackendIdForTempRelations();
backend = ProcNumberForTempRelations();
else
{
/* Do it the hard way. */
backend = GetTempNamespaceBackendId(relform->relnamespace);
Assert(backend != InvalidBackendId);
backend = GetTempNamespaceProcNumber(relform->relnamespace);
Assert(backend != INVALID_PROC_NUMBER);
}
break;
default:
elog(ERROR, "invalid relpersistence: %c", relform->relpersistence);
backend = InvalidBackendId; /* placate compiler */
backend = INVALID_PROC_NUMBER; /* placate compiler */
break;
}

View File

@@ -73,15 +73,16 @@ typedef struct
* This is currently only used in pg_lock_status, so we put it here.
*/
static Datum
VXIDGetDatum(BackendId bid, LocalTransactionId lxid)
VXIDGetDatum(ProcNumber procNumber, LocalTransactionId lxid)
{
/*
* The representation is "<bid>/<lxid>", decimal and unsigned decimal
* respectively. Note that elog.c also knows how to format a vxid.
* The representation is "<procNumber>/<lxid>", decimal and unsigned
* decimal respectively. Note that elog.c also knows how to format a
* vxid.
*/
char vxidstr[32];
snprintf(vxidstr, sizeof(vxidstr), "%d/%u", bid, lxid);
snprintf(vxidstr, sizeof(vxidstr), "%d/%u", procNumber, lxid);
return CStringGetTextDatum(vxidstr);
}
@@ -353,7 +354,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
break;
}
values[10] = VXIDGetDatum(instance->vxid.backendId, instance->vxid.localTransactionId);
values[10] = VXIDGetDatum(instance->vxid.procNumber, instance->vxid.localTransactionId);
if (instance->pid != 0)
values[11] = Int32GetDatum(instance->pid);
else
@@ -419,7 +420,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
nulls[9] = true; /* objsubid */
/* lock holder */
values[10] = VXIDGetDatum(xact->vxid.backendId,
values[10] = VXIDGetDatum(xact->vxid.procNumber,
xact->vxid.localTransactionId);
if (xact->pid != 0)
values[11] = Int32GetDatum(xact->pid);

View File

@@ -146,7 +146,7 @@ pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
{
int pid = PG_GETARG_INT32(0);
PGPROC *proc;
BackendId backendId = InvalidBackendId;
ProcNumber procNumber = INVALID_PROC_NUMBER;
/*
* See if the process with given pid is a backend or an auxiliary process.
@@ -175,9 +175,8 @@ pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(false);
}
if (proc != NULL)
backendId = GetBackendIdFromPGProc(proc);
if (SendProcSignal(pid, PROCSIG_LOG_MEMORY_CONTEXT, backendId) < 0)
procNumber = GetNumberFromPGProc(proc);
if (SendProcSignal(pid, PROCSIG_LOG_MEMORY_CONTEXT, procNumber) < 0)
{
/* Again, just a warning to allow loops */
ereport(WARNING,

View File

@@ -213,7 +213,7 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
/* do when there is more left to send */
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->proc_number));
}
else
{
@@ -669,10 +669,10 @@ pg_backend_pid(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
PG_RETURN_INT32(beentry->st_procpid);
@@ -682,10 +682,10 @@ pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
PG_RETURN_OID(beentry->st_databaseid);
@@ -695,10 +695,10 @@ pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
PG_RETURN_OID(beentry->st_userid);
@@ -711,7 +711,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
TupleDesc tupdesc;
Datum values[PG_STAT_GET_SUBXACT_COLS] = {0};
bool nulls[PG_STAT_GET_SUBXACT_COLS] = {0};
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
LocalPgBackendStatus *local_beentry;
/* Initialise attributes information in the tuple descriptor */
@@ -723,7 +723,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
BlessTupleDesc(tupdesc);
if ((local_beentry = pgstat_get_local_beentry_by_backend_id(beid)) != NULL)
if ((local_beentry = pgstat_get_local_beentry_by_proc_number(procNumber)) != NULL)
{
/* Fill values and NULLs */
values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
@@ -742,13 +742,13 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
const char *activity;
char *clipped_activity;
text *ret;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
activity = "<backend information not available>";
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
activity = "<insufficient privilege>";
@@ -767,12 +767,12 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type = NULL;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
wait_event_type = "<backend information not available>";
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
wait_event_type = "<insufficient privilege>";
@@ -788,12 +788,12 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event = NULL;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
wait_event = "<backend information not available>";
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
wait_event = "<insufficient privilege>";
@@ -810,11 +810,11 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -836,11 +836,11 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -858,11 +858,11 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_start(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
TimestampTz result;
PgBackendStatus *beentry;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -880,13 +880,13 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_host[NI_MAXHOST];
int ret;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -925,13 +925,13 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
Datum
pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_port[NI_MAXSERV];
int ret;
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
if ((beentry = pgstat_get_beentry_by_proc_number(procNumber)) == NULL)
PG_RETURN_NULL();
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))