Commit a61daa14 authored by Bruce Momjian's avatar Bruce Momjian

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
parent a36a8fa3
...@@ -46,7 +46,7 @@ static void prepare_new_cluster(void); ...@@ -46,7 +46,7 @@ static void prepare_new_cluster(void);
static void prepare_new_databases(void); static void prepare_new_databases(void);
static void create_new_objects(void); static void create_new_objects(void);
static void copy_clog_xlog_xid(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 setup(char *argv0, bool *live_check);
static void cleanup(void); static void cleanup(void);
...@@ -250,8 +250,8 @@ prepare_new_cluster(void) ...@@ -250,8 +250,8 @@ prepare_new_cluster(void)
/* /*
* We do freeze after analyze so pg_statistic is also frozen. template0 is * 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 * not frozen here, but data rows were frozen by initdb, and we set its
* datfrozenxid and relfrozenxids later to match the new xid counter * datfrozenxid, relfrozenxids, and relminmxid later to match the new xid
* later. * counter later.
*/ */
prep_status("Freezing all rows on the new cluster"); prep_status("Freezing all rows on the new cluster");
exec_prog(UTILITY_LOG_FILE, NULL, true, exec_prog(UTILITY_LOG_FILE, NULL, true,
...@@ -273,7 +273,7 @@ prepare_new_databases(void) ...@@ -273,7 +273,7 @@ prepare_new_databases(void)
* set. * set.
*/ */
set_frozenxids(); set_frozenxids(false);
prep_status("Restoring global objects in the new cluster"); prep_status("Restoring global objects in the new cluster");
...@@ -356,6 +356,13 @@ create_new_objects(void) ...@@ -356,6 +356,13 @@ create_new_objects(void)
end_progress_output(); end_progress_output();
check_ok(); 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 */ /* regenerate now that we have objects in the databases */
get_db_and_rel_infos(&new_cluster); get_db_and_rel_infos(&new_cluster);
...@@ -489,15 +496,15 @@ copy_clog_xlog_xid(void) ...@@ -489,15 +496,15 @@ copy_clog_xlog_xid(void)
/* /*
* set_frozenxids() * set_frozenxids()
* *
* We have frozen all xids, so set relfrozenxid and datfrozenxid * We have frozen all xids, so set datfrozenxid, relfrozenxid, and
* to be the old cluster's xid counter, which we just set in the new * relminmxid to be the old cluster's xid counter, which we just set
* cluster. User-table frozenxid values will be set by pg_dump * in the new cluster. User-table frozenxid and minmxid values will
* --binary-upgrade, but objects not set by the pg_dump must have * be set by pg_dump --binary-upgrade, but objects not set by the pg_dump
* proper frozen counters. * must have proper frozen counters.
*/ */
static static
void void
set_frozenxids(void) set_frozenxids(bool minmxid_only)
{ {
int dbnum; int dbnum;
PGconn *conn, PGconn *conn,
...@@ -507,15 +514,25 @@ set_frozenxids(void) ...@@ -507,15 +514,25 @@ set_frozenxids(void)
int i_datname; int i_datname;
int i_datallowconn; 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"); 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, PQclear(executeQueryOrDie(conn_template1,
"UPDATE pg_catalog.pg_database " "UPDATE pg_catalog.pg_database "
"SET datfrozenxid = '%u'", "SET datminmxid = '%u'",
old_cluster.controldata.chkpnt_nxtxid)); old_cluster.controldata.chkpnt_nxtmulti));
/* get database names */ /* get database names */
dbres = executeQueryOrDie(conn_template1, dbres = executeQueryOrDie(conn_template1,
...@@ -533,10 +550,10 @@ set_frozenxids(void) ...@@ -533,10 +550,10 @@ set_frozenxids(void)
/* /*
* We must update databases where datallowconn = false, e.g. * We must update databases where datallowconn = false, e.g.
* template0, because autovacuum increments their datfrozenxids and * template0, because autovacuum increments their datfrozenxids,
* relfrozenxids even if autovacuum is turned off, and even though all * relfrozenxids, and relminmxid even if autovacuum is turned off,
* the data rows are already frozen To enable this, we temporarily * and even though all the data rows are already frozen To enable
* change datallowconn. * this, we temporarily change datallowconn.
*/ */
if (strcmp(datallowconn, "f") == 0) if (strcmp(datallowconn, "f") == 0)
PQclear(executeQueryOrDie(conn_template1, PQclear(executeQueryOrDie(conn_template1,
...@@ -545,13 +562,22 @@ set_frozenxids(void) ...@@ -545,13 +562,22 @@ set_frozenxids(void)
conn = connectToServer(&new_cluster, datname); 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, PQclear(executeQueryOrDie(conn,
"UPDATE pg_catalog.pg_class " "UPDATE pg_catalog.pg_class "
"SET relfrozenxid = '%u' " "SET relminmxid = '%u' "
/* only heap, materialized view, and TOAST are vacuumed */ /* only heap, materialized view, and TOAST are vacuumed */
"WHERE relkind IN ('r', 'm', 't')", "WHERE relkind IN ('r', 'm', 't')",
old_cluster.controldata.chkpnt_nxtxid)); old_cluster.controldata.chkpnt_nxtmulti));
PQfinish(conn); PQfinish(conn);
/* Reset datallowconn flag */ /* Reset datallowconn flag */
......
...@@ -203,10 +203,11 @@ start_postmaster(ClusterInfo *cluster, bool throw_error) ...@@ -203,10 +203,11 @@ start_postmaster(ClusterInfo *cluster, bool throw_error)
/* /*
* Using autovacuum=off disables cleanup vacuum and analyze, but freeze * Using autovacuum=off disables cleanup vacuum and analyze, but freeze
* vacuums can still happen, so we set autovacuum_freeze_max_age to its * vacuums can still happen, so we set autovacuum_freeze_max_age and
* maximum. We assume all datfrozenxid and relfrozen values are less than * autovacuum_multixact_freeze_max_age to their maximums. We assume all
* a gap of 2000000000 from the current xid counter, so autovacuum will * datfrozenxid, relfrozenxid, and relminmxid values are less than a gap
* not touch them. * of 2000000000 from the current xid counter, so autovacuum will not
* touch them.
* *
* Turn off durability requirements to improve object creation speed, and * Turn off durability requirements to improve object creation speed, and
* we only modify the new cluster, so only use it there. If there is a * we only modify the new cluster, so only use it there. If there is a
...@@ -214,11 +215,13 @@ start_postmaster(ClusterInfo *cluster, bool throw_error) ...@@ -214,11 +215,13 @@ start_postmaster(ClusterInfo *cluster, bool throw_error)
* win on ext4. * win on ext4.
*/ */
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
"\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"-p %d%s%s %s%s\" start", "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"-p %d%s%s %s%s%s\" start",
cluster->bindir, SERVER_LOG_FILE, cluster->pgconfig, cluster->port, cluster->bindir, SERVER_LOG_FILE, cluster->pgconfig, 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",
(GET_MAJOR_VERSION(cluster->major_version) >= 903) ?
" -c autovacuum_multixact_freeze_max_age=2000000000" : "",
(cluster == &new_cluster) ? (cluster == &new_cluster) ?
" -c synchronous_commit=off -c fsync=off -c full_page_writes=off" : "", " -c synchronous_commit=off -c fsync=off -c full_page_writes=off" : "",
cluster->pgopts ? cluster->pgopts : "", socket_string); cluster->pgopts ? cluster->pgopts : "", socket_string);
......
...@@ -2156,6 +2156,7 @@ dumpDatabase(Archive *fout) ...@@ -2156,6 +2156,7 @@ dumpDatabase(Archive *fout)
i_collate, i_collate,
i_ctype, i_ctype,
i_frozenxid, i_frozenxid,
i_minmxid,
i_tablespace; i_tablespace;
CatalogId dbCatId; CatalogId dbCatId;
DumpId dbDumpId; DumpId dbDumpId;
...@@ -2165,7 +2166,7 @@ dumpDatabase(Archive *fout) ...@@ -2165,7 +2166,7 @@ dumpDatabase(Archive *fout)
*collate, *collate,
*ctype, *ctype,
*tablespace; *tablespace;
uint32 frozenxid; uint32 frozenxid, minmxid;
datname = PQdb(conn); datname = PQdb(conn);
...@@ -2176,12 +2177,26 @@ dumpDatabase(Archive *fout) ...@@ -2176,12 +2177,26 @@ dumpDatabase(Archive *fout)
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* Get the database owner and parameters from pg_database */ /* Get the database owner and parameters from pg_database */
if (fout->remoteVersion >= 80400) if (fout->remoteVersion >= 90300)
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, " "pg_encoding_to_char(encoding) AS encoding, "
"datcollate, datctype, datfrozenxid, " "datcollate, datctype, datfrozenxid, datminmxid, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
"shobj_description(oid, 'pg_database') AS description "
"FROM pg_database "
"WHERE datname = ",
username_subquery);
appendStringLiteralAH(dbQry, datname, fout);
}
else if (fout->remoteVersion >= 80400)
{
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, "
"datcollate, datctype, datfrozenxid, 0 AS datminmxid, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
"shobj_description(oid, 'pg_database') AS description " "shobj_description(oid, 'pg_database') AS description "
...@@ -2195,7 +2210,7 @@ dumpDatabase(Archive *fout) ...@@ -2195,7 +2210,7 @@ dumpDatabase(Archive *fout)
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, " "pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, datfrozenxid, " "NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
"shobj_description(oid, 'pg_database') AS description " "shobj_description(oid, 'pg_database') AS description "
...@@ -2209,7 +2224,7 @@ dumpDatabase(Archive *fout) ...@@ -2209,7 +2224,7 @@ dumpDatabase(Archive *fout)
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, " "pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, datfrozenxid, " "NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace "
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
...@@ -2222,7 +2237,7 @@ dumpDatabase(Archive *fout) ...@@ -2222,7 +2237,7 @@ dumpDatabase(Archive *fout)
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, " "pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, " "NULL AS datcollate, NULL AS datctype, "
"0 AS datfrozenxid, " "0 AS datfrozenxid, 0 AS datminmxid, "
"NULL AS tablespace " "NULL AS tablespace "
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
...@@ -2237,7 +2252,7 @@ dumpDatabase(Archive *fout) ...@@ -2237,7 +2252,7 @@ dumpDatabase(Archive *fout)
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
"pg_encoding_to_char(encoding) AS encoding, " "pg_encoding_to_char(encoding) AS encoding, "
"NULL AS datcollate, NULL AS datctype, " "NULL AS datcollate, NULL AS datctype, "
"0 AS datfrozenxid, " "0 AS datfrozenxid, 0 AS datminmxid, "
"NULL AS tablespace " "NULL AS tablespace "
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
...@@ -2254,6 +2269,7 @@ dumpDatabase(Archive *fout) ...@@ -2254,6 +2269,7 @@ dumpDatabase(Archive *fout)
i_collate = PQfnumber(res, "datcollate"); i_collate = PQfnumber(res, "datcollate");
i_ctype = PQfnumber(res, "datctype"); i_ctype = PQfnumber(res, "datctype");
i_frozenxid = PQfnumber(res, "datfrozenxid"); i_frozenxid = PQfnumber(res, "datfrozenxid");
i_minmxid = PQfnumber(res, "datminmxid");
i_tablespace = PQfnumber(res, "tablespace"); i_tablespace = PQfnumber(res, "tablespace");
dbCatId.tableoid = atooid(PQgetvalue(res, 0, i_tableoid)); dbCatId.tableoid = atooid(PQgetvalue(res, 0, i_tableoid));
...@@ -2263,6 +2279,7 @@ dumpDatabase(Archive *fout) ...@@ -2263,6 +2279,7 @@ dumpDatabase(Archive *fout)
collate = PQgetvalue(res, 0, i_collate); collate = PQgetvalue(res, 0, i_collate);
ctype = PQgetvalue(res, 0, i_ctype); ctype = PQgetvalue(res, 0, i_ctype);
frozenxid = atooid(PQgetvalue(res, 0, i_frozenxid)); frozenxid = atooid(PQgetvalue(res, 0, i_frozenxid));
minmxid = atooid(PQgetvalue(res, 0, i_minmxid));
tablespace = PQgetvalue(res, 0, i_tablespace); tablespace = PQgetvalue(res, 0, i_tablespace);
appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0", appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
...@@ -2289,11 +2306,11 @@ dumpDatabase(Archive *fout) ...@@ -2289,11 +2306,11 @@ dumpDatabase(Archive *fout)
if (binary_upgrade) if (binary_upgrade)
{ {
appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid and datminmxid.\n");
appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n" appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n"
"SET datfrozenxid = '%u'\n" "SET datfrozenxid = '%u', datminmxid = '%u'\n"
"WHERE datname = ", "WHERE datname = ",
frozenxid); frozenxid, minmxid);
appendStringLiteralAH(creaQry, datname, fout); appendStringLiteralAH(creaQry, datname, fout);
appendPQExpBufferStr(creaQry, ";\n"); appendPQExpBufferStr(creaQry, ";\n");
...@@ -2324,32 +2341,40 @@ dumpDatabase(Archive *fout) ...@@ -2324,32 +2341,40 @@ dumpDatabase(Archive *fout)
/* /*
* pg_largeobject and pg_largeobject_metadata come from the old system * pg_largeobject and pg_largeobject_metadata come from the old system
* intact, so set their relfrozenxids. * intact, so set their relfrozenxids and relminmxids.
*/ */
if (binary_upgrade) if (binary_upgrade)
{ {
PGresult *lo_res; PGresult *lo_res;
PQExpBuffer loFrozenQry = createPQExpBuffer(); PQExpBuffer loFrozenQry = createPQExpBuffer();
PQExpBuffer loOutQry = createPQExpBuffer(); PQExpBuffer loOutQry = createPQExpBuffer();
int i_relfrozenxid; int i_relfrozenxid, i_relminmxid;
/* /*
* pg_largeobject * pg_largeobject
*/ */
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid\n" if (fout->remoteVersion >= 90300)
"FROM pg_catalog.pg_class\n" appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
"WHERE oid = %u;\n", "FROM pg_catalog.pg_class\n"
LargeObjectRelationId); "WHERE oid = %u;\n",
LargeObjectRelationId);
else
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
"FROM pg_catalog.pg_class\n"
"WHERE oid = %u;\n",
LargeObjectRelationId);
lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data); lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
i_relminmxid = PQfnumber(lo_res, "relminmxid");
appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject.relfrozenxid\n"); appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u', relminmxid = '%u'\n"
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)), atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
atoi(PQgetvalue(lo_res, 0, i_relminmxid)),
LargeObjectRelationId); LargeObjectRelationId);
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
"pg_largeobject", NULL, NULL, "", "pg_largeobject", NULL, NULL, "",
...@@ -2368,7 +2393,13 @@ dumpDatabase(Archive *fout) ...@@ -2368,7 +2393,13 @@ dumpDatabase(Archive *fout)
resetPQExpBuffer(loFrozenQry); resetPQExpBuffer(loFrozenQry);
resetPQExpBuffer(loOutQry); resetPQExpBuffer(loOutQry);
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid\n" if (fout->remoteVersion >= 90300)
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
"FROM pg_catalog.pg_class\n"
"WHERE oid = %u;\n",
LargeObjectMetadataRelationId);
else
appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
"FROM pg_catalog.pg_class\n" "FROM pg_catalog.pg_class\n"
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
LargeObjectMetadataRelationId); LargeObjectMetadataRelationId);
...@@ -2376,12 +2407,14 @@ dumpDatabase(Archive *fout) ...@@ -2376,12 +2407,14 @@ dumpDatabase(Archive *fout)
lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data); lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
i_relminmxid = PQfnumber(lo_res, "relminmxid");
appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata.relfrozenxid\n"); appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata relfrozenxid and relminmxid\n");
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u', relminmxid = '%u'\n"
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)), atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
atoi(PQgetvalue(lo_res, 0, i_relminmxid)),
LargeObjectMetadataRelationId); LargeObjectMetadataRelationId);
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
"pg_largeobject_metadata", NULL, NULL, "", "pg_largeobject_metadata", NULL, NULL, "",
...@@ -4255,8 +4288,10 @@ getTables(Archive *fout, int *numTables) ...@@ -4255,8 +4288,10 @@ getTables(Archive *fout, int *numTables)
int i_relhasrules; int i_relhasrules;
int i_relhasoids; int i_relhasoids;
int i_relfrozenxid; int i_relfrozenxid;
int i_relminmxid;
int i_toastoid; int i_toastoid;
int i_toastfrozenxid; int i_toastfrozenxid;
int i_toastminmxid;
int i_relpersistence; int i_relpersistence;
int i_relispopulated; int i_relispopulated;
int i_relreplident; int i_relreplident;
...@@ -4304,8 +4339,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4304,8 +4339,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, c.relhastriggers, " "c.relchecks, c.relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, c.relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"tc.relminmxid AS tminmxid, "
"c.relpersistence, c.relispopulated, " "c.relpersistence, c.relispopulated, "
"c.relreplident, c.relpages, " "c.relreplident, c.relpages, "
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
...@@ -4343,8 +4379,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4343,8 +4379,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, c.relhastriggers, " "c.relchecks, c.relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, c.relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"tc.relminmxid AS tminmxid, "
"c.relpersistence, c.relispopulated, " "c.relpersistence, c.relispopulated, "
"'d' AS relreplident, c.relpages, " "'d' AS relreplident, c.relpages, "
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
...@@ -4382,8 +4419,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4382,8 +4419,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, c.relhastriggers, " "c.relchecks, c.relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"0 AS tminmxid, "
"c.relpersistence, 't' as relispopulated, " "c.relpersistence, 't' as relispopulated, "
"'d' AS relreplident, c.relpages, " "'d' AS relreplident, c.relpages, "
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
...@@ -4419,8 +4457,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4419,8 +4457,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, c.relhastriggers, " "c.relchecks, c.relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"0 AS tminmxid, "
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, c.relpages, " "'d' AS relreplident, c.relpages, "
"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
...@@ -4455,8 +4494,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4455,8 +4494,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, c.relhastriggers, " "c.relchecks, c.relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"0 AS tminmxid, "
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, c.relpages, " "'d' AS relreplident, c.relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4491,8 +4531,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4491,8 +4531,9 @@ getTables(Archive *fout, int *numTables)
"(%s c.relowner) AS rolname, " "(%s c.relowner) AS rolname, "
"c.relchecks, (c.reltriggers <> 0) AS relhastriggers, " "c.relchecks, (c.reltriggers <> 0) AS relhastriggers, "
"c.relhasindex, c.relhasrules, c.relhasoids, " "c.relhasindex, c.relhasrules, c.relhasoids, "
"c.relfrozenxid, tc.oid AS toid, " "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, "
"tc.relfrozenxid AS tfrozenxid, " "tc.relfrozenxid AS tfrozenxid, "
"0 AS tminmxid, "
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, c.relpages, " "'d' AS relreplident, c.relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4527,9 +4568,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4527,9 +4568,9 @@ getTables(Archive *fout, int *numTables)
"(%s relowner) AS rolname, " "(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, " "relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, relhasoids, " "relhasindex, relhasrules, relhasoids, "
"0 AS relfrozenxid, " "0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, " "0 AS toid, "
"0 AS tfrozenxid, " "0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, " "'d' AS relreplident, relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4563,9 +4604,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4563,9 +4604,9 @@ getTables(Archive *fout, int *numTables)
"(%s relowner) AS rolname, " "(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, " "relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, relhasoids, " "relhasindex, relhasrules, relhasoids, "
"0 AS relfrozenxid, " "0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, " "0 AS toid, "
"0 AS tfrozenxid, " "0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, " "'d' AS relreplident, relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4595,9 +4636,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4595,9 +4636,9 @@ getTables(Archive *fout, int *numTables)
"(%s relowner) AS rolname, " "(%s relowner) AS rolname, "
"relchecks, (reltriggers <> 0) AS relhastriggers, " "relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, relhasoids, " "relhasindex, relhasrules, relhasoids, "
"0 AS relfrozenxid, " "0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, " "0 AS toid, "
"0 AS tfrozenxid, " "0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, " "'d' AS relreplident, relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4622,9 +4663,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4622,9 +4663,9 @@ getTables(Archive *fout, int *numTables)
"relchecks, (reltriggers <> 0) AS relhastriggers, " "relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, " "relhasindex, relhasrules, "
"'t'::bool AS relhasoids, " "'t'::bool AS relhasoids, "
"0 AS relfrozenxid, " "0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, " "0 AS toid, "
"0 AS tfrozenxid, " "0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, relpages, " "'d' AS relreplident, relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4659,9 +4700,9 @@ getTables(Archive *fout, int *numTables) ...@@ -4659,9 +4700,9 @@ getTables(Archive *fout, int *numTables)
"relchecks, (reltriggers <> 0) AS relhastriggers, " "relchecks, (reltriggers <> 0) AS relhastriggers, "
"relhasindex, relhasrules, " "relhasindex, relhasrules, "
"'t'::bool AS relhasoids, " "'t'::bool AS relhasoids, "
"0 as relfrozenxid, " "0 AS relfrozenxid, 0 AS relminmxid,"
"0 AS toid, " "0 AS toid, "
"0 AS tfrozenxid, " "0 AS tfrozenxid, 0 AS tminmxid,"
"'p' AS relpersistence, 't' as relispopulated, " "'p' AS relpersistence, 't' as relispopulated, "
"'d' AS relreplident, 0 AS relpages, " "'d' AS relreplident, 0 AS relpages, "
"NULL AS reloftype, " "NULL AS reloftype, "
...@@ -4708,8 +4749,10 @@ getTables(Archive *fout, int *numTables) ...@@ -4708,8 +4749,10 @@ getTables(Archive *fout, int *numTables)
i_relhasrules = PQfnumber(res, "relhasrules"); i_relhasrules = PQfnumber(res, "relhasrules");
i_relhasoids = PQfnumber(res, "relhasoids"); i_relhasoids = PQfnumber(res, "relhasoids");
i_relfrozenxid = PQfnumber(res, "relfrozenxid"); i_relfrozenxid = PQfnumber(res, "relfrozenxid");
i_relminmxid = PQfnumber(res, "relminmxid");
i_toastoid = PQfnumber(res, "toid"); i_toastoid = PQfnumber(res, "toid");
i_toastfrozenxid = PQfnumber(res, "tfrozenxid"); i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
i_toastminmxid = PQfnumber(res, "tminmxid");
i_relpersistence = PQfnumber(res, "relpersistence"); i_relpersistence = PQfnumber(res, "relpersistence");
i_relispopulated = PQfnumber(res, "relispopulated"); i_relispopulated = PQfnumber(res, "relispopulated");
i_relreplident = PQfnumber(res, "relreplident"); i_relreplident = PQfnumber(res, "relreplident");
...@@ -4760,8 +4803,10 @@ getTables(Archive *fout, int *numTables) ...@@ -4760,8 +4803,10 @@ getTables(Archive *fout, int *numTables)
tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident)); tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages)); tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid)); tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid)); tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid)); tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid));
tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
if (PQgetisnull(res, i, i_reloftype)) if (PQgetisnull(res, i, i_reloftype))
tblinfo[i].reloftype = NULL; tblinfo[i].reloftype = NULL;
else else
...@@ -13525,22 +13570,23 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13525,22 +13570,23 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
tbinfo->reloftype); tbinfo->reloftype);
} }
appendPQExpBufferStr(q, "\n-- For binary upgrade, set heap's relfrozenxid\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set heap's relfrozenxid and relminmxid\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u', relminmxid = '%u'\n"
"WHERE oid = ", "WHERE oid = ",
tbinfo->frozenxid); tbinfo->frozenxid, tbinfo->minmxid);
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBufferStr(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
if (tbinfo->toast_oid) if (tbinfo->toast_oid)
{ {
/* We preserve the toast oids, so we can use it during restore */ /* We preserve the toast oids, so we can use it during restore */
appendPQExpBufferStr(q, "\n-- For binary upgrade, set toast's relfrozenxid\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u', relminmxid = '%u'\n"
"WHERE oid = '%u';\n", "WHERE oid = '%u';\n",
tbinfo->toast_frozenxid, tbinfo->toast_oid); tbinfo->toast_frozenxid,
tbinfo->toast_minmxid, tbinfo->toast_oid);
} }
} }
......
...@@ -247,8 +247,10 @@ typedef struct _tableInfo ...@@ -247,8 +247,10 @@ typedef struct _tableInfo
bool hastriggers; /* does it have any triggers? */ bool hastriggers; /* does it have any triggers? */
bool hasoids; /* does it have OIDs? */ bool hasoids; /* does it have OIDs? */
uint32 frozenxid; /* for restore frozen xid */ uint32 frozenxid; /* for restore frozen xid */
uint32 minmxid; /* for restore min multi xid */
Oid toast_oid; /* for restore toast frozen xid */ Oid toast_oid; /* for restore toast frozen xid */
uint32 toast_frozenxid; /* for restore toast frozen xid */ uint32 toast_frozenxid; /* for restore toast frozen xid */
uint32 toast_minmxid; /* for restore toast min multi xid */
int ncheck; /* # of CHECK expressions */ int ncheck; /* # of CHECK expressions */
char *reloftype; /* underlying type for typed table */ char *reloftype; /* underlying type for typed table */
/* these two are set only if table is a sequence owned by a column: */ /* these two are set only if table is a sequence owned by a column: */
......
...@@ -1241,12 +1241,22 @@ dumpCreateDB(PGconn *conn) ...@@ -1241,12 +1241,22 @@ dumpCreateDB(PGconn *conn)
PQclear(res); PQclear(res);
/* Now collect all the information about databases to dump */ /* Now collect all the information about databases to dump */
if (server_version >= 80400) if (server_version >= 90300)
res = executeQuery(conn,
"SELECT datname, "
"coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), "
"datcollate, datctype, datfrozenxid, datminmxid, "
"datistemplate, datacl, datconnlimit, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
"WHERE datallowconn ORDER BY 1");
else if (server_version >= 80400)
res = executeQuery(conn, res = executeQuery(conn,
"SELECT datname, " "SELECT datname, "
"coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), " "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"datcollate, datctype, datfrozenxid, " "datcollate, datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, datconnlimit, " "datistemplate, datacl, datconnlimit, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) " "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
...@@ -1256,7 +1266,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1256,7 +1266,7 @@ dumpCreateDB(PGconn *conn)
"SELECT datname, " "SELECT datname, "
"coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), " "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, datfrozenxid, " "null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, datconnlimit, " "datistemplate, datacl, datconnlimit, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) " "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
...@@ -1266,7 +1276,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1266,7 +1276,7 @@ dumpCreateDB(PGconn *conn)
"SELECT datname, " "SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), " "coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, datfrozenxid, " "null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, -1 as datconnlimit, " "datistemplate, datacl, -1 as datconnlimit, "
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) " "FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
...@@ -1276,7 +1286,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1276,7 +1286,7 @@ dumpCreateDB(PGconn *conn)
"SELECT datname, " "SELECT datname, "
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), " "coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, datfrozenxid, " "null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
"datistemplate, datacl, -1 as datconnlimit, " "datistemplate, datacl, -1 as datconnlimit, "
"'pg_default' AS dattablespace " "'pg_default' AS dattablespace "
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) " "FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
...@@ -1288,7 +1298,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1288,7 +1298,7 @@ dumpCreateDB(PGconn *conn)
"(select usename from pg_shadow where usesysid=datdba), " "(select usename from pg_shadow where usesysid=datdba), "
"(select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), " "(select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, " "null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"datistemplate, '' as datacl, -1 as datconnlimit, " "datistemplate, '' as datacl, -1 as datconnlimit, "
"'pg_default' AS dattablespace " "'pg_default' AS dattablespace "
"FROM pg_database d " "FROM pg_database d "
...@@ -1303,7 +1313,7 @@ dumpCreateDB(PGconn *conn) ...@@ -1303,7 +1313,7 @@ dumpCreateDB(PGconn *conn)
"SELECT datname, " "SELECT datname, "
"(select usename from pg_shadow where usesysid=datdba), " "(select usename from pg_shadow where usesysid=datdba), "
"pg_encoding_to_char(d.encoding), " "pg_encoding_to_char(d.encoding), "
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, " "null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid, 0 AS datminmxid, "
"'f' as datistemplate, " "'f' as datistemplate, "
"'' as datacl, -1 as datconnlimit, " "'' as datacl, -1 as datconnlimit, "
"'pg_default' AS dattablespace " "'pg_default' AS dattablespace "
...@@ -1319,10 +1329,11 @@ dumpCreateDB(PGconn *conn) ...@@ -1319,10 +1329,11 @@ dumpCreateDB(PGconn *conn)
char *dbcollate = PQgetvalue(res, i, 3); char *dbcollate = PQgetvalue(res, i, 3);
char *dbctype = PQgetvalue(res, i, 4); char *dbctype = PQgetvalue(res, i, 4);
uint32 dbfrozenxid = atooid(PQgetvalue(res, i, 5)); uint32 dbfrozenxid = atooid(PQgetvalue(res, i, 5));
char *dbistemplate = PQgetvalue(res, i, 6); uint32 dbminmxid = atooid(PQgetvalue(res, i, 6));
char *dbacl = PQgetvalue(res, i, 7); char *dbistemplate = PQgetvalue(res, i, 7);
char *dbconnlimit = PQgetvalue(res, i, 8); char *dbacl = PQgetvalue(res, i, 8);
char *dbtablespace = PQgetvalue(res, i, 9); char *dbconnlimit = PQgetvalue(res, i, 9);
char *dbtablespace = PQgetvalue(res, i, 10);
char *fdbname; char *fdbname;
fdbname = pg_strdup(fmtId(dbname)); fdbname = pg_strdup(fmtId(dbname));
...@@ -1385,11 +1396,11 @@ dumpCreateDB(PGconn *conn) ...@@ -1385,11 +1396,11 @@ dumpCreateDB(PGconn *conn)
if (binary_upgrade) if (binary_upgrade)
{ {
appendPQExpBufferStr(buf, "-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBufferStr(buf, "-- For binary upgrade, set datfrozenxid and datminmxid.\n");
appendPQExpBuffer(buf, "UPDATE pg_catalog.pg_database " appendPQExpBuffer(buf, "UPDATE pg_catalog.pg_database "
"SET datfrozenxid = '%u' " "SET datfrozenxid = '%u', datminmxid = '%u' "
"WHERE datname = ", "WHERE datname = ",
dbfrozenxid); dbfrozenxid, dbminmxid);
appendStringLiteralConn(buf, dbname, conn); appendStringLiteralConn(buf, dbname, conn);
appendPQExpBufferStr(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment