Re: Checkpoints stuck after a failed bulk write inside a savepoint

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: Joao Rito <joaovictor(dot)rito(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Re: Checkpoints stuck after a failed bulk write inside a savepoint
Date: 2026-11-20 07:40:53
Message-ID: av_5hReeUQQ-VY-4@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 16, 2026 at 12:20:36PM -0500, shihao zhong wrote:
> Yes, the cost is one extra fsync per segment on a file we just
> flushed. It only happens when a checkpoint runs during the bulk write.

Hmm. I am not sure to like that much, as it is wasteful, at least.
How about checking the redo LSN twice instead? I would imagine, let's
say:
- First check the redo LSN.
- If it does not match with what's in the bulk state, register a sync
request.
- Within the code block that registered the sync request, re-check the
redo LSN vs the bulk state LSN.
- If the redo LSN and the bulk state LSN in the second check do not
match, do smgrimmedsync().

That's still not better than what's on HEAD, but it reduces the window
of the useless syncs to be close to zero in practice, only when a
checkpoint had the idea to run between the smgrregistersync() and the
smgrregistersync() calls. And we don't lose track of the flag value
due to the fact that we don't use it.

The bulk loading facility exists down to v17, but I'm not convinced
that this is worth a backpatch: this is very unlikely going to show up
in practice.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-11-20 07:49:19 Re: CI slowdown due to PG_TEST_INITDB_EXTRA_OPTS
Previous Message Bertrand Drouvot 2026-11-20 07:39:56 Re: pg_dump: remove restore.sql from tar format