Fix order of bin and data dir checks in pg_upgrade

If you called pg_upgrade with a --new-datadir that points to a
configuration-only dir and no --new-bindir option, it would try to
execute "postgres -C data_directory" using the new binary before
resolving the correct path to it.

To fix, check and resolve the binary dirs first, before calling
adjust_data_dir().  For clarity, rename the setup() function to
check_clusters_stopped() to better reflect what it does now.

One consequence of this is that if the binaries are not found, you now
get an error earlier than before, before the pg_upgrade_output.d
directory and the log files have been created.  That's what
necessitated the test change in this commit.  The log files are
important for things like listing unsupported objects in the source
database, but missing binaries feels like a more permanent error,
similar to invalid options or incorrect directory permissions, and it
seems OK to just print the error to stderr for those.

This has been broken forever, but I chose to not backpatch since no
one else has complained, it's a pretty minor issue, and it's easy to
work around by passing the binary dir explicitly.  Maybe later, if
someone in the field runs into this.

Reviewed-by: Chao Li <[email protected]>
Reviewed-by: Bohyun Lee <[email protected]>
Discussion: 
https://www.postgresql.org/message-id/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d733fcaf5cac6b88de9417f2b43e51490e36c7b1

Modified Files
--------------
src/bin/pg_upgrade/exec.c              | 21 ++++----------------
src/bin/pg_upgrade/option.c            |  7 ++++---
src/bin/pg_upgrade/pg_upgrade.c        | 36 ++++++++++++++++++++++++----------
src/bin/pg_upgrade/pg_upgrade.h        |  4 +++-
src/bin/pg_upgrade/t/002_pg_upgrade.pl | 31 +++++++----------------------
5 files changed, 44 insertions(+), 55 deletions(-)

Reply via email to