1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Have the REPACK decoding worker use timeout values from the steering backend

The worker connects as the table owner in a new session, so a role- or
database-level lock_timeout and transaction_timeout unhelpfully apply to
it, possibly canceling the wait for older transactions.  This cannot be
overridden by the REPACK calling session.  Fix by passing the timeout
values from the steering backend via the DecodingWorkerShared struct and
adopting these values in the worker; this way, values from session-local
SET reach the worker too.

In passing, remove a pointless member from the same struct.

Author: Shihao Zhong <zhong950419@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CAGRkXqTYaBjFvjtjPb1+=sZWvt93=2c472bmM+xdG7w9ZvAydA@mail.gmail.com
This commit is contained in:
Álvaro Herrera
2026-09-17 12:46:43 +02:00
parent fc29deb521
commit 746a507a39
3 changed files with 18 additions and 3 deletions

View File

@@ -3769,10 +3769,13 @@ start_repack_decoding_worker(Oid relid)
shared->roleid = GetUserId();
shared->relid = relid;
ConditionVariableInit(&shared->cv);
shared->backend_proc = MyProc;
shared->backend_pid = MyProcPid;
shared->backend_proc_number = MyProcNumber;
/* Transmit our timeouts to the worker too */
shared->lock_timeout = LockTimeout;
shared->transaction_timeout = TransactionTimeout;
mq = shm_mq_create((char *) BUFFERALIGN(shared->error_queue),
REPACK_ERROR_QUEUE_SIZE);
shm_mq_set_receiver(mq, MyProc);

View File

@@ -27,6 +27,7 @@
#include "storage/ipc.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#define PGREPACK_PLUGIN "pgrepack"
@@ -64,6 +65,7 @@ RepackWorkerMain(Datum main_arg)
LogicalDecodingContext *decoding_ctx;
SharedFileSet *sfs;
Snapshot snapshot;
char buf[32];
am_repack_worker = true;
@@ -84,7 +86,8 @@ RepackWorkerMain(Datum main_arg)
* Join locking group - see the comments around the call of
* start_repack_decoding_worker().
*/
if (!BecomeLockGroupMember(shared->backend_proc, shared->backend_pid))
if (!BecomeLockGroupMember(GetPGProcByNumber(shared->backend_proc_number),
shared->backend_pid))
return; /* The leader is not running anymore. */
/*
@@ -108,6 +111,12 @@ RepackWorkerMain(Datum main_arg)
BGWORKER_BYPASS_ALLOWCONN |
BGWORKER_BYPASS_ROLELOGINCHECK);
/* Adopt the steering backend's relevant timeouts. */
snprintf(buf, sizeof(buf), "%d", shared->lock_timeout);
SetConfigOption("lock_timeout", buf, PGC_SUSET, PGC_S_OVERRIDE);
snprintf(buf, sizeof(buf), "%d", shared->transaction_timeout);
SetConfigOption("transaction_timeout", buf, PGC_SUSET, PGC_S_OVERRIDE);
/*
* Transaction is needed to open relation, and it also provides us with a
* resource owner.

View File

@@ -95,6 +95,10 @@ typedef struct DecodingWorkerShared
/* Role to connect as. */
Oid roleid;
/* Timeouts to use in the worker */
int lock_timeout;
int transaction_timeout;
/* Relation from which data changes to decode. */
Oid relid;
@@ -102,7 +106,6 @@ typedef struct DecodingWorkerShared
ConditionVariable cv;
/* Info to signal the backend. */
PGPROC *backend_proc;
pid_t backend_pid;
ProcNumber backend_proc_number;