diff --git a/contrib/pg_upgrade/dump.c b/contrib/pg_upgrade/dump.c
new file mode 100644
index 577ccac..dbdf9a5
*** a/contrib/pg_upgrade/dump.c
--- b/contrib/pg_upgrade/dump.c
*************** generate_old_dump(void)
*** 24,30 ****
  	 * restores the frozenid's for databases and relations.
  	 */
  	exec_prog(UTILITY_LOG_FILE, NULL, true,
! 			  "\"%s/pg_dumpall\" %s --schema-only --binary-upgrade %s -f %s",
  			  new_cluster.bindir, cluster_conn_opts(&old_cluster),
  			  log_opts.verbose ? "--verbose" : "",
  			  ALL_DUMP_FILE);
--- 24,30 ----
  	 * restores the frozenid's for databases and relations.
  	 */
  	exec_prog(UTILITY_LOG_FILE, NULL, true,
! 			  "\"%s/pg_dumpall\" %s --schema-only --globals-only --binary-upgrade %s -f %s",
  			  new_cluster.bindir, cluster_conn_opts(&old_cluster),
  			  log_opts.verbose ? "--verbose" : "",
  			  ALL_DUMP_FILE);
*************** generate_old_dump(void)
*** 47,63 ****
  void
  split_old_dump(void)
  {
! 	FILE	   *all_dump,
! 			   *globals_dump,
! 			   *db_dump;
! 	FILE	   *current_output;
  	char		line[LINE_ALLOC];
  	bool		start_of_line = true;
  	char		create_role_str[MAX_STRING];
  	char		create_role_str_quote[MAX_STRING];
  	char		filename[MAXPGPATH];
- 	bool		suppressed_username = false;
- 
  
  	/* 
  	 * Open all files in binary mode to avoid line end translation on Windows,
--- 47,58 ----
  void
  split_old_dump(void)
  {
! 	FILE	   *all_dump, *globals_dump;
  	char		line[LINE_ALLOC];
  	bool		start_of_line = true;
  	char		create_role_str[MAX_STRING];
  	char		create_role_str_quote[MAX_STRING];
  	char		filename[MAXPGPATH];
  
  	/* 
  	 * Open all files in binary mode to avoid line end translation on Windows,
*************** split_old_dump(void)
*** 70,80 ****
  	snprintf(filename, sizeof(filename), "%s", GLOBALS_DUMP_FILE);
  	if ((globals_dump = fopen_priv(filename, PG_BINARY_W)) == NULL)
  		pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno));
- 	snprintf(filename, sizeof(filename), "%s", DB_DUMP_FILE);
- 	if ((db_dump = fopen_priv(filename, PG_BINARY_W)) == NULL)
- 		pg_log(PG_FATAL, "Could not write to dump file \"%s\": %s\n", filename, getErrorText(errno));
- 
- 	current_output = globals_dump;
  
  	/* patterns used to prevent our own username from being recreated */
  	snprintf(create_role_str, sizeof(create_role_str),
--- 65,70 ----
*************** split_old_dump(void)
*** 84,102 ****
  
  	while (fgets(line, sizeof(line), all_dump) != NULL)
  	{
- 		/* switch to db_dump file output? */
- 		if (current_output == globals_dump && start_of_line &&
- 			suppressed_username &&
- 			strncmp(line, "\\connect ", strlen("\\connect ")) == 0)
- 			current_output = db_dump;
- 
  		/* output unless we are recreating our own username */
! 		if (current_output != globals_dump || !start_of_line ||
  			(strncmp(line, create_role_str, strlen(create_role_str)) != 0 &&
  			 strncmp(line, create_role_str_quote, strlen(create_role_str_quote)) != 0))
! 			fputs(line, current_output);
! 		else
! 			suppressed_username = true;
  
  		if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
  			start_of_line = true;
--- 74,84 ----
  
  	while (fgets(line, sizeof(line), all_dump) != NULL)
  	{
  		/* output unless we are recreating our own username */
! 		if (!start_of_line ||
  			(strncmp(line, create_role_str, strlen(create_role_str)) != 0 &&
  			 strncmp(line, create_role_str_quote, strlen(create_role_str_quote)) != 0))
! 			fputs(line, globals_dump);
  
  		if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
  			start_of_line = true;
*************** split_old_dump(void)
*** 106,110 ****
  
  	fclose(all_dump);
  	fclose(globals_dump);
- 	fclose(db_dump);
  }
--- 88,91 ----
diff --git a/contrib/pg_upgrade/function.c b/contrib/pg_upgrade/function.c
new file mode 100644
index 77bd3a0..d95dd6f
*** a/contrib/pg_upgrade/function.c
--- b/contrib/pg_upgrade/function.c
*************** uninstall_support_functions_from_new_clu
*** 102,111 ****
  
  	prep_status("Removing support functions from new cluster");
  
! 	for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
  	{
! 		DbInfo	   *new_db = &new_cluster.dbarr.dbs[dbnum];
! 		PGconn	   *conn = connectToServer(&new_cluster, new_db->db_name);
  
  		/* suppress NOTICE of dropped objects */
  		PQclear(executeQueryOrDie(conn,
--- 102,112 ----
  
  	prep_status("Removing support functions from new cluster");
  
! 	/* use old db names because there might be a mismatch */
! 	for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
  	{
! 		DbInfo	   *old_db = &old_cluster.dbarr.dbs[dbnum];
! 		PGconn	   *conn = connectToServer(&new_cluster, old_db->db_name);
  
  		/* suppress NOTICE of dropped objects */
  		PQclear(executeQueryOrDie(conn,
diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c
new file mode 100644
index 4d2e79c..1e72108
*** a/contrib/pg_upgrade/pg_upgrade.c
--- b/contrib/pg_upgrade/pg_upgrade.c
*************** main(int argc, char **argv)
*** 117,129 ****
  	/* New now using xids of the old system */
  
  	/* -- NEW -- */
  	start_postmaster(&new_cluster);
  
  	prepare_new_databases();
! 
  	create_new_objects();
  
  	stop_postmaster(false);
  
  	/*
  	 * Most failures happen in create_new_objects(), which has completed at
--- 117,134 ----
  	/* New now using xids of the old system */
  
  	/* -- NEW -- */
+ 	old_cluster.port++;
+ 	start_postmaster(&old_cluster);
  	start_postmaster(&new_cluster);
  
  	prepare_new_databases();
! 	
  	create_new_objects();
  
  	stop_postmaster(false);
+ 	os_info.running_cluster = &old_cluster;
+ 	stop_postmaster(false);
+ 	old_cluster.port--;
  
  	/*
  	 * Most failures happen in create_new_objects(), which has completed at
*************** static void
*** 279,308 ****
  create_new_objects(void)
  {
  	int			dbnum;
  
  	prep_status("Adding support functions to new cluster");
  
! 	for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
  	{
! 		DbInfo	   *new_db = &new_cluster.dbarr.dbs[dbnum];
  
  		/* skip db we already installed */
! 		if (strcmp(new_db->db_name, "template1") != 0)
! 			install_support_functions_in_new_db(new_db->db_name);
  	}
  	check_ok();
  
  	prep_status("Restoring database schema to new cluster");
! 	exec_prog(RESTORE_LOG_FILE, NULL, true,
! 			  "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"",
! 			  new_cluster.bindir, cluster_conn_opts(&new_cluster),
! 			  DB_DUMP_FILE);
  	check_ok();
  
  	/* regenerate now that we have objects in the databases */
  	get_db_and_rel_infos(&new_cluster);
  
  	uninstall_support_functions_from_new_cluster();
  }
  
  /*
--- 284,335 ----
  create_new_objects(void)
  {
  	int			dbnum;
+ 	/* save off conn_opts because it is a static local var */
+ 	char	   *old_conn_opts = pg_strdup(cluster_conn_opts(&old_cluster));
  
  	prep_status("Adding support functions to new cluster");
  
! 	/*
! 	 *	The new cluster might have databases that don't exist in the old
! 	 *	one, so cycle over the old database names.
! 	 */
! 	for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
  	{
! 		DbInfo	   *old_db = &old_cluster.dbarr.dbs[dbnum];
  
  		/* skip db we already installed */
! 		if (strcmp(old_db->db_name, "template1") != 0)
! 			install_support_functions_in_new_db(old_db->db_name);
  	}
  	check_ok();
  
  	prep_status("Restoring database schema to new cluster");
! 
! 	for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
! 	{
! 		DbInfo	   *old_db = &old_cluster.dbarr.dbs[dbnum];
! 		
! 		/*
! 		 *	Using pg_restore --single-transaction is faster than other
! 		 *	methods, like --jobs.  pg_dump only produces its output at the
! 		 *	end, so there is little parallelism using the pipe.
! 		 */
! 		exec_prog(RESTORE_LOG_FILE, NULL, true,
! 				  "\"%s/pg_dump\" %s --schema-only --binary-upgrade --format=custom %s \"%s\" |"
! 				  "\"%s/pg_restore\" %s --exit-on-error --single-transaction %s --dbname \"%s\"",
! 				  new_cluster.bindir, old_conn_opts,
! 				  log_opts.verbose ? "--verbose" : "", old_db->db_name,
! 				  new_cluster.bindir, cluster_conn_opts(&new_cluster),
! 				  log_opts.verbose ? "--verbose" : "", old_db->db_name);
! 	}
  	check_ok();
  
  	/* regenerate now that we have objects in the databases */
  	get_db_and_rel_infos(&new_cluster);
  
  	uninstall_support_functions_from_new_cluster();
+ 
+ 	pg_free(old_conn_opts);
  }
  
  /*
*************** cleanup(void)
*** 463,468 ****
  		/* remove SQL files */
  		unlink(ALL_DUMP_FILE);
  		unlink(GLOBALS_DUMP_FILE);
- 		unlink(DB_DUMP_FILE);
  	}
  }
--- 490,494 ----
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
new file mode 100644
index ace56e5..72ed3bd
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
***************
*** 32,38 ****
  #define ALL_DUMP_FILE		"pg_upgrade_dump_all.sql"
  /* contains both global db information and CREATE DATABASE commands */
  #define GLOBALS_DUMP_FILE	"pg_upgrade_dump_globals.sql"
- #define DB_DUMP_FILE		"pg_upgrade_dump_db.sql"
  
  #define SERVER_LOG_FILE		"pg_upgrade_server.log"
  #define RESTORE_LOG_FILE	"pg_upgrade_restore.log"
--- 32,37 ----
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
new file mode 100644
index ca95bad..ce27fe3
*** a/src/bin/pg_dump/pg_dumpall.c
--- b/src/bin/pg_dump/pg_dumpall.c
*************** main(int argc, char *argv[])
*** 502,508 ****
  		}
  
  		/* Dump CREATE DATABASE commands */
! 		if (!globals_only && !roles_only && !tablespaces_only)
  			dumpCreateDB(conn);
  
  		/* Dump role/database settings */
--- 502,508 ----
  		}
  
  		/* Dump CREATE DATABASE commands */
! 		if (binary_upgrade || (!globals_only && !roles_only && !tablespaces_only))
  			dumpCreateDB(conn);
  
  		/* Dump role/database settings */
