Add REPACK progress phases for logical decoding setup

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add REPACK progress phases for logical decoding setup
Date: 2026-09-18 21:19:20
Message-ID: CAN12+YJOeOyPYB5JS28VE_+rzg=RbzQXfj58TGfMYwv-TX9mJA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While stress testing REPACK (CONCURRENTLY), I noticed that the current
"initializing" phase contains multiple operations that can wait indefinitely.
The transaction wait can be prolonged by long-running or prepared
transactions, or by another REPACK (CONCURRENTLY) operation that already has
an XID. Describing the whole phase as "expected to be very brief" [1] is
misleading.

To make these waits visible and distinguish the work immediately before and
after the old transaction wait, three progress phases between
"initializing" and
the heap scan should be added.

1/ enabling logical decoding

When wal_level is logical, or logical decoding is already enabled, this phase
is effectively instantaneous. Otherwise, REPACK waits for every running
process to acknowledge a ProcSignalBarrier. This normally finishes quickly,
but the barrier has no timeout and can take longer if a process does not
respond promptly.

2/ waiting for old transactions

The snapshot builder waits for transactions with assigned XIDs to finish
before it can reach a consistent point.

3/ building initial snapshot

REPACK obtains the initial snapshot from the decoding worker and prepares to
start copying the table. This separates the end of the transaction wait
from the start of the heap scan.

This gives the following sequence:

initializing (default, expected to be brief)
enabling logical decoding
waiting for old transactions
building initial snapshot
seq scanning heap / index scanning heap

The attached patch has the worker publish its setup stage through shared
memory and signal the existing condition variable.

Thoughts?

[1] https://www.postgresql.org/docs/19/progress-reporting.html

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v1-0001-Add-REPACK-progress-phases-for-logical-decoding-s.patch application/octet-stream 14.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2026-09-18 21:39:36 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Previous Message Okanovic, Haris 2026-09-18 21:11:30 Re: [PATCH] Reduce LWLockWaitListLock() cache-line contention with adaptive spin reads