pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vitaly Davydov <v.davydov@postgrespro.ru>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Deadlock detector fails to activate on a hot standby replica
Date: Fri, 12 Jun 2026 09:00:43 +0300
Message-ID: <b8f9bf41-8afa-46f5-9718-dc096bd666c0@postgrespro.ru> (raw)
In-Reply-To: <CAHGQGwFED52rRVb_a=bVSdbOA=oARVOUyw381GC_6uKoNWJAtQ@mail.gmail.com>
References: <44c24dcf-5710-410f-b1b6-d10b315f3d51@postgrespro.ru>
	<b178ea8d-9ed9-48b3-b4f7-5cfc3ff6ee44@postgrespro.ru>
	<CAHGQGwExVv1-mtPEX-JFGBXNY2r8DfP+sQVPD8GpDTefW0KdsQ@mail.gmail.com>
	<25cba756-9459-4811-aeaf-4a8715735c82@postgrespro.ru>
	<CAHGQGwFCqEkeaoUKHPJ5kpGjrKrJ5nzqE6NqjT-Rz3S6Zg7fug@mail.gmail.com>
	<CAHGQGwGNfwDH4hF_LnXzjnUd3d8+PF=f3dRbNn9XkL1hFbvRRQ@mail.gmail.com>
	<12324a50-95d3-4de4-bd89-b295924b35bb@postgrespro.ru>
	<CAHGQGwFED52rRVb_a=bVSdbOA=oARVOUyw381GC_6uKoNWJAtQ@mail.gmail.com>

Dear Fujii Masao,

On 6/10/26 11:42, Fujii Masao wrote:
 > Could you review the v4 patches?

I've got the issue with BM_PIN_COUNT_WAITER. The origin of the issue is that
the other backend resets the flag before sending the notification (signal)
to the waiter. I agree with your changes where this flag is set again.

I would like to propose BufferIsReadyForCleanup function name instead of
BufferShouldWaitForCleanupLockForStandby (and change the returning value
semantics). There are other possible alternatives: BufferIsReadyForWriting,
BufferIsReadyForExclusiveAccess or something else. The code will look like
below:

if (BufferIsReadyForCleanup(bufid + 1))
     break;

I've also found strange email in the commit messages like below:
Author: masao.fujii <masao.fujii@masao.fujii’s-MacBook-Pro>

I tried the modified 031 tap test but I do not see that it reproduces the issue
on the version without the fix. My version of 031 tap test hangs without the
fix. I haven't yet reviewed the tap test code at the moment, but I'm going to do
it as well.

Below one more note that is not directly related to the fix but may probably
improve the code readability.

1. BufferIsReadyForCleanup can be re-used with some small modifications in
LockBufferForCleanup like shown below:

LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
if (BufferIsReadyForCleanup())
{
     // log recovery conflict
     return;
}

In this case, we have to reset PM_PIN_COUNT_WAITER state in BufferIsReadyForCleanup:

if (buf_refcount == 1)
{
     bufHdr->wait_backend_procno = -1;
     PinCountWaitBuf = NULL;
     UnlockBufHdrExt(bufHdr, 0, PM_PIN_COUNT_WAITER);
     return false;
}

I may to prepare one more commit with this change.

With best regards,
Vitaly





view thread (43+ messages)  latest in thread

Message-ID: <b8f9bf41-8afa-46f5-9718-dc096bd666c0@postgrespro.ru>
Permalink:  ../b8f9bf41-8afa-46f5-9718-dc096bd666c0@postgrespro.ru/
Also on:    postgresql.org/message-id/b8f9bf41-8afa-46f5-9718-dc096bd666c0@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: v.davydov@postgrespro.ru, masao.fujii@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Deadlock detector fails to activate on a hot standby replica
  In-Reply-To: <b8f9bf41-8afa-46f5-9718-dc096bd666c0@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox