From 44091442db7e0d9fd7f0495f09d725fc92d940b5 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 25 Apr 2011 20:17:48 -0400 Subject: [PATCH] In pg_upgrade, avoid one start/stop of the postmaster; use the -w (wait) flag for pg_ctl start/stop; remove the unused "quiet" flag in the functions for starting/stopping the postmaster. --- contrib/pg_upgrade/check.c | 14 +++++++------- contrib/pg_upgrade/pg_upgrade.c | 19 +++++++------------ contrib/pg_upgrade/pg_upgrade.h | 4 ++-- contrib/pg_upgrade/server.c | 10 +++++----- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c index 415f95b616..a9436ce5b2 100644 --- a/contrib/pg_upgrade/check.c +++ b/contrib/pg_upgrade/check.c @@ -46,7 +46,7 @@ check_old_cluster(bool live_check, /* -- OLD -- */ if (!live_check) - start_postmaster(&old_cluster, false); + start_postmaster(&old_cluster); set_locale_and_encoding(&old_cluster); @@ -104,7 +104,7 @@ check_old_cluster(bool live_check, } if (!live_check) - stop_postmaster(false, false); + stop_postmaster(false); } @@ -134,7 +134,7 @@ report_clusters_compatible(void) { pg_log(PG_REPORT, "\n*Clusters are compatible*\n"); /* stops new cluster */ - stop_postmaster(false, false); + stop_postmaster(false); exit(0); } @@ -152,7 +152,7 @@ issue_warnings(char *sequence_script_file_name) /* old = PG 8.3 warnings? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803) { - start_postmaster(&new_cluster, true); + start_postmaster(&new_cluster); /* restore proper sequence values using file created from old server */ if (sequence_script_file_name) @@ -171,15 +171,15 @@ issue_warnings(char *sequence_script_file_name) old_8_3_rebuild_tsvector_tables(&new_cluster, false); old_8_3_invalidate_hash_gin_indexes(&new_cluster, false); old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false); - stop_postmaster(false, true); + stop_postmaster(false); } /* Create dummy large object permissions for old < PG 9.0? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) { - start_postmaster(&new_cluster, true); + start_postmaster(&new_cluster); new_9_0_populate_pg_largeobject_metadata(&new_cluster, false); - stop_postmaster(false, true); + stop_postmaster(false); } } diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c index e435aaef08..9f7a538765 100644 --- a/contrib/pg_upgrade/pg_upgrade.c +++ b/contrib/pg_upgrade/pg_upgrade.c @@ -77,7 +77,7 @@ main(int argc, char **argv) /* -- NEW -- */ - start_postmaster(&new_cluster, false); + start_postmaster(&new_cluster); check_new_cluster(); report_clusters_compatible(); @@ -88,7 +88,7 @@ main(int argc, char **argv) disable_old_cluster(); prepare_new_cluster(); - stop_postmaster(false, false); + stop_postmaster(false); /* * Destructive Changes to New Cluster @@ -98,10 +98,15 @@ main(int argc, char **argv) /* New now using xids of the old system */ + /* -- NEW -- */ + start_postmaster(&new_cluster); + prepare_new_databases(); create_new_objects(); + stop_postmaster(false); + transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); @@ -216,9 +221,6 @@ prepare_new_cluster(void) static void prepare_new_databases(void) { - /* -- NEW -- */ - start_postmaster(&new_cluster, false); - /* * We set autovacuum_freeze_max_age to its maximum value so autovacuum * does not launch here and delete clog files, before the frozen xids are @@ -252,8 +254,6 @@ prepare_new_databases(void) /* we load this to get a current list of databases */ get_db_and_rel_infos(&new_cluster); - - stop_postmaster(false, false); } @@ -262,9 +262,6 @@ create_new_objects(void) { int dbnum; - /* -- NEW -- */ - start_postmaster(&new_cluster, false); - prep_status("Adding support functions to new cluster"); for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++) @@ -290,8 +287,6 @@ create_new_objects(void) get_db_and_rel_infos(&new_cluster); uninstall_support_functions_from_new_cluster(); - - stop_postmaster(false, false); } diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h index 5865315d9e..358bf606b1 100644 --- a/contrib/pg_upgrade/pg_upgrade.h +++ b/contrib/pg_upgrade/pg_upgrade.h @@ -359,8 +359,8 @@ void init_tablespaces(void); PGconn *connectToServer(ClusterInfo *cluster, const char *db_name); PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...); -void start_postmaster(ClusterInfo *cluster, bool quiet); -void stop_postmaster(bool fast, bool quiet); +void start_postmaster(ClusterInfo *cluster); +void stop_postmaster(bool fast); uint32 get_major_server_version(ClusterInfo *cluster); void check_for_libpq_envvars(void); diff --git a/contrib/pg_upgrade/server.c b/contrib/pg_upgrade/server.c index ab8d8c7334..0c9914b413 100644 --- a/contrib/pg_upgrade/server.c +++ b/contrib/pg_upgrade/server.c @@ -160,13 +160,13 @@ stop_postmaster_atexit(void) stop_postmaster_on_exit(int exitstatus, void *arg) #endif { - stop_postmaster(true, true); + stop_postmaster(true); } void -start_postmaster(ClusterInfo *cluster, bool quiet) +start_postmaster(ClusterInfo *cluster) { char cmd[MAXPGPATH]; const char *bindir; @@ -205,7 +205,7 @@ start_postmaster(ClusterInfo *cluster, bool quiet) * not touch them. */ snprintf(cmd, sizeof(cmd), - SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" " + SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" " "-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE, bindir, output_filename, datadir, port, (cluster->controldata.cat_ver >= @@ -228,7 +228,7 @@ start_postmaster(ClusterInfo *cluster, bool quiet) void -stop_postmaster(bool fast, bool quiet) +stop_postmaster(bool fast) { char cmd[MAXPGPATH]; const char *bindir; @@ -249,7 +249,7 @@ stop_postmaster(bool fast, bool quiet) /* See comment in start_postmaster() about why win32 output is ignored. */ snprintf(cmd, sizeof(cmd), - SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> " + SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> " "\"%s\" 2>&1" SYSTEMQUOTE, bindir, #ifndef WIN32 -- 2.40.0