mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
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.
This commit is contained in:
parent
6b43fddee4
commit
17a16eeb7c
@ -170,7 +170,7 @@ issue_warnings(char *sequence_script_file_name)
|
|||||||
"--no-psqlrc --port %d --username \"%s\" "
|
"--no-psqlrc --port %d --username \"%s\" "
|
||||||
"-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
"-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, new_cluster.port, os_info.user,
|
new_cluster.bindir, new_cluster.port, os_info.user,
|
||||||
sequence_script_file_name, log_opts.filename);
|
sequence_script_file_name, log_opts.filename2);
|
||||||
unlink(sequence_script_file_name);
|
unlink(sequence_script_file_name);
|
||||||
check_ok();
|
check_ok();
|
||||||
}
|
}
|
||||||
|
@ -192,8 +192,15 @@ parseCommandLine(int argc, char *argv[])
|
|||||||
pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
|
pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log_opts.filename = strdup(DEVNULL);
|
log_opts.filename = pg_strdup(DEVNULL);
|
||||||
|
|
||||||
|
/* WIN32 files do not accept writes from multiple processes */
|
||||||
|
#ifndef WIN32
|
||||||
|
log_opts.filename2 = pg_strdup(log_opts.filename);
|
||||||
|
#else
|
||||||
|
log_opts.filename2 = pg_strdup(DEVNULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* if no debug file name, output to the terminal */
|
/* if no debug file name, output to the terminal */
|
||||||
if (log_opts.debug && !log_opts.debug_fd)
|
if (log_opts.debug && !log_opts.debug_fd)
|
||||||
{
|
{
|
||||||
|
@ -193,8 +193,8 @@ prepare_new_cluster(void)
|
|||||||
prep_status("Analyzing all rows in the new cluster");
|
prep_status("Analyzing all rows in the new cluster");
|
||||||
exec_prog(true,
|
exec_prog(true,
|
||||||
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
||||||
"--all --analyze >> %s 2>&1" SYSTEMQUOTE,
|
"--all --analyze >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
|
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
|
||||||
check_ok();
|
check_ok();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -206,8 +206,8 @@ prepare_new_cluster(void)
|
|||||||
prep_status("Freezing all rows on the new cluster");
|
prep_status("Freezing all rows on the new cluster");
|
||||||
exec_prog(true,
|
exec_prog(true,
|
||||||
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
||||||
"--all --freeze >> %s 2>&1" SYSTEMQUOTE,
|
"--all --freeze >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
|
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
|
||||||
check_ok();
|
check_ok();
|
||||||
|
|
||||||
get_pg_database_relfilenode(&new_cluster);
|
get_pg_database_relfilenode(&new_cluster);
|
||||||
@ -245,7 +245,7 @@ prepare_new_databases(void)
|
|||||||
"--no-psqlrc --port %d --username \"%s\" "
|
"--no-psqlrc --port %d --username \"%s\" "
|
||||||
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
|
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
|
||||||
GLOBALS_DUMP_FILE, log_opts.filename);
|
GLOBALS_DUMP_FILE, log_opts.filename2);
|
||||||
check_ok();
|
check_ok();
|
||||||
|
|
||||||
/* we load this to get a current list of databases */
|
/* we load this to get a current list of databases */
|
||||||
@ -276,7 +276,7 @@ create_new_objects(void)
|
|||||||
"--no-psqlrc --port %d --username \"%s\" "
|
"--no-psqlrc --port %d --username \"%s\" "
|
||||||
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
|
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
|
||||||
DB_DUMP_FILE, log_opts.filename);
|
DB_DUMP_FILE, log_opts.filename2);
|
||||||
check_ok();
|
check_ok();
|
||||||
|
|
||||||
/* regenerate now that we have objects in the databases */
|
/* regenerate now that we have objects in the databases */
|
||||||
@ -324,7 +324,7 @@ copy_clog_xlog_xid(void)
|
|||||||
exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -l %u,%u,%u \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
|
exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -l %u,%u,%u \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
new_cluster.bindir, old_cluster.controldata.chkpnt_tli,
|
new_cluster.bindir, old_cluster.controldata.chkpnt_tli,
|
||||||
old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
|
old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
|
||||||
new_cluster.pgdata, log_opts.filename);
|
new_cluster.pgdata, log_opts.filename2);
|
||||||
check_ok();
|
check_ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +199,16 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *filename; /* name of log file (may be /dev/null) */
|
char *filename; /* name of log file (may be /dev/null) */
|
||||||
|
/*
|
||||||
|
* WIN32 files do not accept writes from multiple processes
|
||||||
|
*
|
||||||
|
* 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 we have to send all
|
||||||
|
* other output to 'nul'. Therefore, we set this to DEVNULL on Win32, and
|
||||||
|
* it equals 'filename' on all other platforms.
|
||||||
|
*/
|
||||||
|
char *filename2;
|
||||||
FILE *fd; /* log FILE */
|
FILE *fd; /* log FILE */
|
||||||
bool debug; /* TRUE -> log more information */
|
bool debug; /* TRUE -> log more information */
|
||||||
FILE *debug_fd; /* debug-level log FILE */
|
FILE *debug_fd; /* debug-level log FILE */
|
||||||
|
@ -147,19 +147,6 @@ start_postmaster(ClusterInfo *cluster)
|
|||||||
bool exit_hook_registered = false;
|
bool exit_hook_registered = false;
|
||||||
int pg_ctl_return = 0;
|
int pg_ctl_return = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
char *output_filename = log_opts.filename;
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* On Win32, we can't send both pg_upgrade 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 all
|
|
||||||
* other output to 'nul'.
|
|
||||||
*/
|
|
||||||
char *output_filename = DEVNULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!exit_hook_registered)
|
if (!exit_hook_registered)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_ATEXIT
|
#ifdef HAVE_ATEXIT
|
||||||
@ -180,11 +167,11 @@ start_postmaster(ClusterInfo *cluster)
|
|||||||
snprintf(cmd, sizeof(cmd),
|
snprintf(cmd, sizeof(cmd),
|
||||||
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" "
|
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" "
|
||||||
"-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
|
"-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
cluster->bindir, output_filename, cluster->pgdata, cluster->port,
|
cluster->bindir, log_opts.filename2, cluster->pgdata, cluster->port,
|
||||||
(cluster->controldata.cat_ver >=
|
(cluster->controldata.cat_ver >=
|
||||||
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" :
|
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" :
|
||||||
"-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
|
"-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
|
||||||
log_opts.filename);
|
log_opts.filename2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't throw an error right away, let connecting throw the error because
|
* Don't throw an error right away, let connecting throw the error because
|
||||||
@ -221,13 +208,6 @@ stop_postmaster(bool fast)
|
|||||||
const char *bindir;
|
const char *bindir;
|
||||||
const char *datadir;
|
const char *datadir;
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
char *output_filename = log_opts.filename;
|
|
||||||
#else
|
|
||||||
/* See comment in start_postmaster() about why win32 output is ignored. */
|
|
||||||
char *output_filename = DEVNULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (os_info.running_cluster == &old_cluster)
|
if (os_info.running_cluster == &old_cluster)
|
||||||
{
|
{
|
||||||
bindir = old_cluster.bindir;
|
bindir = old_cluster.bindir;
|
||||||
@ -244,8 +224,8 @@ stop_postmaster(bool fast)
|
|||||||
snprintf(cmd, sizeof(cmd),
|
snprintf(cmd, sizeof(cmd),
|
||||||
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> "
|
SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> "
|
||||||
"\"%s\" 2>&1" SYSTEMQUOTE,
|
"\"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
bindir, output_filename, datadir, fast ? "-m fast" : "",
|
bindir, log_opts.filename2, datadir, fast ? "-m fast" : "",
|
||||||
output_filename);
|
log_opts.filename2);
|
||||||
|
|
||||||
exec_prog(fast ? false : true, "%s", cmd);
|
exec_prog(fast ? false : true, "%s", cmd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user