Alexander Lakhin <[email protected]> wrote:

> I've stumbled upon one more issue with this feature:
> CREATE TABLE t (i int PRIMARY KEY);
> REPACK (CONCURRENTLY) t;
> 
> fails for me with sanitizers enabled and
> min_dynamic_shared_memory = '1GB'
> in postgresql.conf as below:
> 2026-04-12 13:23:02.000 UTC [2733633] LOG:  statement: REPACK (CONCURRENTLY) 
> t;
> repack.c:3373:15: runtime error: load of value 240, which is not a valid 
> value for type '_Bool'
>     #0 0x6441f7eba454 in start_repack_decoding_worker 
> .../src/backend/commands/repack.c:3373
>     #1 0x6441f7ebdaad in rebuild_relation 
> .../src/backend/commands/repack.c:1010
>     #2 0x6441f7ebe9a2 in cluster_rel .../src/backend/commands/repack.c:656
>     #3 0x6441f7ebefea in process_single_relation 
> .../src/backend/commands/repack.c:2359
>     #4 0x6441f7ebf870 in ExecRepack .../src/backend/commands/repack.c:296
>     #5 0x6441f886f20e in standard_ProcessUtility 
> .../src/backend/tcop/utility.c:867

I could not reproduce the problem, but noticed that the field is not
initialized correctly. Please confirm that 0001 should fix that.

While working on it, I noticed that one field can be removed from
DecodingWorkerShared - 0002 removes that.

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com

>From c049bbe9b02e4adfbf6ebbea6eaabad900dc67a0 Mon Sep 17 00:00:00 2001
From: Antonin Houska <[email protected]>
Date: Mon, 13 Apr 2026 11:28:57 +0200
Subject: [PATCH 1/2] Add missing initialization.

Backend can check the variable before the worker could have the chance to
initialize it.
---
 src/backend/commands/repack.c | 1 +
 1 file changed, 1 insertion(+)

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);
-- 
2.47.3

>From 35711000d05bdbc2b1faf0e25938976d2b665555 Mon Sep 17 00:00:00 2001
From: Antonin Houska <[email protected]>
Date: Mon, 13 Apr 2026 11:36:41 +0200
Subject: [PATCH 2/2] Remove dsm_seg from DecodingWorkerShared.

The value is only needed by te worker, so there is no need to store it in
shared memory.
---
 src/backend/commands/repack_worker.c   | 5 +++--
 src/include/commands/repack_internal.h | 1 -
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/backend/commands/repack_worker.c b/src/backend/commands/repack_worker.c
index 5bd020e0184..a594d6db25f 100644
--- a/src/backend/commands/repack_worker.c
+++ b/src/backend/commands/repack_worker.c
@@ -51,6 +51,7 @@ static XLogSegNo repack_current_segment = 0;
 static RelFileLocator repacked_rel_locator = {.relNumber = InvalidOid};
 static RelFileLocator repacked_rel_toast_locator = {.relNumber = InvalidOid};
 
+static dsm_segment	*worker_dsm_segment = NULL;
 
 /* REPACK decoding worker entry point */
 void
@@ -78,9 +79,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 +177,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.
-- 
2.47.3

Reply via email to