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

From: Bohyun Lee <bohyun(dot)lee(at)databricks(dot)com>
To: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Daniel Gustafsson <daniel(at)yesql(dot)se>, shihao zhong <zhong950419(at)gmail(dot)com>, Harrison Booth <harrisontbooth(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, myon(at)debian(dot)org
Subject: Re: [PATCH] pg_upgrade: add --initdb option to create the new cluster automatically
Date: 2026-11-26 18:46:43
Message-ID: CAMPh8MpFQejDr1aoZ946Vk7aFmcME89xo_m54eDsGVjrkYJqiA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Heikki, Daniel, and Greg,

As Heikki suggested, I've started with --print-initdb-options because
Debian's pg_upgradecluster needs it. Indeed, it would be nice to better
support
users of Debian’s upgrade scripts, as well as those running pg_upgrade
directly.

The attached v11 patch adds:

pg_upgrade --print-initdb-options -b /old/bin -d /old/data

It prints one line of shell-quoted initdb arguments, following
pg_config --configure, with diagnostics on stderr, including the WAL
segment size, checksum setting, and template0 encoding and locale
defaults.

Printing can inspect a running or stopped source. It does not check a
target cluster, so combining it with --check is rejected. After creating
the target, callers can run ordinary pg_upgrade --check.

I've also attached a postgresql-common companion patch demonstrating how
pg_upgradecluster can use the printed WAL/checksum settings while
retaining Debian's maintenance-database selection, locale overrides,
configuration copying, and hooks.

This preserves the opportunity to set shared_preload_libraries before the
new server starts. The PG TAP test covers output reuse through a
normal check and upgrade, shell quoting, and source lifecycle. I also
tested the patched pg_upgradecluster through a complete upgrade in an
isolated Debian package layout.

Best,
Bohyun

On Wed, Nov 25, 2026 at 4:12 PM Greg Sabino Mullane <htamfids(at)gmail(dot)com>
wrote:

> On Fri, Nov 20, 2026 at 8:11 AM Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
> wrote:
>
>> Setting shared_preload_libraries in the config file.
>
>
> Thanks, that's a good example. While some don't require it and CREATE
> EXTENSION works fine (e.g. the one I immediately thought of,
> pg_stat_statements), others do require a middle step (e.g. pg_cron). Your
> --print-initdb-options and --initdb-only ideas are good, and I lean towards
> the latter. The other option is to make --initdb smarter. Maybe that means
> copying the existing conf files over, maybe it means picking pieces out
> like shared_preload_libraries. At any rate, that's probably a bigger ask
> than this patch. Perhaps we can just release this patch as is (with a
> --initdb flag), and have a separate patch that does --initdb-only and/or
> gives --initdb more brains?
>
> Cheers,
> Greg
>
>

Attachment Content-Type Size
v1-postgresql-common-initdb-options.patch application/octet-stream 22.1 KB
v11-pg_upgrade-print-initdb-options.patch application/octet-stream 28.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-11-26 18:54:43 Re: Fix two race conditions in processing interrupts
Previous Message Raja Sai pranav 2026-11-26 18:30:25 Use option_parse_int() for pg_createsubscriber --recovery-timeout and pgbench --max-tries