Skip to content

Commit 25bd499

Browse files
author
Marina Polyakova
committedApr 3, 2024·
Fix build with PostgreSQL 17devel at 7eb9a8201890f3b208fd4c109a5b08bf139b692a
See the following commits in PostgreSQL 17devel: - ab355e3a88de745607f6dd4c21f0119b5c68f2ad Redefine backend ID to be an index into the proc array - 024c521117579a6d356050ad3d78fdc95e44eefa Replace BackendIds with 0-based ProcNumbers
1 parent a5afb51 commit 25bd499

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed
 

Diff for: ‎pg_query_state.c

+45-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ search_be_status(int pid)
365365

366366
for (beid = 1; beid <= pgstat_fetch_stat_numbackends(); beid++)
367367
{
368-
#if PG_VERSION_NUM >= 160000
368+
#if PG_VERSION_NUM >= 170000
369+
PgBackendStatus *be_status = pgstat_get_beentry_by_proc_number(beid);
370+
#elif PG_VERSION_NUM >= 160000
369371
PgBackendStatus *be_status = pgstat_get_beentry_by_backend_id(beid);
370372
#else
371373
PgBackendStatus *be_status = pgstat_fetch_stat_beentry(beid);
@@ -505,7 +507,14 @@ pg_query_state(PG_FUNCTION_ARGS)
505507
errmsg("attempt to extract state of current process")));
506508

507509
proc = BackendPidGetProc(pid);
508-
if (!proc || proc->backendId == InvalidBackendId || proc->databaseId == InvalidOid || proc->roleId == InvalidOid)
510+
if (!proc ||
511+
#if PG_VERSION_NUM >= 170000
512+
proc->vxid.procNumber == INVALID_PROC_NUMBER ||
513+
#else
514+
proc->backendId == InvalidBackendId ||
515+
#endif
516+
proc->databaseId == InvalidOid ||
517+
proc->roleId == InvalidOid)
509518
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
510519
errmsg("backend with pid=%d not found", pid)));
511520

@@ -730,15 +739,25 @@ GetRemoteBackendUserId(PGPROC *proc)
730739
{
731740
Oid result;
732741

742+
#if PG_VERSION_NUM >= 170000
743+
Assert(proc && proc->vxid.procNumber != INVALID_PROC_NUMBER);
744+
#else
733745
Assert(proc && proc->backendId != InvalidBackendId);
746+
#endif
747+
734748
Assert(UserIdPollReason != INVALID_PROCSIGNAL);
735749
Assert(counterpart_userid);
736750

737751
counterpart_userid->userid = InvalidOid;
738752
counterpart_userid->caller = MyLatch;
739753
pg_write_barrier();
740754

755+
#if PG_VERSION_NUM >= 170000
756+
SendProcSignal(proc->pid, UserIdPollReason, proc->vxid.procNumber);
757+
#else
741758
SendProcSignal(proc->pid, UserIdPollReason, proc->backendId);
759+
#endif
760+
742761
for (;;)
743762
{
744763
SpinLockAcquire(&counterpart_userid->mutex);
@@ -926,7 +945,12 @@ GetRemoteBackendWorkers(PGPROC *proc)
926945
List *result = NIL;
927946
LOCKTAG tag;
928947

948+
#if PG_VERSION_NUM >= 170000
949+
Assert(proc && proc->vxid.procNumber != INVALID_PROC_NUMBER);
950+
#else
929951
Assert(proc && proc->backendId != InvalidBackendId);
952+
#endif
953+
930954
Assert(WorkerPollReason != INVALID_PROCSIGNAL);
931955
Assert(mq);
932956

@@ -936,7 +960,12 @@ GetRemoteBackendWorkers(PGPROC *proc)
936960
shm_mq_set_receiver(mq, MyProc);
937961
UnlockShmem(&tag);
938962

963+
#if PG_VERSION_NUM >= 170000
964+
sig_result = SendProcSignal(proc->pid, WorkerPollReason, proc->vxid.procNumber);
965+
#else
939966
sig_result = SendProcSignal(proc->pid, WorkerPollReason, proc->backendId);
967+
#endif
968+
940969
if (sig_result == -1)
941970
goto signal_error;
942971

@@ -1088,9 +1117,16 @@ GetRemoteBackendQueryStates(PGPROC *leader,
10881117
* send signal `QueryStatePollReason` to all processes and define all alive
10891118
* ones
10901119
*/
1120+
#if PG_VERSION_NUM >= 170000
1121+
sig_result = SendProcSignal(leader->pid,
1122+
QueryStatePollReason,
1123+
leader->vxid.procNumber);
1124+
#else
10911125
sig_result = SendProcSignal(leader->pid,
10921126
QueryStatePollReason,
10931127
leader->backendId);
1128+
#endif
1129+
10941130
if (sig_result == -1)
10951131
goto signal_error;
10961132
foreach(iter, pworkers)
@@ -1101,9 +1137,16 @@ GetRemoteBackendQueryStates(PGPROC *leader,
11011137

11021138
pg_atomic_add_fetch_u32(&counterpart_userid->n_peers, 1);
11031139

1140+
#if PG_VERSION_NUM >= 170000
1141+
sig_result = SendProcSignal(proc->pid,
1142+
QueryStatePollReason,
1143+
proc->vxid.procNumber);
1144+
#else
11041145
sig_result = SendProcSignal(proc->pid,
11051146
QueryStatePollReason,
11061147
proc->backendId);
1148+
#endif
1149+
11071150
if (sig_result == -1)
11081151
{
11091152
if (errno != ESRCH)

0 commit comments

Comments
 (0)
Please sign in to comment.