Re: Buffer locking is special (hints, checksums, AIO writes)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: Buffer locking is special (hints, checksums, AIO writes)
Date: 2026-01-24 21:03:04
Message-ID: ipf7upm2ooqnx5hkrw63prrcf4tvbcg4hansufiju3hdso35wr@4opaqhl6lwm7
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2026-01-24 15:31:14 -0500, Andres Freund wrote:
> I think this is more likely to be a spgist bug, not a bug in the patch. From
> what I can tell, spgist tries to conditionally lock a buffer that it itself
> already has locked exclusively - that's why the assertion is failing.
>
> I reproduced this locally, and could see in a bt full stack that the buffer
> that spgist is trying to lock conditionally, is also referenced as
> newInnerBuffer in doPickSplit(). So it's not an issue of bufmgr.c loosing
> track of which buffers are locked with what mode.
>
> I haven't yet figured out why spgist ends up with a buffer it already is
> using.
>
> We could of course just accept this case and have the conditional lock
> acquisition fail, but I think trying to conditionally lock a buffer that you
> already lock is indicative of something having gone wrong. But I'm open to
> going there anyway, just to avoid causing problems with previously "working"
> code.

Looking at the spgist code, and the README, I think we may need to accept the
uglines of silently failing when a backend tries to conditionally lock a
buffer that it itself has already locked. Even though I still don't
understand how it happens in this this specific case, that doesn't even have
concurrency.

Pretty ... not great ... that spgist does stuff like extending a relation
while holding an exclusive buffer lock.

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-01-24 21:11:47 Re: Buffer locking is special (hints, checksums, AIO writes)
Previous Message Andres Freund 2026-01-24 20:31:14 Re: Buffer locking is special (hints, checksums, AIO writes)