On 28/10/2026 02:41, shihao zhong wrote:
Hi Bohyun,

Thanks for v10.  I think this patch is LGTM

I stepped back a little to think harder about the usability aspect of this. I think for anyone running pg_upgrade directly, this is a clear improvement. On that front though, I think we should document the new "pg_upgrade --initdb" option as the easy, default way to run pg_upgrade. Maybe even make it the default. Or have pg_upgrade check if the new cluster already exists and run initdb automatically if it doesn't.

But a bigger issue is this thing that Daniel commented earlier:

I am not convinced that all this complexity and overhead isn't better suited
for external wrappers to pg_upgrade like Debian's pg_upgradecluster etc.

I think this can be, and really should be, useful for pg_upgradecluster. (And I mean also other scripts in other distributions, docker images etc., but I'll use pg_upgradecluster to stand in for all of those). It currently has logic to read the options of the old cluster, like locale and whether checksums are enabled, and build the initdb options to use based on that. It seems silly that the calling script needs to know how to do all that. pg_ugprade already has the knowledge, because it already has checks to verify that you used the right options. So this is a case of "I know exactly what options you need to use, and I will complain if you get them wrong, but I won't tell you what those options are until you try."

This new "pg_upgrade --initdb" option should be able to replace that logic. If it cannot, if pg_upgradecluster still needs to duplicate the logic to check the old cluster's options, it makes this patch a lot less interesting. Unfortunately it seems difficult for pg_upgradecluster to use this in its current form. I think we need to step back and figure out how to make it usable for pg_upgradecluster.

The reason pg_upgradecluster cannot readily use this is that it doesn't fit its workflow very well. It does basically this:

1. Read old cluster's options to determine the initdb options needed
2. Call pg_createcluster with with those options. pg_createcluster calls initdb
3. Copy config files from the old cluster
4. Run some other upgrade scripts from pg_upgradecluster.d. (Not sure what those might do)
5. Run pg_upgrade

Using "pg_upgrade --initdb" would require big changes to that workflow. How can we avoid that?

One idea is to have another option, "pg_upgrade --print-initdb-options", that just prints the initdb options you need to use to initialize the cluster. That would replace the current pg_upgradecluster's logic to figure out those option, but keep the workflow otherwise the same.

Another idea is to have an option like "pg_upgrade --initdb-only", which just runs initdb with the right options, and stops. You can call that first, to create the new cluster, do all the configuration steps, and then call pg_upgrade again to perform the upgrade. That requires a little more changes to the workflow, but I think it wouldn't be too bad.


I think the current "pg_upgrade --initdb" mode where it just creates the cluster for you is still useful and convenient for anyone running pg_upgrade directly, and for simpler scripts that don't have extra configuration steps like pg_upgradecluster does. So I would keep that too. But one way or another, more complicated scripts need to have the control back between running initdb and performing the upgrade.

- Heikki


Reply via email to