postgres.git / summary / log / commit / refs

commit    a62ff0829d6b151a7107f6ae7f7f90b52405a247
Author:   Álvaro Herrera <alvherre@kurilemu.de>
Date:     Thu Sep 17 10:46:43 2026 +0000
First released in: 19.0

    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


src/backend/commands/repack.c | 5 ++++- src/backend/commands/repack_worker.c | 11 ++++++++++- src/include/commands/repack_internal.h | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index 9ef0dfb40b7..759be53d6b8 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -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); diff --git a/src/backend/commands/repack_worker.c b/src/backend/commands/repack_worker.c index f51a896ebd9..690863c6411 100644 --- a/src/backend/commands/repack_worker.c +++ b/src/backend/commands/repack_worker.c @@ -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. diff --git a/src/include/commands/repack_internal.h b/src/include/commands/repack_internal.h index 42111aa4ae3..ec6e31d77f2 100644 --- a/src/include/commands/repack_internal.h +++ b/src/include/commands/repack_internal.h @@ -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;