| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Bohyun Lee <bohyun(dot)lee(at)databricks(dot)com> |
| Cc: | Greg Sabino Mullane <htamfids(at)gmail(dot)com>, 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-12-02 06:48:00 |
| Message-ID: | B20405FA-D6C0-4509-A8B0-5A2DD95B420C@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Nov 27, 2026, at 02:46, Bohyun Lee <bohyun(dot)lee(at)databricks(dot)com> wrote:
>
> 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
>
> <v1-postgresql-common-initdb-options.patch><v11-pg_upgrade-print-initdb-options.patch>
Thanks for the patch. A few comments on v11:
1. My first test run shows:
```
% pg_upgrade --print-initdb-options -b /usr/local/pgsql/bin -d .
Examining old cluster settings ok
--wal-segsize=16 --data-checksums --encoding=UTF8 --locale-provider=libc --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
```
This made me wonder: which options are printed? I ran the command against my test cluster, which was created with “initdb .”. I didn’t give any options to the initdb command, so all the printed options have their default values. What is the principle for deciding which options to print? I saw that Heikki pointed out Debian’s pg_upgradecluster, but this patch prints more options than pg_upgradecluster consumes. I think we should at least describe the principle in the commit message.
2 - pg_upgrade.c
```
- /* same goes for the new postmaster */
- if (pid_lock_file_exists(new_cluster.pgdata))
+ /* Printing does not use the new cluster. */
+ if (!user_opts.print_initdb_options &&
+ pid_lock_file_exists(new_cluster.pgdata))
{
```
I think it’s better to leave the existing pid_lock_file_exists() check unchanged. Instead, we can return early if user_opts.print_initdb_options is true.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chao Li | 2026-12-02 06:55:05 | Re: [PATCH v2] Reuse slot helpers in pg_get_replication_slots and slot copy |
| Previous Message | Neil Chen | 2026-12-02 06:47:29 | Re: [PATCH] Handle SQL NULL results from casts in JSON generation |