[PATCH] Fix REPACK decoding worker not cleaned up on FATAL exit

From: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: alvherre(at)kurilemu(dot)de
Subject: [PATCH] Fix REPACK decoding worker not cleaned up on FATAL exit
Date: 2026-05-12 23:26:23
Message-ID: CA+fm-RNoPxL2N7db_A0anMXV_aDu6jWj4PNOPtMtBUAPDPvSXQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

When a REPACK (CONCURRENTLY) session is terminated via
pg_terminate_backend(), the REPACK decoding worker keeps running
indefinitely and holds its temporary replication slot.

To reproduce:

-- Session 1: start a long REPACK
REPACK (CONCURRENTLY) big_table;

-- Session 2: kill it
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE query LIKE '%REPACK%';

-- The slot persists:
SELECT slot_name, active FROM pg_replication_slots;
-- repack_NNNN | t (still active, cannot be dropped)

Root cause:

pg_terminate_backend() causes ereport(FATAL) via ProcDiePending.
FATAL exits bypass PG_FINALLY blocks, so stop_repack_decoding_worker()
is never called. The decoding worker is left running.

Fix:

Register an on_proc_exit callback when the decoding worker starts.
The callback calls TerminateBackgroundWorker() to signal the worker.
We do not wait for the worker to exit in the callback (WaitLatch is
not safe during proc_exit); the worker's RS_TEMPORARY slot is dropped
automatically when the worker process exits.

Thanks,
Baji Shaik
AWS RDS

Attachment Content-Type Size
0001-Fix-REPACK-decoding-worker-not-cleaned-up-on-FATAL-e.patch application/octet-stream 3.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul A Jungwirth 2026-05-13 00:05:03 Re: FOR PORTION OF does not recompute GENERATED STORED columns that depend on the range column
Previous Message Baji Shaik 2026-05-12 23:19:13 [PATCH] Fix errhint messages for REPACK (CONCURRENTLY) restrictions