*
* main source file
*
- * Copyright (c) 2010, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2011, PostgreSQL Global Development Group
* contrib/pg_upgrade/pg_upgrade.c
*/
+/*
+ * To simplify the upgrade process, we force certain system items to be
+ * consistent between old and new clusters:
+ *
+ * We control all assignments of pg_class.relfilenode so we can keep the
+ * same relfilenodes for old and new files. The only exception is
+ * pg_largeobject, pg_largeobject_metadata, and its indexes, which can
+ * change due to a cluster, reindex, or vacuum full. (We don't create
+ * those so have no control over their oid/relfilenode values.)
+ *
+ * While pg_class.oid and pg_class.relfilenode are intially the same, they
+ * can diverge due to cluster, reindex, or vacuum full. The new cluster
+ * will again have matching pg_class.relfilenode and pg_class.oid values,
+ * but based on the new relfilenode value, so the old/new oids might
+ * differ.
+ *
+ * We control all assignments of pg_type.oid because these are stored
+ * in composite types.
+ */
+
+
+
#include "pg_upgrade.h"
#ifdef HAVE_LANGINFO_H
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
check_new_cluster();
report_clusters_compatible();
- pg_log(PG_REPORT, "\nPerforming Migration\n");
- pg_log(PG_REPORT, "--------------------\n");
+ pg_log(PG_REPORT, "\nPerforming Upgrade\n");
+ pg_log(PG_REPORT, "------------------\n");
disable_old_cluster();
prepare_new_cluster();
prep_status("Setting next oid for new cluster");
exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -o %u \"%s\" > "
DEVNULL SYSTEMQUOTE,
- new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata);
+ new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata);
check_ok();
create_script_for_old_cluster_deletion(&deletion_script_file_name);
exec_prog(true,
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
"--all --analyze >> %s 2>&1" SYSTEMQUOTE,
- new_cluster.bindir, new_cluster.port, os_info.user, log.filename);
+ new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
check_ok();
/*
exec_prog(true,
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
"--all --freeze >> %s 2>&1" SYSTEMQUOTE,
- new_cluster.bindir, new_cluster.port, os_info.user, log.filename);
+ new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
check_ok();
- get_pg_database_relfilenode(CLUSTER_NEW);
+ get_pg_database_relfilenode(&new_cluster);
}
prepare_new_databases(void)
{
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
/*
* We set autovacuum_freeze_max_age to its maximum value so autovacuum
prep_status("Creating databases in the new cluster");
exec_prog(true,
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
- /* --no-psqlrc prevents AUTOCOMMIT=off */
+ /* --no-psqlrc prevents AUTOCOMMIT=off */
"--no-psqlrc --port %d --username \"%s\" "
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
- GLOBALS_DUMP_FILE, log.filename);
+ GLOBALS_DUMP_FILE, log_opts.filename);
check_ok();
- get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
+ get_db_and_rel_infos(&new_cluster);
stop_postmaster(false, false);
}
create_new_objects(void)
{
/* -- NEW -- */
- start_postmaster(CLUSTER_NEW, false);
+ start_postmaster(&new_cluster, false);
install_support_functions();
"--no-psqlrc --port %d --username \"%s\" "
"-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
- DB_DUMP_FILE, log.filename);
+ DB_DUMP_FILE, log_opts.filename);
check_ok();
/* regenerate now that we have db schemas */
dbarr_free(&new_cluster.dbarr);
- get_db_and_rel_infos(&new_cluster.dbarr, CLUSTER_NEW);
+ get_db_and_rel_infos(&new_cluster);
uninstall_support_functions();
snprintf(old_clog_path, sizeof(old_clog_path), "%s/pg_clog", old_cluster.pgdata);
snprintf(new_clog_path, sizeof(new_clog_path), "%s/pg_clog", new_cluster.pgdata);
- if (rmtree(new_clog_path, true) != true)
+ if (!rmtree(new_clog_path, true))
pg_log(PG_FATAL, "Unable to delete directory %s\n", new_clog_path);
check_ok();
prep_status("Copying old commit clogs to new server");
- /* libpgport's copydir() doesn't work in FRONTEND code */
#ifndef WIN32
exec_prog(true, SYSTEMQUOTE "%s \"%s\" \"%s\"" SYSTEMQUOTE,
"cp -Rf",
/* set the next transaction id of the new cluster */
prep_status("Setting next transaction id for new cluster");
exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -f -x %u \"%s\" > " DEVNULL SYSTEMQUOTE,
- new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid, new_cluster.pgdata);
+ 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, SYSTEMQUOTE "\"%s/pg_resetxlog\" -l %u,%u,%u \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
new_cluster.bindir, old_cluster.controldata.chkpnt_tli,
- old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
- new_cluster.pgdata, log.filename);
+ old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
+ new_cluster.pgdata, log_opts.filename);
check_ok();
}
prep_status("Setting frozenxid counters in new cluster");
- conn_template1 = connectToServer("template1", CLUSTER_NEW);
+ conn_template1 = connectToServer(&new_cluster, "template1");
/* set pg_database.datfrozenxid */
PQclear(executeQueryOrDie(conn_template1,
"SET datallowconn = true "
"WHERE datname = '%s'", datname));
- conn = connectToServer(datname, CLUSTER_NEW);
+ conn = connectToServer(&new_cluster, datname);
/* set pg_class.relfrozenxid */
PQclear(executeQueryOrDie(conn,
dbarr_free(&old_cluster.dbarr);
dbarr_free(&new_cluster.dbarr);
- pg_free(log.filename);
+ pg_free(log_opts.filename);
pg_free(os_info.user);
- pg_free(old_cluster.major_version_str);
- pg_free(new_cluster.major_version_str);
pg_free(old_cluster.controldata.lc_collate);
pg_free(new_cluster.controldata.lc_collate);
pg_free(old_cluster.controldata.lc_ctype);
pg_free(old_cluster.tablespace_suffix);
pg_free(new_cluster.tablespace_suffix);
- if (log.fd != NULL)
+ if (log_opts.fd != NULL)
{
- fclose(log.fd);
- log.fd = NULL;
+ fclose(log_opts.fd);
+ log_opts.fd = NULL;
}
- if (log.debug_fd)
- fclose(log.debug_fd);
+ if (log_opts.debug_fd)
+ fclose(log_opts.debug_fd);
snprintf(filename, sizeof(filename), "%s/%s", os_info.cwd, ALL_DUMP_FILE);
unlink(filename);