mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
pg_upgrade: preserve database and relation minmxid values
Also set these values for pre-9.3 old clusters that don't have values to preserve. Analysis by Alvaro Backpatch through 9.3
This commit is contained in:
@ -47,7 +47,7 @@ static void prepare_new_cluster(void);
|
||||
static void prepare_new_databases(void);
|
||||
static void create_new_objects(void);
|
||||
static void copy_clog_xlog_xid(void);
|
||||
static void set_frozenxids(void);
|
||||
static void set_frozenxids(bool minmxid_only);
|
||||
static void setup(char *argv0, bool *live_check);
|
||||
static void cleanup(void);
|
||||
|
||||
@ -251,8 +251,8 @@ prepare_new_cluster(void)
|
||||
/*
|
||||
* We do freeze after analyze so pg_statistic is also frozen. template0 is
|
||||
* not frozen here, but data rows were frozen by initdb, and we set its
|
||||
* datfrozenxid and relfrozenxids later to match the new xid counter
|
||||
* later.
|
||||
* datfrozenxid, relfrozenxids, and relminmxid later to match the new xid
|
||||
* counter later.
|
||||
*/
|
||||
prep_status("Freezing all rows on the new cluster");
|
||||
exec_prog(UTILITY_LOG_FILE, NULL, true,
|
||||
@ -274,7 +274,7 @@ prepare_new_databases(void)
|
||||
* set.
|
||||
*/
|
||||
|
||||
set_frozenxids();
|
||||
set_frozenxids(false);
|
||||
|
||||
prep_status("Restoring global objects in the new cluster");
|
||||
|
||||
@ -357,6 +357,13 @@ create_new_objects(void)
|
||||
end_progress_output();
|
||||
check_ok();
|
||||
|
||||
/*
|
||||
* We don't have minmxids for databases or relations in pre-9.3
|
||||
* clusters, so set those after we have restores the schemas.
|
||||
*/
|
||||
if (GET_MAJOR_VERSION(old_cluster.major_version) < 903)
|
||||
set_frozenxids(true);
|
||||
|
||||
/* regenerate now that we have objects in the databases */
|
||||
get_db_and_rel_infos(&new_cluster);
|
||||
|
||||
@ -498,7 +505,7 @@ copy_clog_xlog_xid(void)
|
||||
*/
|
||||
static
|
||||
void
|
||||
set_frozenxids(void)
|
||||
set_frozenxids(bool minmxid_only)
|
||||
{
|
||||
int dbnum;
|
||||
PGconn *conn,
|
||||
@ -508,15 +515,25 @@ set_frozenxids(void)
|
||||
int i_datname;
|
||||
int i_datallowconn;
|
||||
|
||||
prep_status("Setting frozenxid counters in new cluster");
|
||||
if (!minmxid_only)
|
||||
prep_status("Setting frozenxid and minmxid counters in new cluster");
|
||||
else
|
||||
prep_status("Setting minmxid counter in new cluster");
|
||||
|
||||
conn_template1 = connectToServer(&new_cluster, "template1");
|
||||
|
||||
/* set pg_database.datfrozenxid */
|
||||
if (!minmxid_only)
|
||||
/* set pg_database.datfrozenxid */
|
||||
PQclear(executeQueryOrDie(conn_template1,
|
||||
"UPDATE pg_catalog.pg_database "
|
||||
"SET datfrozenxid = '%u'",
|
||||
old_cluster.controldata.chkpnt_nxtxid));
|
||||
|
||||
/* set pg_database.datminmxid */
|
||||
PQclear(executeQueryOrDie(conn_template1,
|
||||
"UPDATE pg_catalog.pg_database "
|
||||
"SET datfrozenxid = '%u'",
|
||||
old_cluster.controldata.chkpnt_nxtxid));
|
||||
"SET datminmxid = '%u'",
|
||||
old_cluster.controldata.chkpnt_nxtmulti));
|
||||
|
||||
/* get database names */
|
||||
dbres = executeQueryOrDie(conn_template1,
|
||||
@ -534,10 +551,10 @@ set_frozenxids(void)
|
||||
|
||||
/*
|
||||
* We must update databases where datallowconn = false, e.g.
|
||||
* template0, because autovacuum increments their datfrozenxids and
|
||||
* relfrozenxids even if autovacuum is turned off, and even though all
|
||||
* the data rows are already frozen To enable this, we temporarily
|
||||
* change datallowconn.
|
||||
* template0, because autovacuum increments their datfrozenxids,
|
||||
* relfrozenxids, and relminmxid even if autovacuum is turned off,
|
||||
* and even though all the data rows are already frozen To enable
|
||||
* this, we temporarily change datallowconn.
|
||||
*/
|
||||
if (strcmp(datallowconn, "f") == 0)
|
||||
PQclear(executeQueryOrDie(conn_template1,
|
||||
@ -547,13 +564,22 @@ set_frozenxids(void)
|
||||
|
||||
conn = connectToServer(&new_cluster, datname);
|
||||
|
||||
/* set pg_class.relfrozenxid */
|
||||
if (!minmxid_only)
|
||||
/* set pg_class.relfrozenxid */
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"UPDATE pg_catalog.pg_class "
|
||||
"SET relfrozenxid = '%u' "
|
||||
/* only heap, materialized view, and TOAST are vacuumed */
|
||||
"WHERE relkind IN ('r', 'm', 't')",
|
||||
old_cluster.controldata.chkpnt_nxtxid));
|
||||
|
||||
/* set pg_class.relminmxid */
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"UPDATE pg_catalog.pg_class "
|
||||
"SET relfrozenxid = '%u' "
|
||||
"SET relminmxid = '%u' "
|
||||
/* only heap, materialized view, and TOAST are vacuumed */
|
||||
"WHERE relkind IN ('r', 'm', 't')",
|
||||
old_cluster.controldata.chkpnt_nxtxid));
|
||||
old_cluster.controldata.chkpnt_nxtmulti));
|
||||
PQfinish(conn);
|
||||
|
||||
/* Reset datallowconn flag */
|
||||
|
Reference in New Issue
Block a user