From 02df2994aabc4bb9b43ef8bfbc82c3b0669625fa Mon Sep 17 00:00:00 2001 From: Logan Leger Date: Tue, 11 Jun 2019 13:05:47 -0500 Subject: [PATCH] cmd/brew-postgresql-upgrade-database: fix initdb issues. * Add `safe_system` to `initdb` call to catch errors If the `initdb` step fails (which it can if the options passed are invalid), then the script will continue having marked `initdb_run` as `true`. This causes the script to continue to `pg_upgrade` step which will fail, ultimately triggering the `ensure` block. Since `initdb_run` is `true`, the script tries to remove `datadir` which we don't want since that step failed. The change here adds `safe_system` to ensure if the `initdb` step fails, it correctly bails out. * Add -X to `psql` call to ignore `.psqlrc` files Customizations in `.psqlrc` files can make the output of `psql` unpredictable, which can break parsing of the command's output. Using -X causes `psql` to ignore any such files and use the default output behavior, which can be parsed with consistency. --- cmd/brew-postgresql-upgrade-database.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/brew-postgresql-upgrade-database.rb b/cmd/brew-postgresql-upgrade-database.rb index 402054ef858..8e2c0bf1248 100755 --- a/cmd/brew-postgresql-upgrade-database.rb +++ b/cmd/brew-postgresql-upgrade-database.rb @@ -64,8 +64,8 @@ begin sql_for_lc_collate = "SELECT setting FROM pg_settings WHERE name LIKE 'lc_collate';" sql_for_lc_ctype = "SELECT setting FROM pg_settings WHERE name LIKE 'lc_ctype';" - lc_collate = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAc", sql_for_lc_collate).strip - lc_ctype = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAc", sql_for_lc_ctype).strip + lc_collate = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAX", "-U", ENV["USER"], "-c", sql_for_lc_collate) + lc_ctype = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAX", "-U", ENV["USER"], "-c", sql_for_lc_ctype) initdb_args = [] initdb_args += ["--lc-collate", lc_collate] unless lc_collate.empty? initdb_args += ["--lc-ctype", lc_ctype] unless lc_ctype.empty? @@ -79,7 +79,7 @@ begin moved_data = true (var/"postgres").mkpath - system "#{bin}/initdb", *initdb_args, "#{var}/postgres" + safe_system "#{bin}/initdb", *initdb_args, "#{var}/postgres" initdb_run = true (var/"log").cd do