Re: WAL_LOG CREATE DATABASE strategy broken for non-standard page layouts

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Rogers Wang <rogers(dot)ww(at)qq(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: WAL_LOG CREATE DATABASE strategy broken for non-standard page layouts
Date: 2026-11-19 21:42:43
Message-ID: CAAKRu_afwDbAtjyfoBjYgv_h49LD9UD6+yGrTB09qM_FFmhVTw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 18, 2026 at 10:42 AM Zhijie Hou <houzhijie22(at)gmail(dot)com> wrote:
>
> On Wed, Nov18, 2026 at 06:47 AM Melanie Plageman wrote:
>
> > Ah, okay. I'll do that. The original test feels awfully fragile. Is
> > there something we could do to strengthen it? Like check that one of
> > the buffers is marked BM_PERMANENT somehow? It seems very trivial to
> > accidentally eliminate the coverage. And there are of course lots of
> > ways for those buffers to get evicted.
>
> Maybe we could add a few comments above the CREATE DATABASE command to
> give developers a hint, and if it's worth it, we could add a check after
> the command to verify that pg_class's pages stay in the buffer cache
> (But note that if we add this check, we'd better disable autovaccum to
> prevent background access):
>
> # Verify that scanning template1's pg_class performs zero disk reads,
> # confirming its pages were not evicted by CREATE DATABASE.
> is( $node->safe_psql(
> $db_template, q{
> SELECT pg_stat_get_xact_blocks_fetched('pg_class'::regclass) -
> pg_stat_get_xact_blocks_hit('pg_class'::regclass)
> FROM pg_class
> HAVING sum(relpages) >= 0;
> }),
> "0",
> "template pg_class pages remain cached after CREATE DATABASE");

I decided to just add a comment to the test instead. I've now
committed and backpatched the main fix. The remaining patch attached
is targeted at master only and applies the optimization to
RelationCopyStorage(). I've added a few things since the last version
including a test.

- Melanie

Attachment Content-Type Size
v4-0001-Reduce-WAL-generated-when-copying-relation-storag.patch text/x-patch 7.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Nathan Bossart 2026-11-19 21:23:32 pg_restore fails on extracted tar archives with large objects