The attached applied patch improves pg_upgrade by:  avoiding one
start/stop of the postmaster;  using the -w (wait) flag for pg_ctl
start/stop;  removing the unused "quiet" flag in the functions for
starting/stopping the postmaster.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
new file mode 100644
index 415f95b..a9436ce
*** a/contrib/pg_upgrade/check.c
--- b/contrib/pg_upgrade/check.c
*************** check_old_cluster(bool live_check,
*** 46,52 ****
  	/* -- OLD -- */
  
  	if (!live_check)
! 		start_postmaster(&old_cluster, false);
  
  	set_locale_and_encoding(&old_cluster);
  
--- 46,52 ----
  	/* -- OLD -- */
  
  	if (!live_check)
! 		start_postmaster(&old_cluster);
  
  	set_locale_and_encoding(&old_cluster);
  
*************** check_old_cluster(bool live_check,
*** 104,110 ****
  	}
  
  	if (!live_check)
! 		stop_postmaster(false, false);
  }
  
  
--- 104,110 ----
  	}
  
  	if (!live_check)
! 		stop_postmaster(false);
  }
  
  
*************** report_clusters_compatible(void)
*** 134,140 ****
  	{
  		pg_log(PG_REPORT, "\n*Clusters are compatible*\n");
  		/* stops new cluster */
! 		stop_postmaster(false, false);
  		exit(0);
  	}
  
--- 134,140 ----
  	{
  		pg_log(PG_REPORT, "\n*Clusters are compatible*\n");
  		/* stops new cluster */
! 		stop_postmaster(false);
  		exit(0);
  	}
  
*************** issue_warnings(char *sequence_script_fil
*** 152,158 ****
  	/* old = PG 8.3 warnings? */
  	if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
  	{
! 		start_postmaster(&new_cluster, true);
  
  		/* restore proper sequence values using file created from old server */
  		if (sequence_script_file_name)
--- 152,158 ----
  	/* old = PG 8.3 warnings? */
  	if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803)
  	{
! 		start_postmaster(&new_cluster);
  
  		/* restore proper sequence values using file created from old server */
  		if (sequence_script_file_name)
*************** issue_warnings(char *sequence_script_fil
*** 171,185 ****
  		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);
  	}
  
  	/* Create dummy large object permissions for old < PG 9.0? */
  	if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
  	{
! 		start_postmaster(&new_cluster, true);
  		new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
! 		stop_postmaster(false, true);
  	}
  }
  
--- 171,185 ----
  		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);
  	}
  
  	/* Create dummy large object permissions for old < PG 9.0? */
  	if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
  	{
! 		start_postmaster(&new_cluster);
  		new_9_0_populate_pg_largeobject_metadata(&new_cluster, false);
! 		stop_postmaster(false);
  	}
  }
  
diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c
new file mode 100644
index e435aae..9f7a538
*** a/contrib/pg_upgrade/pg_upgrade.c
--- b/contrib/pg_upgrade/pg_upgrade.c
*************** main(int argc, char **argv)
*** 77,83 ****
  
  
  	/* -- NEW -- */
! 	start_postmaster(&new_cluster, false);
  
  	check_new_cluster();
  	report_clusters_compatible();
--- 77,83 ----
  
  
  	/* -- NEW -- */
! 	start_postmaster(&new_cluster);
  
  	check_new_cluster();
  	report_clusters_compatible();
*************** main(int argc, char **argv)
*** 88,94 ****
  	disable_old_cluster();
  	prepare_new_cluster();
  
! 	stop_postmaster(false, false);
  
  	/*
  	 * Destructive Changes to New Cluster
--- 88,94 ----
  	disable_old_cluster();
  	prepare_new_cluster();
  
! 	stop_postmaster(false);
  
  	/*
  	 * Destructive Changes to New Cluster
*************** main(int argc, char **argv)
*** 98,107 ****
--- 98,112 ----
  
  	/* 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);
  
*************** prepare_new_cluster(void)
*** 216,224 ****
  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
--- 221,226 ----
*************** prepare_new_databases(void)
*** 252,259 ****
  
  	/* we load this to get a current list of databases */
  	get_db_and_rel_infos(&new_cluster);
- 
- 	stop_postmaster(false, false);
  }
  
  
--- 254,259 ----
*************** create_new_objects(void)
*** 262,270 ****
  {
  	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++)
--- 262,267 ----
*************** create_new_objects(void)
*** 290,297 ****
  	get_db_and_rel_infos(&new_cluster);
  
  	uninstall_support_functions_from_new_cluster();
- 
- 	stop_postmaster(false, false);
  }
  
  
--- 287,292 ----
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
new file mode 100644
index 5865315..358bf60
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
*************** void		init_tablespaces(void);
*** 359,366 ****
  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);
  uint32		get_major_server_version(ClusterInfo *cluster);
  void		check_for_libpq_envvars(void);
  
--- 359,366 ----
  PGconn	   *connectToServer(ClusterInfo *cluster, const char *db_name);
  PGresult   *executeQueryOrDie(PGconn *conn, const char *fmt,...);
  
! 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
new file mode 100644
index ab8d8c7..0c9914b
*** a/contrib/pg_upgrade/server.c
--- b/contrib/pg_upgrade/server.c
*************** stop_postmaster_atexit(void)
*** 160,172 ****
  stop_postmaster_on_exit(int exitstatus, void *arg)
  #endif
  {
! 	stop_postmaster(true, true);
  
  }
  
  
  void
! start_postmaster(ClusterInfo *cluster, bool quiet)
  {
  	char		cmd[MAXPGPATH];
  	const char *bindir;
--- 160,172 ----
  stop_postmaster_on_exit(int exitstatus, void *arg)
  #endif
  {
! 	stop_postmaster(true);
  
  }
  
  
  void
! start_postmaster(ClusterInfo *cluster)
  {
  	char		cmd[MAXPGPATH];
  	const char *bindir;
*************** start_postmaster(ClusterInfo *cluster, b
*** 205,211 ****
  	 * not touch them.
  	 */
  	snprintf(cmd, sizeof(cmd),
! 			 SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
  			 "-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
  			 bindir, output_filename, datadir, port,
  			 (cluster->controldata.cat_ver >=
--- 205,211 ----
  	 * not touch them.
  	 */
  	snprintf(cmd, sizeof(cmd),
! 			 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 >=
*************** start_postmaster(ClusterInfo *cluster, b
*** 228,234 ****
  
  
  void
! stop_postmaster(bool fast, bool quiet)
  {
  	char		cmd[MAXPGPATH];
  	const char *bindir;
--- 228,234 ----
  
  
  void
! stop_postmaster(bool fast)
  {
  	char		cmd[MAXPGPATH];
  	const char *bindir;
*************** stop_postmaster(bool fast, bool quiet)
*** 249,255 ****
  
  	/* 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 >> "
  			 "\"%s\" 2>&1" SYSTEMQUOTE,
  			 bindir,
  #ifndef WIN32
--- 249,255 ----
  
  	/* See comment in start_postmaster() about why win32 output is ignored. */
  	snprintf(cmd, sizeof(cmd),
! 			 SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> "
  			 "\"%s\" 2>&1" SYSTEMQUOTE,
  			 bindir,
  #ifndef WIN32
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to