mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
pg_upgrade: Fix exec_prog API to be less flaky
The previous signature made it very easy to pass something other than the printf-format specifier in the corresponding position, without any warning from the compiler. While at it, move some of the escaping, redirecting and quoting responsibilities from the callers into exec_prog() itself. This makes the callsites cleaner.
This commit is contained in:
@ -140,11 +140,10 @@ main(int argc, char **argv)
|
||||
* because there is no need to have the schema load use new oids.
|
||||
*/
|
||||
prep_status("Setting next OID for new cluster");
|
||||
exec_prog(true, true, UTILITY_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE "\"%s/pg_resetxlog\" -o %u \"%s\" >> \"%s\" 2>&1"
|
||||
SYSTEMQUOTE,
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
"\"%s/pg_resetxlog\" -o %u \"%s\"",
|
||||
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid,
|
||||
new_cluster.pgdata, UTILITY_LOG_FILE);
|
||||
new_cluster.pgdata);
|
||||
check_ok();
|
||||
|
||||
create_script_for_cluster_analyze(&analyze_script_file_name);
|
||||
@ -211,11 +210,10 @@ prepare_new_cluster(void)
|
||||
* --analyze so autovacuum doesn't update statistics later
|
||||
*/
|
||||
prep_status("Analyzing all rows in the new cluster");
|
||||
exec_prog(true, true, UTILITY_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
||||
"--all --analyze %s >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
"\"%s/vacuumdb\" --port %d --username \"%s\" --all --analyze %s",
|
||||
new_cluster.bindir, new_cluster.port, os_info.user,
|
||||
log_opts.verbose ? "--verbose" : "", UTILITY_LOG_FILE);
|
||||
log_opts.verbose ? "--verbose" : "");
|
||||
check_ok();
|
||||
|
||||
/*
|
||||
@ -225,11 +223,10 @@ prepare_new_cluster(void)
|
||||
* later.
|
||||
*/
|
||||
prep_status("Freezing all rows on the new cluster");
|
||||
exec_prog(true, true, UTILITY_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
|
||||
"--all --freeze %s >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
"\"%s/vacuumdb\" --port %d --username \"%s\" --all --freeze %s",
|
||||
new_cluster.bindir, new_cluster.port, os_info.user,
|
||||
log_opts.verbose ? "--verbose" : "", UTILITY_LOG_FILE);
|
||||
log_opts.verbose ? "--verbose" : "");
|
||||
check_ok();
|
||||
|
||||
get_pg_database_relfilenode(&new_cluster);
|
||||
@ -263,14 +260,10 @@ prepare_new_databases(void)
|
||||
* support functions in template1 but pg_dumpall creates database using
|
||||
* the template0 template.
|
||||
*/
|
||||
exec_prog(true, true, RESTORE_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE "\"%s/psql\" --echo-queries "
|
||||
"--set ON_ERROR_STOP=on "
|
||||
/* --no-psqlrc prevents AUTOCOMMIT=off */
|
||||
"--no-psqlrc --port %d --username \"%s\" "
|
||||
"-f \"%s\" --dbname template1 >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
exec_prog(RESTORE_LOG_FILE, NULL, true,
|
||||
"\"%s/psql\" " EXEC_PSQL_ARGS " --port %d --username \"%s\" -f \"%s\"",
|
||||
new_cluster.bindir, new_cluster.port, os_info.user,
|
||||
GLOBALS_DUMP_FILE, RESTORE_LOG_FILE);
|
||||
GLOBALS_DUMP_FILE);
|
||||
check_ok();
|
||||
|
||||
/* we load this to get a current list of databases */
|
||||
@ -296,13 +289,10 @@ create_new_objects(void)
|
||||
check_ok();
|
||||
|
||||
prep_status("Restoring database schema to new cluster");
|
||||
exec_prog(true, true, RESTORE_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE "\"%s/psql\" --echo-queries "
|
||||
"--set ON_ERROR_STOP=on "
|
||||
"--no-psqlrc --port %d --username \"%s\" "
|
||||
"-f \"%s\" --dbname template1 >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
exec_prog(RESTORE_LOG_FILE, NULL, true,
|
||||
"\"%s/psql\" " EXEC_PSQL_ARGS " --port %d --username \"%s\" -f \"%s\"",
|
||||
new_cluster.bindir, new_cluster.port, os_info.user,
|
||||
DB_DUMP_FILE, RESTORE_LOG_FILE);
|
||||
DB_DUMP_FILE);
|
||||
check_ok();
|
||||
|
||||
/* regenerate now that we have objects in the databases */
|
||||
@ -331,16 +321,14 @@ copy_subdir_files(char *subdir)
|
||||
|
||||
prep_status("Copying old %s to new server", subdir);
|
||||
|
||||
exec_prog(true, false, UTILITY_LOG_FILE, NULL,
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
#ifndef WIN32
|
||||
SYSTEMQUOTE "%s \"%s\" \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
"cp -Rf",
|
||||
"cp -Rf \"%s\" \"%s\"",
|
||||
#else
|
||||
/* flags: everything, no confirm, quiet, overwrite read-only */
|
||||
SYSTEMQUOTE "%s \"%s\" \"%s\\\" >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||
"xcopy /e /y /q /r",
|
||||
"xcopy /e /y /q /r \"%s\" \"%s\\\"",
|
||||
#endif
|
||||
old_path, new_path, UTILITY_LOG_FILE);
|
||||
old_path, new_path);
|
||||
|
||||
check_ok();
|
||||
}
|
||||
@ -353,22 +341,18 @@ copy_clog_xlog_xid(void)
|
||||
|
||||
/* set the next transaction id of the new cluster */
|
||||
prep_status("Setting next transaction ID for new cluster");
|
||||
exec_prog(true, true, UTILITY_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE
|
||||
"\"%s/pg_resetxlog\" -f -x %u \"%s\" >> \"%s\" 2>&1"
|
||||
SYSTEMQUOTE, new_cluster.bindir,
|
||||
old_cluster.controldata.chkpnt_nxtxid,
|
||||
new_cluster.pgdata, UTILITY_LOG_FILE);
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
"\"%s/pg_resetxlog\" -f -x %u \"%s\"",
|
||||
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid,
|
||||
new_cluster.pgdata);
|
||||
check_ok();
|
||||
|
||||
/* now reset the wal archives in the new cluster */
|
||||
prep_status("Resetting WAL archives");
|
||||
exec_prog(true, true, UTILITY_LOG_FILE, NULL,
|
||||
SYSTEMQUOTE
|
||||
"\"%s/pg_resetxlog\" -l %s \"%s\" >> \"%s\" 2>&1"
|
||||
SYSTEMQUOTE, new_cluster.bindir,
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
"\"%s/pg_resetxlog\" -l %s \"%s\"", new_cluster.bindir,
|
||||
old_cluster.controldata.nextxlogfile,
|
||||
new_cluster.pgdata, UTILITY_LOG_FILE);
|
||||
new_cluster.pgdata);
|
||||
check_ok();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user