Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 17a16ee

Browse files
committed
In pg_upgrade, fix the -l/log option to work on Windows.
Also, double-quote the log file name in all places, to allow (on all platforms) log file names with spaces. Back patch to 9.0 and 9.1.
1 parent 6b43fdd commit 17a16ee

File tree

5 files changed

+30
-33
lines changed

5 files changed

+30
-33
lines changed

contrib/pg_upgrade/check.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ issue_warnings(char *sequence_script_file_name)
170170
"--no-psqlrc --port %d --username \"%s\" "
171171
"-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
172172
new_cluster.bindir, new_cluster.port, os_info.user,
173-
sequence_script_file_name, log_opts.filename);
173+
sequence_script_file_name, log_opts.filename2);
174174
unlink(sequence_script_file_name);
175175
check_ok();
176176
}

contrib/pg_upgrade/option.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ parseCommandLine(int argc, char *argv[])
192192
pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
193193
}
194194
else
195-
log_opts.filename = strdup(DEVNULL);
195+
log_opts.filename = pg_strdup(DEVNULL);
196196

197+
/* WIN32 files do not accept writes from multiple processes */
198+
#ifndef WIN32
199+
log_opts.filename2 = pg_strdup(log_opts.filename);
200+
#else
201+
log_opts.filename2 = pg_strdup(DEVNULL);
202+
#endif
203+
197204
/* if no debug file name, output to the terminal */
198205
if (log_opts.debug && !log_opts.debug_fd)
199206
{

contrib/pg_upgrade/pg_upgrade.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ prepare_new_cluster(void)
193193
prep_status("Analyzing all rows in the new cluster");
194194
exec_prog(true,
195195
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
196-
"--all --analyze >> %s 2>&1" SYSTEMQUOTE,
197-
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
196+
"--all --analyze >> \"%s\" 2>&1" SYSTEMQUOTE,
197+
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
198198
check_ok();
199199

200200
/*
@@ -206,8 +206,8 @@ prepare_new_cluster(void)
206206
prep_status("Freezing all rows on the new cluster");
207207
exec_prog(true,
208208
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
209-
"--all --freeze >> %s 2>&1" SYSTEMQUOTE,
210-
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
209+
"--all --freeze >> \"%s\" 2>&1" SYSTEMQUOTE,
210+
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
211211
check_ok();
212212

213213
get_pg_database_relfilenode(&new_cluster);
@@ -245,7 +245,7 @@ prepare_new_databases(void)
245245
"--no-psqlrc --port %d --username \"%s\" "
246246
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
247247
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
248-
GLOBALS_DUMP_FILE, log_opts.filename);
248+
GLOBALS_DUMP_FILE, log_opts.filename2);
249249
check_ok();
250250

251251
/* we load this to get a current list of databases */
@@ -276,7 +276,7 @@ create_new_objects(void)
276276
"--no-psqlrc --port %d --username \"%s\" "
277277
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
278278
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
279-
DB_DUMP_FILE, log_opts.filename);
279+
DB_DUMP_FILE, log_opts.filename2);
280280
check_ok();
281281

282282
/* regenerate now that we have objects in the databases */
@@ -324,7 +324,7 @@ copy_clog_xlog_xid(void)
324324
exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -l %u,%u,%u \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
325325
new_cluster.bindir, old_cluster.controldata.chkpnt_tli,
326326
old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
327-
new_cluster.pgdata, log_opts.filename);
327+
new_cluster.pgdata, log_opts.filename2);
328328
check_ok();
329329
}
330330

contrib/pg_upgrade/pg_upgrade.h

+10
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ typedef struct
199199
typedef struct
200200
{
201201
char *filename; /* name of log file (may be /dev/null) */
202+
/*
203+
* WIN32 files do not accept writes from multiple processes
204+
*
205+
* On Win32, we can't send both pg_upgrade output and command output to the
206+
* same file because we get the error: "The process cannot access the file
207+
* because it is being used by another process." so we have to send all
208+
* other output to 'nul'. Therefore, we set this to DEVNULL on Win32, and
209+
* it equals 'filename' on all other platforms.
210+
*/
211+
char *filename2;
202212
FILE *fd; /* log FILE */
203213
bool debug; /* TRUE -> log more information */
204214
FILE *debug_fd; /* debug-level log FILE */

contrib/pg_upgrade/server.c

+4-24
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,6 @@ start_postmaster(ClusterInfo *cluster)
147147
bool exit_hook_registered = false;
148148
int pg_ctl_return = 0;
149149

150-
#ifndef WIN32
151-
char *output_filename = log_opts.filename;
152-
#else
153-
154-
/*
155-
* On Win32, we can't send both pg_upgrade output and pg_ctl output to the
156-
* same file because we get the error: "The process cannot access the file
157-
* because it is being used by another process." so we have to send all
158-
* other output to 'nul'.
159-
*/
160-
char *output_filename = DEVNULL;
161-
#endif
162-
163150
if (!exit_hook_registered)
164151
{
165152
#ifdef HAVE_ATEXIT
@@ -180,11 +167,11 @@ start_postmaster(ClusterInfo *cluster)
180167
snprintf(cmd, sizeof(cmd),
181168
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" "
182169
"-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
183-
cluster->bindir, output_filename, cluster->pgdata, cluster->port,
170+
cluster->bindir, log_opts.filename2, cluster->pgdata, cluster->port,
184171
(cluster->controldata.cat_ver >=
185172
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" :
186173
"-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
187-
log_opts.filename);
174+
log_opts.filename2);
188175

189176
/*
190177
* Don't throw an error right away, let connecting throw the error because
@@ -221,13 +208,6 @@ stop_postmaster(bool fast)
221208
const char *bindir;
222209
const char *datadir;
223210

224-
#ifndef WIN32
225-
char *output_filename = log_opts.filename;
226-
#else
227-
/* See comment in start_postmaster() about why win32 output is ignored. */
228-
char *output_filename = DEVNULL;
229-
#endif
230-
231211
if (os_info.running_cluster == &old_cluster)
232212
{
233213
bindir = old_cluster.bindir;
@@ -244,8 +224,8 @@ stop_postmaster(bool fast)
244224
snprintf(cmd, sizeof(cmd),
245225
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> "
246226
"\"%s\" 2>&1" SYSTEMQUOTE,
247-
bindir, output_filename, datadir, fast ? "-m fast" : "",
248-
output_filename);
227+
bindir, log_opts.filename2, datadir, fast ? "-m fast" : "",
228+
log_opts.filename2);
249229

250230
exec_prog(fast ? false : true, "%s", cmd);
251231

0 commit comments

Comments
 (0)