From: Álvaro Herrera Date: Thu, 16 Apr 2026 20:27:04 +0000 (+0200) Subject: Add missing initialization X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=05c401d5786a05ea630e884ffa492aa01683d15b;p=thirdparty%2Fpostgresql.git Add missing initialization The backend running REPACK can check DecodingWorkerShared->initialized before the worker could have the chance to initialize it, possibly leading to wrong behavior. While at it, remove DecodingWorkerShared->worker_dsm_segment, because that doesn't actually need to be in shared memory; a simple local-memory global variable is enough. Oversights in commit 28d534e2ae0a. Author: Antonin Houska Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/18181295-8375-4789-ad32-269d78d6001e@gmail.com --- diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index 58e3867246f..67364cc60e3 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -3311,6 +3311,7 @@ start_repack_decoding_worker(Oid relid) BUFFERALIGN(REPACK_ERROR_QUEUE_SIZE); seg = dsm_create(size, 0); shared = (DecodingWorkerShared *) dsm_segment_address(seg); + shared->initialized = false; shared->lsn_upto = InvalidXLogRecPtr; shared->done = false; SharedFileSetInit(&shared->sfs, seg); diff --git a/src/backend/commands/repack_worker.c b/src/backend/commands/repack_worker.c index 362e0766c41..b17edd771e2 100644 --- a/src/backend/commands/repack_worker.c +++ b/src/backend/commands/repack_worker.c @@ -44,6 +44,9 @@ static bool am_repack_worker = false; /* The WAL segment being decoded. */ static XLogSegNo repack_current_segment = 0; +/* Our DSM segment, for shutting down */ +static dsm_segment *worker_dsm_segment = NULL; + /* * Keep track of the table we're processing, to skip logical decoding of data * from other relations. @@ -78,9 +81,9 @@ RepackWorkerMain(Datum main_arg) ereport(ERROR, errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not map dynamic shared memory segment")); + worker_dsm_segment = seg; shared = (DecodingWorkerShared *) dsm_segment_address(seg); - shared->dsm_seg = seg; /* Arrange to signal the leader if we exit. */ before_shmem_exit(RepackWorkerShutdown, PointerGetDatum(shared)); @@ -176,7 +179,7 @@ RepackWorkerShutdown(int code, Datum arg) PROCSIG_REPACK_MESSAGE, shared->backend_proc_number); - dsm_detach(shared->dsm_seg); + dsm_detach(worker_dsm_segment); } bool diff --git a/src/include/commands/repack_internal.h b/src/include/commands/repack_internal.h index 3ff64444351..6a85cee8910 100644 --- a/src/include/commands/repack_internal.h +++ b/src/include/commands/repack_internal.h @@ -107,7 +107,6 @@ typedef struct DecodingWorkerShared PGPROC *backend_proc; pid_t backend_pid; ProcNumber backend_proc_number; - dsm_segment *dsm_seg; /* * Memory the queue is located in.