Re: Document prepared transaction lock waits with two_phase subscriptions

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "amit(dot)kapila16(at)gmail(dot)com" <amit(dot)kapila16(at)gmail(dot)com>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Subject: Re: Document prepared transaction lock waits with two_phase subscriptions
Date: 2026-11-16 13:44:57
Message-ID: avsI2UmGU6U8TQlF@bdtpg
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Nov 16, 2026 at 08:20:45PM +0800, Zhijie Hou wrote:
> On Mon, Nov16, 2026 at 05:36 PM Bertrand Drouvot wrote:
> >
> > === 1
> >
> > I wonder if it would also be worth mentioning a nonzero lock_timeout
> > as a possible mitigation too?
>
> Before adding this, I'd like to confirm what would be a good way to suggest
> users configure lock_timeout here. Setting lock_timeout globally (or at the
> database level) would also apply to the logical replication apply worker
> itself (potentially causing it to error out on normal lock waits). On the
> other hand, setting it per session/transaction before running commands that
> take conflicting locks (such as TRUNCATE, ALTER TABLE, LOCK, etc.) avoids
> that, though there are many commands that can take conflicting locks so
> users would need to remember to set it whenever running them (or set it per
> role for administrative sessions). Do you have per-session usage in mind, or
> another way of using lock_timeout?

I had per-session/transaction usage in mind, before executing commands that might
request conflicting table locks. A per role setting also makes sense when a
dedicated role is used for administrative commands. I agree that we should not
recommend setting it globally or at the database level, as that would also affect
the apply workers.

What about juse one sentence, something like?

"
Using a nonzero lock_timeout in sessions or transactions that might request such
conflicting locks can prevent them from waiting indefinitely.
"

> Thanks 2, 3 and 4 look good to me and addressed in V2.

Thanks!

> > Another options I could see (because the doc changes explain the
> > workarounds) would be to help diagnose:
> >
> > 1/ improve log_lock_waits to identify a prepared transaction holding a
> > lock by its XID, instead of reporting it as process 0.
> >
> > 2/ improve the existing pg_locks example query so that it identifies
> > locks held by both newly prepared and recovered prepared transactions.
> >
> > Thoughts?
>
> Both sound like useful diagnostic improvements for prepared transactions in
> general (even outside logical replication), so +1 for discussing them in a
> separate thread.

Thanks for confirming, I'll open a dedicated thread.

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikhil Sontakke 2026-11-16 13:53:31 Re: Dropping a composite attribute causes data integrity violations
Previous Message Tomas Vondra 2026-11-16 13:43:56 Re: reconsider_full_join_clause fails to consider if COALESCE() arguments are NULL-preserving