1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.523 2009/02/17 22:32:54 momjian Exp $
15+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.524 2009/02/18 12:07:07 momjian Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -1585,6 +1585,7 @@ dumpDatabase(Archive *AH)
15851585i_encoding ,
15861586i_collate ,
15871587i_ctype ,
1588+ i_frozenxid ,
15881589i_tablespace ;
15891590CatalogId dbCatId ;
15901591DumpId dbDumpId ;
@@ -1594,6 +1595,7 @@ dumpDatabase(Archive *AH)
15941595* collate ,
15951596* ctype ,
15961597* tablespace ;
1598+ uint32 frozenxid ;
15971599
15981600datname = PQdb (g_conn );
15991601
@@ -1609,7 +1611,7 @@ dumpDatabase(Archive *AH)
16091611appendPQExpBuffer (dbQry ,"SELECT tableoid, oid, "
16101612"(%s datdba) AS dba, "
16111613"pg_encoding_to_char(encoding) AS encoding, "
1612- "datcollate, datctype, "
1614+ "datcollate, datctype,datfrozenxid, "
16131615"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
16141616"shobj_description(oid, 'pg_database') AS description "
16151617
@@ -1623,7 +1625,7 @@ dumpDatabase(Archive *AH)
16231625appendPQExpBuffer (dbQry ,"SELECT tableoid, oid, "
16241626"(%s datdba) AS dba, "
16251627"pg_encoding_to_char(encoding) AS encoding, "
1626- "NULL AS datcollate, NULL AS datctype, "
1628+ "NULL AS datcollate, NULL AS datctype,datfrozenxid, "
16271629"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
16281630"shobj_description(oid, 'pg_database') AS description "
16291631
@@ -1637,7 +1639,7 @@ dumpDatabase(Archive *AH)
16371639appendPQExpBuffer (dbQry ,"SELECT tableoid, oid, "
16381640"(%s datdba) AS dba, "
16391641"pg_encoding_to_char(encoding) AS encoding, "
1640- "NULL AS datcollate, NULL AS datctype, "
1642+ "NULL AS datcollate, NULL AS datctype,datfrozenxid, "
16411643"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace "
16421644"FROM pg_database "
16431645"WHERE datname = " ,
@@ -1650,6 +1652,7 @@ dumpDatabase(Archive *AH)
16501652"(%s datdba) AS dba, "
16511653"pg_encoding_to_char(encoding) AS encoding, "
16521654"NULL AS datcollate, NULL AS datctype, "
1655+ "0 AS datfrozenxid, "
16531656"NULL AS tablespace "
16541657"FROM pg_database "
16551658"WHERE datname = " ,
@@ -1664,6 +1667,7 @@ dumpDatabase(Archive *AH)
16641667"(%s datdba) AS dba, "
16651668"pg_encoding_to_char(encoding) AS encoding, "
16661669"NULL AS datcollate, NULL AS datctype, "
1670+ "0 AS datfrozenxid, "
16671671"NULL AS tablespace "
16681672"FROM pg_database "
16691673"WHERE datname = " ,
@@ -1696,6 +1700,7 @@ dumpDatabase(Archive *AH)
16961700i_encoding = PQfnumber (res ,"encoding" );
16971701i_collate = PQfnumber (res ,"datcollate" );
16981702i_ctype = PQfnumber (res ,"datctype" );
1703+ i_frozenxid = PQfnumber (res ,"datfrozenxid" );
16991704i_tablespace = PQfnumber (res ,"tablespace" );
17001705
17011706dbCatId .tableoid = atooid (PQgetvalue (res ,0 ,i_tableoid ));
@@ -1704,6 +1709,7 @@ dumpDatabase(Archive *AH)
17041709encoding = PQgetvalue (res ,0 ,i_encoding );
17051710collate = PQgetvalue (res ,0 ,i_collate );
17061711ctype = PQgetvalue (res ,0 ,i_ctype );
1712+ frozenxid = atooid (PQgetvalue (res ,0 ,i_frozenxid ));
17071713tablespace = PQgetvalue (res ,0 ,i_tablespace );
17081714
17091715appendPQExpBuffer (creaQry ,"CREATE DATABASE %s WITH TEMPLATE = template0" ,
@@ -1728,6 +1734,15 @@ dumpDatabase(Archive *AH)
17281734fmtId (tablespace ));
17291735appendPQExpBuffer (creaQry ,";\n" );
17301736
1737+ if (binary_upgrade )
1738+ {
1739+ appendPQExpBuffer (creaQry ,"\n-- For binary upgrade, set datfrozenxid.\n" );
1740+ appendPQExpBuffer (creaQry ,"UPDATE pg_database\n"
1741+ "SET datfrozenxid = '%u'\n"
1742+ "WHEREdatname = '%s';\n" ,
1743+ frozenxid ,datname );
1744+ }
1745+
17311746appendPQExpBuffer (delQry ,"DROP DATABASE %s;\n" ,
17321747fmtId (datname ));
17331748
@@ -3114,6 +3129,7 @@ getTables(int *numTables)
31143129int i_relhasindex ;
31153130int i_relhasrules ;
31163131int i_relhasoids ;
3132+ int i_relfrozenxid ;
31173133int i_owning_tab ;
31183134int i_owning_col ;
31193135int i_reltablespace ;
@@ -3155,6 +3171,7 @@ getTables(int *numTables)
31553171"(%s c.relowner) AS rolname, "
31563172"c.relchecks, c.relhastriggers, "
31573173"c.relhasindex, c.relhasrules, c.relhasoids, "
3174+ "c.relfrozenxid, "
31583175"d.refobjid AS owning_tab, "
31593176"d.refobjsubid AS owning_col, "
31603177"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
@@ -3186,6 +3203,7 @@ getTables(int *numTables)
31863203"(%s relowner) AS rolname, "
31873204"relchecks, (reltriggers <> 0) AS relhastriggers, "
31883205"relhasindex, relhasrules, relhasoids, "
3206+ "relfrozenxid, "
31893207"d.refobjid AS owning_tab, "
31903208"d.refobjsubid AS owning_col, "
31913209"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
@@ -3216,6 +3234,7 @@ getTables(int *numTables)
32163234"(%s relowner) AS rolname, "
32173235"relchecks, (reltriggers <> 0) AS relhastriggers, "
32183236"relhasindex, relhasrules, relhasoids, "
3237+ "0 AS relfrozenxid, "
32193238"d.refobjid AS owning_tab, "
32203239"d.refobjsubid AS owning_col, "
32213240"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
@@ -3246,6 +3265,7 @@ getTables(int *numTables)
32463265"(%s relowner) AS rolname, "
32473266"relchecks, (reltriggers <> 0) AS relhastriggers, "
32483267"relhasindex, relhasrules, relhasoids, "
3268+ "0 AS relfrozenxid, "
32493269"d.refobjid AS owning_tab, "
32503270"d.refobjsubid AS owning_col, "
32513271"NULL AS reltablespace, "
@@ -3272,6 +3292,7 @@ getTables(int *numTables)
32723292"(%s relowner) AS rolname, "
32733293"relchecks, (reltriggers <> 0) AS relhastriggers, "
32743294"relhasindex, relhasrules, relhasoids, "
3295+ "0 AS relfrozenxid, "
32753296"NULL::oid AS owning_tab, "
32763297"NULL::int4 AS owning_col, "
32773298"NULL AS reltablespace, "
@@ -3293,6 +3314,7 @@ getTables(int *numTables)
32933314"relchecks, (reltriggers <> 0) AS relhastriggers, "
32943315"relhasindex, relhasrules, "
32953316"'t'::bool AS relhasoids, "
3317+ "0 AS relfrozenxid, "
32963318"NULL::oid AS owning_tab, "
32973319"NULL::int4 AS owning_col, "
32983320"NULL AS reltablespace, "
@@ -3324,6 +3346,7 @@ getTables(int *numTables)
33243346"relchecks, (reltriggers <> 0) AS relhastriggers, "
33253347"relhasindex, relhasrules, "
33263348"'t'::bool AS relhasoids, "
3349+ "0 as relfrozenxid, "
33273350"NULL::oid AS owning_tab, "
33283351"NULL::int4 AS owning_col, "
33293352"NULL AS reltablespace, "
@@ -3367,6 +3390,7 @@ getTables(int *numTables)
33673390i_relhasindex = PQfnumber (res ,"relhasindex" );
33683391i_relhasrules = PQfnumber (res ,"relhasrules" );
33693392i_relhasoids = PQfnumber (res ,"relhasoids" );
3393+ i_relfrozenxid = PQfnumber (res ,"relfrozenxid" );
33703394i_owning_tab = PQfnumber (res ,"owning_tab" );
33713395i_owning_col = PQfnumber (res ,"owning_col" );
33723396i_reltablespace = PQfnumber (res ,"reltablespace" );
@@ -3404,6 +3428,7 @@ getTables(int *numTables)
34043428tblinfo [i ].hasrules = (strcmp (PQgetvalue (res ,i ,i_relhasrules ),"t" )== 0 );
34053429tblinfo [i ].hastriggers = (strcmp (PQgetvalue (res ,i ,i_relhastriggers ),"t" )== 0 );
34063430tblinfo [i ].hasoids = (strcmp (PQgetvalue (res ,i ,i_relhasoids ),"t" )== 0 );
3431+ tblinfo [i ].frozenxid = atooid (PQgetvalue (res ,i ,i_relfrozenxid ));
34073432tblinfo [i ].ncheck = atoi (PQgetvalue (res ,i ,i_relchecks ));
34083433if (PQgetisnull (res ,i ,i_owning_tab ))
34093434{
@@ -9860,6 +9885,15 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
98609885tbinfo -> dobj .name );
98619886}
98629887}
9888+ appendPQExpBuffer (q ,"\n-- For binary upgrade, set relfrozenxid.\n" );
9889+ appendPQExpBuffer (q ,"UPDATE pg_class\n"
9890+ "SET relfrozenxid = '%u'\n"
9891+ "WHERErelname = '%s'\n"
9892+ "AND relnamespace = "
9893+ "(SELECT oid FROM pg_namespace "
9894+ "WHERE nspname = CURRENT_SCHEMA);\n" ,
9895+ tbinfo -> frozenxid ,
9896+ tbinfo -> dobj .name );
98639897}
98649898
98659899/* Loop dumping statistics and storage statements */