Re: [PATCH] pg_upgrade: add --initdb option to create the new cluster automatically

From: Hüseyin Demir <huseyin(dot)d3r(at)gmail(dot)com>
To: Bohyun Lee <bohyun(dot)lee(at)databricks(dot)com>
Cc: Greg Sabino Mullane <htamfids(at)gmail(dot)com>, Daniel Gustafsson <daniel(at)yesql(dot)se>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] pg_upgrade: add --initdb option to create the new cluster automatically
Date: 2026-08-18 10:31:53
Message-ID: CAB5wL7bv2MSKj-ctaqkKZ3ZYyWiR7SMBxiHiS8VdHP0zc9ZKNQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> v5 resolved this as a dry run rather than a hard block. --check
> --initdb reports the initdb command it would run and validates the
> preconditions (correct new-binary version, empty target directory, old
> cluster reachable) without creating the new cluster. v6 keeps that,
> and the docs now describe it.

Thanks, appreciated.

> > I'm not clear what pointing this out for --initdb only accomplishes.
> > A wrong -B is going to cause problems regardless of the mode.
> I agree, and I believe this meets Demir's point about orphan directories.
> v5 checks the new-binary version up front, so a wrong -B fails before anything is
> written. An atexit handler removes the created directory if a later
> check fails, up until the point where real data has been copied. So
> there is no need for a -B note specific to --initdb in the docs.
> v6 carries both.

Got it, great.

>
> > Eliminating what exactly? And why would a vacuum or checkpoint cause
> > problems?
> The old server is started here with the same start_postmaster() that
> pg_upgrade uses elsewhere -- including -b, which disables autovacuum --
> only to read template0's encoding and locale, then stopped before the
> new cluster is created. So autovacuum will not run, and a checkpoint
> would be harmless. It is a brief, read-only start using pg_upgrade's
> existing mechanism, so it adds no risk beyond the old-server starts
> pg_upgrade already performs. The docs now mention this brief start.

Thanks for handling this.

> Beyond the review points, v6 also tightens two things I noticed while
> reworking this:

> - The empty-directory guard now rejects any non-empty target directory,
> not just one already containing a PG_VERSION file. This closes a gap
> in the orphan-cleanup path. The cleanup handler removes the whole new
> data directory on failure, so it must not run against a directory that
> already held the user's files.

> - Because --initdb reads template0 by briefly starting the old server, it
> now checks in advance that the old server is shut down and fails with the
> usual "shut down that postmaster" message, rather than failing later
> when pg_resetwal refuses to run against a live server.

Good catches, I have no objections to v6.

Regards,
Demir.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-08-18 10:37:05 Re: Error handling in after-startup shmem requests
Previous Message Kwangwon Seo 2026-08-18 10:11:58 Re: [PATCH] Fix quotation logic for unreserved keywords in window specifications