mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Have pg_dump/pg_dumpall --binary-upgrade restore frozenids for relations
and databases.
This commit is contained in:
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.523 2009/02/17 22:32:54 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.524 2009/02/18 12:07:07 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1585,6 +1585,7 @@ dumpDatabase(Archive *AH)
|
|||||||
i_encoding,
|
i_encoding,
|
||||||
i_collate,
|
i_collate,
|
||||||
i_ctype,
|
i_ctype,
|
||||||
|
i_frozenxid,
|
||||||
i_tablespace;
|
i_tablespace;
|
||||||
CatalogId dbCatId;
|
CatalogId dbCatId;
|
||||||
DumpId dbDumpId;
|
DumpId dbDumpId;
|
||||||
@ -1594,6 +1595,7 @@ dumpDatabase(Archive *AH)
|
|||||||
*collate,
|
*collate,
|
||||||
*ctype,
|
*ctype,
|
||||||
*tablespace;
|
*tablespace;
|
||||||
|
uint32 frozenxid;
|
||||||
|
|
||||||
datname = PQdb(g_conn);
|
datname = PQdb(g_conn);
|
||||||
|
|
||||||
@ -1609,7 +1611,7 @@ dumpDatabase(Archive *AH)
|
|||||||
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, "
|
"datcollate, datctype, datfrozenxid, "
|
||||||
"(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 "
|
||||||
|
|
||||||
@ -1623,7 +1625,7 @@ dumpDatabase(Archive *AH)
|
|||||||
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, "
|
"NULL AS datcollate, NULL AS datctype, datfrozenxid, "
|
||||||
"(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 "
|
||||||
|
|
||||||
@ -1637,7 +1639,7 @@ dumpDatabase(Archive *AH)
|
|||||||
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, "
|
"NULL AS datcollate, NULL AS datctype, datfrozenxid, "
|
||||||
"(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 = ",
|
||||||
@ -1650,6 +1652,7 @@ dumpDatabase(Archive *AH)
|
|||||||
"(%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, "
|
||||||
"NULL AS tablespace "
|
"NULL AS tablespace "
|
||||||
"FROM pg_database "
|
"FROM pg_database "
|
||||||
"WHERE datname = ",
|
"WHERE datname = ",
|
||||||
@ -1664,6 +1667,7 @@ dumpDatabase(Archive *AH)
|
|||||||
"(%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, "
|
||||||
"NULL AS tablespace "
|
"NULL AS tablespace "
|
||||||
"FROM pg_database "
|
"FROM pg_database "
|
||||||
"WHERE datname = ",
|
"WHERE datname = ",
|
||||||
@ -1696,6 +1700,7 @@ dumpDatabase(Archive *AH)
|
|||||||
i_encoding = PQfnumber(res, "encoding");
|
i_encoding = PQfnumber(res, "encoding");
|
||||||
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_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));
|
||||||
@ -1704,6 +1709,7 @@ dumpDatabase(Archive *AH)
|
|||||||
encoding = PQgetvalue(res, 0, i_encoding);
|
encoding = PQgetvalue(res, 0, i_encoding);
|
||||||
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));
|
||||||
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",
|
||||||
@ -1728,6 +1734,15 @@ dumpDatabase(Archive *AH)
|
|||||||
fmtId(tablespace));
|
fmtId(tablespace));
|
||||||
appendPQExpBuffer(creaQry, ";\n");
|
appendPQExpBuffer(creaQry, ";\n");
|
||||||
|
|
||||||
|
if (binary_upgrade)
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n");
|
||||||
|
appendPQExpBuffer(creaQry, "UPDATE pg_database\n"
|
||||||
|
"SET datfrozenxid = '%u'\n"
|
||||||
|
"WHERE datname = '%s';\n",
|
||||||
|
frozenxid, datname);
|
||||||
|
}
|
||||||
|
|
||||||
appendPQExpBuffer(delQry, "DROP DATABASE %s;\n",
|
appendPQExpBuffer(delQry, "DROP DATABASE %s;\n",
|
||||||
fmtId(datname));
|
fmtId(datname));
|
||||||
|
|
||||||
@ -3114,6 +3129,7 @@ getTables(int *numTables)
|
|||||||
int i_relhasindex;
|
int i_relhasindex;
|
||||||
int i_relhasrules;
|
int i_relhasrules;
|
||||||
int i_relhasoids;
|
int i_relhasoids;
|
||||||
|
int i_relfrozenxid;
|
||||||
int i_owning_tab;
|
int i_owning_tab;
|
||||||
int i_owning_col;
|
int i_owning_col;
|
||||||
int i_reltablespace;
|
int i_reltablespace;
|
||||||
@ -3155,6 +3171,7 @@ getTables(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, "
|
||||||
"d.refobjid AS owning_tab, "
|
"d.refobjid AS owning_tab, "
|
||||||
"d.refobjsubid AS owning_col, "
|
"d.refobjsubid AS owning_col, "
|
||||||
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
||||||
@ -3186,6 +3203,7 @@ getTables(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, "
|
||||||
|
"relfrozenxid, "
|
||||||
"d.refobjid AS owning_tab, "
|
"d.refobjid AS owning_tab, "
|
||||||
"d.refobjsubid AS owning_col, "
|
"d.refobjsubid AS owning_col, "
|
||||||
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
||||||
@ -3216,6 +3234,7 @@ getTables(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, "
|
||||||
"d.refobjid AS owning_tab, "
|
"d.refobjid AS owning_tab, "
|
||||||
"d.refobjsubid AS owning_col, "
|
"d.refobjsubid AS owning_col, "
|
||||||
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
||||||
@ -3246,6 +3265,7 @@ getTables(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, "
|
||||||
"d.refobjid AS owning_tab, "
|
"d.refobjid AS owning_tab, "
|
||||||
"d.refobjsubid AS owning_col, "
|
"d.refobjsubid AS owning_col, "
|
||||||
"NULL AS reltablespace, "
|
"NULL AS reltablespace, "
|
||||||
@ -3272,6 +3292,7 @@ getTables(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, "
|
||||||
"NULL::oid AS owning_tab, "
|
"NULL::oid AS owning_tab, "
|
||||||
"NULL::int4 AS owning_col, "
|
"NULL::int4 AS owning_col, "
|
||||||
"NULL AS reltablespace, "
|
"NULL AS reltablespace, "
|
||||||
@ -3293,6 +3314,7 @@ getTables(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, "
|
||||||
"NULL::oid AS owning_tab, "
|
"NULL::oid AS owning_tab, "
|
||||||
"NULL::int4 AS owning_col, "
|
"NULL::int4 AS owning_col, "
|
||||||
"NULL AS reltablespace, "
|
"NULL AS reltablespace, "
|
||||||
@ -3324,6 +3346,7 @@ getTables(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, "
|
||||||
"NULL::oid AS owning_tab, "
|
"NULL::oid AS owning_tab, "
|
||||||
"NULL::int4 AS owning_col, "
|
"NULL::int4 AS owning_col, "
|
||||||
"NULL AS reltablespace, "
|
"NULL AS reltablespace, "
|
||||||
@ -3367,6 +3390,7 @@ getTables(int *numTables)
|
|||||||
i_relhasindex = PQfnumber(res, "relhasindex");
|
i_relhasindex = PQfnumber(res, "relhasindex");
|
||||||
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_owning_tab = PQfnumber(res, "owning_tab");
|
i_owning_tab = PQfnumber(res, "owning_tab");
|
||||||
i_owning_col = PQfnumber(res, "owning_col");
|
i_owning_col = PQfnumber(res, "owning_col");
|
||||||
i_reltablespace = PQfnumber(res, "reltablespace");
|
i_reltablespace = PQfnumber(res, "reltablespace");
|
||||||
@ -3404,6 +3428,7 @@ getTables(int *numTables)
|
|||||||
tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
|
tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
|
||||||
tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
|
tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
|
||||||
tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
|
tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
|
||||||
|
tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
|
||||||
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
|
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
|
||||||
if (PQgetisnull(res, i, i_owning_tab))
|
if (PQgetisnull(res, i, i_owning_tab))
|
||||||
{
|
{
|
||||||
@ -9860,6 +9885,15 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
|
|||||||
tbinfo->dobj.name);
|
tbinfo->dobj.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
appendPQExpBuffer(q, "\n-- For binary upgrade, set relfrozenxid.\n");
|
||||||
|
appendPQExpBuffer(q, "UPDATE pg_class\n"
|
||||||
|
"SET relfrozenxid = '%u'\n"
|
||||||
|
"WHERE relname = '%s'\n"
|
||||||
|
" AND relnamespace = "
|
||||||
|
"(SELECT oid FROM pg_namespace "
|
||||||
|
"WHERE nspname = CURRENT_SCHEMA);\n",
|
||||||
|
tbinfo->frozenxid,
|
||||||
|
tbinfo->dobj.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop dumping statistics and storage statements */
|
/* Loop dumping statistics and storage statements */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.151 2009/02/17 15:41:50 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.152 2009/02/18 12:07:07 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -226,6 +226,7 @@ typedef struct _tableInfo
|
|||||||
bool hasrules; /* does it have any rules? */
|
bool hasrules; /* does it have any rules? */
|
||||||
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 */
|
||||||
int ncheck; /* # of CHECK expressions */
|
int ncheck; /* # of CHECK expressions */
|
||||||
/* 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: */
|
||||||
Oid owning_tab; /* OID of table owning sequence */
|
Oid owning_tab; /* OID of table owning sequence */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.114 2009/02/17 15:41:50 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.115 2009/02/18 12:07:08 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -27,7 +27,7 @@ int optreset;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "dumputils.h"
|
#include "dumputils.h"
|
||||||
|
#include "pg_backup.h"
|
||||||
|
|
||||||
/* version string we expect back from pg_dump */
|
/* version string we expect back from pg_dump */
|
||||||
#define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
|
#define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
|
||||||
@ -71,6 +71,8 @@ static int server_version;
|
|||||||
static FILE *OPF;
|
static FILE *OPF;
|
||||||
static char *filename = NULL;
|
static char *filename = NULL;
|
||||||
|
|
||||||
|
static int binary_upgrade = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -90,7 +92,6 @@ main(int argc, char *argv[])
|
|||||||
const char *std_strings;
|
const char *std_strings;
|
||||||
int c,
|
int c,
|
||||||
ret;
|
ret;
|
||||||
int binary_upgrade = 0;
|
|
||||||
|
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
{"binary-upgrade", no_argument, &binary_upgrade, 1}, /* not documented */
|
{"binary-upgrade", no_argument, &binary_upgrade, 1}, /* not documented */
|
||||||
@ -937,7 +938,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), "
|
||||||
"datcollate, datctype, "
|
"datcollate, datctype, datfrozenxid, "
|
||||||
"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) "
|
||||||
@ -947,7 +948,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, "
|
"null::text AS datcollate, null::text AS datctype, datfrozenxid, "
|
||||||
"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) "
|
||||||
@ -957,7 +958,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, "
|
"null::text AS datcollate, null::text AS datctype, datfrozenxid, "
|
||||||
"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) "
|
||||||
@ -967,7 +968,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, "
|
"null::text AS datcollate, null::text AS datctype, datfrozenxid, "
|
||||||
"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) "
|
||||||
@ -979,7 +980,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, "
|
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid"
|
||||||
"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 "
|
||||||
@ -994,7 +995,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, "
|
"null::text AS datcollate, null::text AS datctype, 0 AS datfrozenxid"
|
||||||
"'f' as datistemplate, "
|
"'f' as datistemplate, "
|
||||||
"'' as datacl, -1 as datconnlimit, "
|
"'' as datacl, -1 as datconnlimit, "
|
||||||
"'pg_default' AS dattablespace "
|
"'pg_default' AS dattablespace "
|
||||||
@ -1009,10 +1010,11 @@ dumpCreateDB(PGconn *conn)
|
|||||||
char *dbencoding = PQgetvalue(res, i, 2);
|
char *dbencoding = PQgetvalue(res, i, 2);
|
||||||
char *dbcollate = PQgetvalue(res, i, 3);
|
char *dbcollate = PQgetvalue(res, i, 3);
|
||||||
char *dbctype = PQgetvalue(res, i, 4);
|
char *dbctype = PQgetvalue(res, i, 4);
|
||||||
char *dbistemplate = PQgetvalue(res, i, 5);
|
uint32 dbfrozenxid = atooid(PQgetvalue(res, i, 5));
|
||||||
char *dbacl = PQgetvalue(res, i, 6);
|
char *dbistemplate = PQgetvalue(res, i, 6);
|
||||||
char *dbconnlimit = PQgetvalue(res, i, 7);
|
char *dbacl = PQgetvalue(res, i, 7);
|
||||||
char *dbtablespace = PQgetvalue(res, i, 8);
|
char *dbconnlimit = PQgetvalue(res, i, 8);
|
||||||
|
char *dbtablespace = PQgetvalue(res, i, 9);
|
||||||
char *fdbname;
|
char *fdbname;
|
||||||
|
|
||||||
fdbname = strdup(fmtId(dbname));
|
fdbname = strdup(fmtId(dbname));
|
||||||
@ -1076,6 +1078,15 @@ dumpCreateDB(PGconn *conn)
|
|||||||
appendStringLiteralConn(buf, dbname, conn);
|
appendStringLiteralConn(buf, dbname, conn);
|
||||||
appendPQExpBuffer(buf, ";\n");
|
appendPQExpBuffer(buf, ";\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (binary_upgrade)
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(buf, "\n-- For binary upgrade, set datfrozenxid.\n");
|
||||||
|
appendPQExpBuffer(buf, "UPDATE pg_database\n"
|
||||||
|
"SET datfrozenxid = '%u'\n"
|
||||||
|
"WHERE datname = '%s';\n",
|
||||||
|
dbfrozenxid, fdbname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip_acls &&
|
if (!skip_acls &&
|
||||||
|
Reference in New Issue
Block a user