Re: Do not emit FPW for unlogged relations in BRIN empty-page

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Do not emit FPW for unlogged relations in BRIN empty-page
Date: 2025-12-18 12:57:09
Message-ID: 162110c0-8487-43bb-be0d-710bb5071818@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 17/12/2025 17:13, Kirill Reshke wrote:
> Hi hackers.
>
> I have been reviewing other patches, and spotted code in
> `brin_initialize_empty_new_buffer`. This function emits FPW for
> newly-initialized BRIN bufferafter `MarkBufferDirty`. It seems to me
> that this is unnecessary for UNLOGGED relations.
>
> I have re-checked instances of `MarkBufferDirty` and it seems to me
> that we always do WAL-logging stuff under RelationNeedsWAL marco,
> except for ambuildempty and few other cases.
>
> This code is hard to hit, so no reproducer here. In my understanding,
> this function executes under some concurrent patterns for index write
> activity. But I did not get when exactly.
> WDYT?

Yep, that's a bug. I was able to reproduce it with the attached script.
Run the script,then do "pg_ctl -D data restart -m immediate". Crash
recovery fails like this:

2025-12-18 14:55:00.266 EET [1494915] LOG: database system was
interrupted; last known up at 2025-12-18 14:54:45 EET
2025-12-18 14:55:00.405 EET [1494915] LOG: database system was not
properly shut down; automatic recovery in progress
2025-12-18 14:55:00.408 EET [1494915] LOG: redo starts at 0/1AAA080
2025-12-18 14:55:00.413 EET [1494915] LOG: invalid record length at
0/1EC5268: wanted 24, got 0
2025-12-18 14:55:00.413 EET [1494915] LOG: redo done at 0/1EC5240
system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2025-12-18 14:55:00.414 EET [1494915] FATAL: could not create file
"base/12974/16406": File exists
2025-12-18 14:55:00.414 EET [1494914] LOG: startup process (PID
1494915) exited with exit code 1
2025-12-18 14:55:00.414 EET [1494914] LOG: aborting startup due to
startup process failure

I'll commit and backpatch your fix. Thanks!

- Heikki

Attachment Content-Type Size
unlogged-brin-repro.sh application/x-shellscript 1.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2025-12-18 13:36:44 Re: pg_plan_advice
Previous Message Ashutosh Bapat 2025-12-18 12:52:52 Re: Report bytes and transactions actually sent downtream