mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	Fix pg_upgrade's use of pg_ctl on Win32 to not send command and sever
output to the same file, because it is impossible. Also set user name for pg_dumpall in pg_upgrade.
This commit is contained in:
		
							parent
							
								
									7b6f29006e
								
							
						
					
					
						commit
						601d1eeddc
					
				| @ -19,9 +19,9 @@ generate_old_dump(migratorContext *ctx) | |||||||
| 	 * restores the frozenid's for databases and relations. | 	 * restores the frozenid's for databases and relations. | ||||||
| 	 */ | 	 */ | ||||||
| 	exec_prog(ctx, true, | 	exec_prog(ctx, true, | ||||||
| 			  SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --schema-only " | 			  SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --username \"%s\" " | ||||||
| 			  "--binary-upgrade > \"%s/" ALL_DUMP_FILE "\"" SYSTEMQUOTE, | 			  "--schema-only --binary-upgrade > \"%s/" ALL_DUMP_FILE "\"" | ||||||
| 			  ctx->new.bindir, ctx->old.port, ctx->cwd); | 			  SYSTEMQUOTE, ctx->new.bindir, ctx->old.port, ctx->user, ctx->cwd); | ||||||
| 	check_ok(ctx); | 	check_ok(ctx); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -174,12 +174,10 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[]) | |||||||
| 		 * start. | 		 * start. | ||||||
| 		 */ | 		 */ | ||||||
| 		/* truncate */ | 		/* truncate */ | ||||||
| 		ctx->log_fd = fopen(ctx->logfile, "w"); | 		if ((ctx->log_fd = fopen(ctx->logfile, "w")) == NULL) | ||||||
| 		if (!ctx->log_fd) |  | ||||||
| 			pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile); | 			pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile); | ||||||
| 		fclose(ctx->log_fd); | 		fclose(ctx->log_fd); | ||||||
| 		ctx->log_fd = fopen(ctx->logfile, "a"); | 		if ((ctx->log_fd = fopen(ctx->logfile, "a")) == NULL) | ||||||
| 		if (!ctx->log_fd) |  | ||||||
| 			pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile); | 			pg_log(ctx, PG_FATAL, "Cannot write to log file %s\n", ctx->logfile); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ | |||||||
| #define pg_link_file		win32_pghardlink | #define pg_link_file		win32_pghardlink | ||||||
| #define EXE_EXT				".exe" | #define EXE_EXT				".exe" | ||||||
| #define sleep(x)			Sleep(x * 1000) | #define sleep(x)			Sleep(x * 1000) | ||||||
| #define DEVNULL "nul" | #define DEVNULL				"nul" | ||||||
| /* "con" does not work from the Msys 1.0.10 console (part of MinGW). */ | /* "con" does not work from the Msys 1.0.10 console (part of MinGW). */ | ||||||
| #define DEVTTY  "con" | #define DEVTTY  "con" | ||||||
| /* from pgport */ | /* from pgport */ | ||||||
|  | |||||||
| @ -177,12 +177,22 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet) | |||||||
| 		port = ctx->new.port; | 		port = ctx->new.port; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* use -l for Win32 */ | 	/*
 | ||||||
|  | 	 * On Win32, we can't send both server output and pg_ctl 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 we have to send pg_ctl output to 'nul'. | ||||||
|  | 	 */	  | ||||||
| 	snprintf(cmd, sizeof(cmd), | 	snprintf(cmd, sizeof(cmd), | ||||||
| 			 SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" " | 			 SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" " | ||||||
| 			 "-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" " | 			 "-o \"-p %d -c autovacuum=off -c autovacuum_freeze_max_age=2000000000\" " | ||||||
| 			 "start >> \"%s\" 2>&1" SYSTEMQUOTE, | 			 "start >> \"%s\" 2>&1" SYSTEMQUOTE, | ||||||
| 			 bindir, ctx->logfile, datadir, port, ctx->logfile); | 			 bindir, ctx->logfile, datadir, port, | ||||||
|  | #ifndef WIN32 | ||||||
|  | 			 ctx->logfile); | ||||||
|  | #else | ||||||
|  | 			 DEVNULL); | ||||||
|  | #endif | ||||||
| 	exec_prog(ctx, true, "%s", cmd); | 	exec_prog(ctx, true, "%s", cmd); | ||||||
| 
 | 
 | ||||||
| 	/* wait for the server to start properly */ | 	/* wait for the server to start properly */ | ||||||
| @ -200,6 +210,7 @@ start_postmaster(migratorContext *ctx, Cluster whichCluster, bool quiet) | |||||||
| void | void | ||||||
| stop_postmaster(migratorContext *ctx, bool fast, bool quiet) | stop_postmaster(migratorContext *ctx, bool fast, bool quiet) | ||||||
| { | { | ||||||
|  | 	char		cmd[MAXPGPATH]; | ||||||
| 	const char *bindir; | 	const char *bindir; | ||||||
| 	const char *datadir; | 	const char *datadir; | ||||||
| 
 | 
 | ||||||
| @ -216,10 +227,16 @@ stop_postmaster(migratorContext *ctx, bool fast, bool quiet) | |||||||
| 	else | 	else | ||||||
| 		return;					/* no cluster running */ | 		return;					/* no cluster running */ | ||||||
| 
 | 
 | ||||||
| 	/* use -l for Win32 */ | 	/* See comment in start_postmaster() about why win32 output is ignored. */ | ||||||
| 	exec_prog(ctx, fast ? false : true, | 	snprintf(cmd, sizeof(cmd), | ||||||
| 			  SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> \"%s\" 2>&1" SYSTEMQUOTE, | 			  SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" %s stop >> \"%s\" 2>&1" SYSTEMQUOTE, | ||||||
| 		 bindir, ctx->logfile, datadir, fast ? "-m fast" : "", ctx->logfile); | 			  bindir, ctx->logfile, datadir, fast ? "-m fast" : "", | ||||||
|  | #ifndef WIN32 | ||||||
|  | 			  ctx->logfile); | ||||||
|  | #else | ||||||
|  | 			  DEVNULL); | ||||||
|  | #endif | ||||||
|  | 	exec_prog(ctx, fast ? false : true, "%s", cmd); | ||||||
| 
 | 
 | ||||||
| 	ctx->postmasterPID = 0; | 	ctx->postmasterPID = 0; | ||||||
| 	ctx->running_cluster = NONE; | 	ctx->running_cluster = NONE; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user