diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c
new file mode 100644
index 06af6d4..66a70ca
*** a/contrib/pg_upgrade/option.c
--- b/contrib/pg_upgrade/option.c
*************** parseCommandLine(int argc, char *argv[])
*** 57,63 ****
  	int			optindex = 0;	/* used by getopt_long */
  	int			os_user_effective_id;
  	FILE		*fp;
! 	int			i;
  	time_t		run_time = time(NULL);
  	
  	user_opts.transfer_mode = TRANSFER_MODE_COPY;
--- 57,63 ----
  	int			optindex = 0;	/* used by getopt_long */
  	int			os_user_effective_id;
  	FILE		*fp;
! 	char		**filename;
  	time_t		run_time = time(NULL);
  	
  	user_opts.transfer_mode = TRANSFER_MODE_COPY;
*************** parseCommandLine(int argc, char *argv[])
*** 188,198 ****
  	}
  
  	/* label start of upgrade in logfiles */
! 	for (i = 0; i < NUM_LOG_FILES; i++)
  	{
! 		if ((fp = fopen_priv(output_files[i], "a")) == NULL)
! 			pg_log(PG_FATAL, "cannot write to log file %s\n",
! 				   output_files[i]);
  		fprintf(fp, "\n"
  		"-----------------------------------------------------------------\n"
  		"  pg_upgrade run on %s"
--- 188,199 ----
  	}
  
  	/* label start of upgrade in logfiles */
! 	for (filename = output_files; *filename != NULL; filename++)
  	{
! 		if ((fp = fopen_priv(*filename, "a")) == NULL)
! 			pg_log(PG_FATAL, "cannot write to log file %s\n", *filename);
! 
! 		/* Start with newline because we might be appending to a file. */
  		fprintf(fp, "\n"
  		"-----------------------------------------------------------------\n"
  		"  pg_upgrade run on %s"
diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c
new file mode 100644
index cc74f11..7297efd
*** a/contrib/pg_upgrade/pg_upgrade.c
--- b/contrib/pg_upgrade/pg_upgrade.c
*************** ClusterInfo old_cluster,
*** 55,65 ****
  			new_cluster;
  OSInfo		os_info;
  
! char *output_files[NUM_LOG_FILES] = {
  	SERVER_LOG_FILE,
  	RESTORE_LOG_FILE,
  	UTILITY_LOG_FILE,
! 	INTERNAL_LOG_FILE
  };
  
  
--- 55,70 ----
  			new_cluster;
  OSInfo		os_info;
  
! char *output_files[] = {
  	SERVER_LOG_FILE,
+ #ifdef WIN32
+ 	/* file is unique on Win32 */
+ 	SERVER_LOG_FILE2,
+ #endif
  	RESTORE_LOG_FILE,
  	UTILITY_LOG_FILE,
! 	INTERNAL_LOG_FILE,
! 	NULL
  };
  
  
*************** cleanup(void)
*** 454,474 ****
  	/* Remove dump and log files? */
  	if (!log_opts.retain)
  	{
! 		char		filename[MAXPGPATH];
! 		int i;
  
! 		for (i = 0; i < NUM_LOG_FILES; i++)
! 		{
! 			snprintf(filename, sizeof(filename), "%s", output_files[i]);
! 			unlink(filename);
! 		}
  
  		/* remove SQL files */
! 		snprintf(filename, sizeof(filename), "%s", ALL_DUMP_FILE);
! 		unlink(filename);
! 		snprintf(filename, sizeof(filename), "%s", GLOBALS_DUMP_FILE);
! 		unlink(filename);
! 		snprintf(filename, sizeof(filename), "%s", DB_DUMP_FILE);
! 		unlink(filename);
  	}
  }
--- 459,472 ----
  	/* Remove dump and log files? */
  	if (!log_opts.retain)
  	{
! 		char		**filename;
  
! 		for (filename = output_files; *filename != NULL; filename++)
! 			unlink(*filename);
  
  		/* remove SQL files */
! 		unlink(ALL_DUMP_FILE);
! 		unlink(GLOBALS_DUMP_FILE);
! 		unlink(DB_DUMP_FILE);
  	}
  }
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
new file mode 100644
index 6dcb1a5..0d6269a
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
***************
*** 40,46 ****
  #define UTILITY_LOG_FILE	"pg_upgrade_utility.log"
  #define INTERNAL_LOG_FILE	"pg_upgrade_internal.log"
  
- #define NUM_LOG_FILES		4
  extern char *output_files[];
  
  /*
--- 40,45 ----
*************** extern char *output_files[];
*** 49,56 ****
   * On Win32, we can't send both pg_upgrade output and command output to the
   * same file because we get the error: "The process cannot access the file
   * because it is being used by another process." so send the pg_ctl
!  * command-line output to the utility log file on Windows, rather than
!  * into the server log file.
   *
   * We could use the Windows pgwin32_open() flags to allow shared file
   * writes but is unclear how all other tools would use those flags, so
--- 48,57 ----
   * On Win32, we can't send both pg_upgrade output and command output to the
   * same file because we get the error: "The process cannot access the file
   * because it is being used by another process." so send the pg_ctl
!  * command-line output to a new file, rather than into the server log file.
!  * Ideally we could use UTILITY_LOG_FILE for this, but some Windows platforms
!  * keep the pg_ctl output file open even after pg_ctl exits, perhaps by the
!  * running postmaster.
   *
   * We could use the Windows pgwin32_open() flags to allow shared file
   * writes but is unclear how all other tools would use those flags, so
*************** extern char *output_files[];
*** 60,66 ****
  #ifndef WIN32
  #define SERVER_LOG_FILE2	SERVER_LOG_FILE
  #else
! #define SERVER_LOG_FILE2	UTILITY_LOG_FILE
  #endif
  
  
--- 61,67 ----
  #ifndef WIN32
  #define SERVER_LOG_FILE2	SERVER_LOG_FILE
  #else
! #define SERVER_LOG_FILE2	"pg_upgrade_server2.log"
  #endif
  
  
