Re: Add REPACK progress phases for logical decoding setup

From: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add REPACK progress phases for logical decoding setup
Date: 2026-09-22 21:20:30
Message-ID: CAN12+YK4RfLhR2WRohSe1XH2q5x25M6iFYYaq6+o7sYwk1u+Kw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you both for the review!

> > 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.
>
> Right, these steps could take a time. Please note that if there is one
> logical slot or wal_level is set to 'logical', (1) is no-op.

Good point. I added a point about effective_wal_level in the docs.

> >
> > 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.
>
> While it's true that the logical decoding might need to read WAL
> records until the snapshot reaches a consistent state, I'm not sure
> that it can justify having its own phase. I think we can merge it to
> (2) and have something like a "initializing logical decoding" phase.

Sure. I also was not sure about this one. So I went ahead and
put it under the "initializing logical decoding" step.

> I've not looked at the patch in depth yet but I agree with the general
> idea. Just to be clear, I think adding new phases would be a v20 item
> rather than an open item for v19. For v19, we can revise the
> documentation part only.

Agreed, so I split it that way.

v2-0001 is documentation only and is what I propose for the v19 open
item. It adds more documentation about the "initializing" and "catch-up"
phases for the steps that could be unbounded. It covers enabling logical
decoding and initializing logical decoding, and the ACCESS EXCLUSIVE lock
that is taken to perform the swap in the "catch-up" phase.

v2-0002 is for v20 and adds only the "enabling logical decoding" and
"initializing logical decoding" phases, moving the descriptions above into
their own rows. It needs a catversion bump, which is not included.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v2-0002-Add-REPACK-progress-phases-for-logical-decoding-s.patch application/octet-stream 10.9 KB
v2-0001-doc-Improve-REPACK-phase-documentation-for-long-o.patch application/octet-stream 2.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2026-09-22 21:21:25 Re: proposal: add new dblink function, dblink_wait_for_query()
Previous Message Bharath Rupireddy 2026-09-22 21:12:11 Re: Teach pg_upgrade to deal with invalid databases