@@ -3812,6 +3812,8 @@ getTables(int *numTables)
38123812int i_relhasrules ;
38133813int i_relhasoids ;
38143814int i_relfrozenxid ;
3815+ int i_toastoid ;
3816+ int i_toastfrozenxid ;
38153817int i_relpersistence ;
38163818int i_owning_tab ;
38173819int i_owning_col ;
@@ -3855,7 +3857,9 @@ getTables(int *numTables)
38553857"(%s c.relowner) AS rolname, "
38563858"c.relchecks, c.relhastriggers, "
38573859"c.relhasindex, c.relhasrules, c.relhasoids, "
3858- "c.relfrozenxid, c.relpersistence, "
3860+ "c.relfrozenxid, tc.oid AS toid, "
3861+ "tc.relfrozenxid AS tfrozenxid, "
3862+ "c.relpersistence, "
38593863"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
38603864"d.refobjid AS owning_tab, "
38613865"d.refobjsubid AS owning_col, "
@@ -3889,7 +3893,9 @@ getTables(int *numTables)
38893893"(%s c.relowner) AS rolname, "
38903894"c.relchecks, c.relhastriggers, "
38913895"c.relhasindex, c.relhasrules, c.relhasoids, "
3892- "c.relfrozenxid, 'p' AS relpersistence, "
3896+ "c.relfrozenxid, tc.oid AS toid, "
3897+ "tc.relfrozenxid AS tfrozenxid, "
3898+ "'p' AS relpersistence, "
38933899"CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
38943900"d.refobjid AS owning_tab, "
38953901"d.refobjsubid AS owning_col, "
@@ -3922,7 +3928,9 @@ getTables(int *numTables)
39223928"(%s c.relowner) AS rolname, "
39233929"c.relchecks, c.relhastriggers, "
39243930"c.relhasindex, c.relhasrules, c.relhasoids, "
3925- "c.relfrozenxid, 'p' AS relpersistence, "
3931+ "c.relfrozenxid, tc.oid AS toid, "
3932+ "tc.relfrozenxid AS tfrozenxid, "
3933+ "'p' AS relpersistence, "
39263934"NULL AS reloftype, "
39273935"d.refobjid AS owning_tab, "
39283936"d.refobjsubid AS owning_col, "
@@ -3955,7 +3963,10 @@ getTables(int *numTables)
39553963"(%s relowner) AS rolname, "
39563964"relchecks, (reltriggers <> 0) AS relhastriggers, "
39573965"relhasindex, relhasrules, relhasoids, "
3958- "relfrozenxid, 'p' AS relpersistence, "
3966+ "relfrozenxid, "
3967+ "0 AS toid, "
3968+ "0 AS tfrozenxid, "
3969+ "'p' AS relpersistence, "
39593970"NULL AS reloftype, "
39603971"d.refobjid AS owning_tab, "
39613972"d.refobjsubid AS owning_col, "
@@ -3987,7 +3998,10 @@ getTables(int *numTables)
39873998"(%s relowner) AS rolname, "
39883999"relchecks, (reltriggers <> 0) AS relhastriggers, "
39894000"relhasindex, relhasrules, relhasoids, "
3990- "0 AS relfrozenxid, 'p' AS relpersistence, "
4001+ "0 AS relfrozenxid, "
4002+ "0 AS toid, "
4003+ "0 AS tfrozenxid, "
4004+ "'p' AS relpersistence, "
39914005"NULL AS reloftype, "
39924006"d.refobjid AS owning_tab, "
39934007"d.refobjsubid AS owning_col, "
@@ -4019,7 +4033,10 @@ getTables(int *numTables)
40194033"(%s relowner) AS rolname, "
40204034"relchecks, (reltriggers <> 0) AS relhastriggers, "
40214035"relhasindex, relhasrules, relhasoids, "
4022- "0 AS relfrozenxid, 'p' AS relpersistence, "
4036+ "0 AS relfrozenxid, "
4037+ "0 AS toid, "
4038+ "0 AS tfrozenxid, "
4039+ "'p' AS relpersistence, "
40234040"NULL AS reloftype, "
40244041"d.refobjid AS owning_tab, "
40254042"d.refobjsubid AS owning_col, "
@@ -4047,7 +4064,10 @@ getTables(int *numTables)
40474064"(%s relowner) AS rolname, "
40484065"relchecks, (reltriggers <> 0) AS relhastriggers, "
40494066"relhasindex, relhasrules, relhasoids, "
4050- "0 AS relfrozenxid, 'p' AS relpersistence, "
4067+ "0 AS relfrozenxid, "
4068+ "0 AS toid, "
4069+ "0 AS tfrozenxid, "
4070+ "'p' AS relpersistence, "
40514071"NULL AS reloftype, "
40524072"NULL::oid AS owning_tab, "
40534073"NULL::int4 AS owning_col, "
@@ -4070,7 +4090,10 @@ getTables(int *numTables)
40704090"relchecks, (reltriggers <> 0) AS relhastriggers, "
40714091"relhasindex, relhasrules, "
40724092"'t'::bool AS relhasoids, "
4073- "0 AS relfrozenxid, 'p' AS relpersistence, "
4093+ "0 AS relfrozenxid, "
4094+ "0 AS toid, "
4095+ "0 AS tfrozenxid, "
4096+ "'p' AS relpersistence, "
40744097"NULL AS reloftype, "
40754098"NULL::oid AS owning_tab, "
40764099"NULL::int4 AS owning_col, "
@@ -4103,7 +4126,10 @@ getTables(int *numTables)
41034126"relchecks, (reltriggers <> 0) AS relhastriggers, "
41044127"relhasindex, relhasrules, "
41054128"'t'::bool AS relhasoids, "
4106- "0 as relfrozenxid, 'p' AS relpersistence, "
4129+ "0 as relfrozenxid, "
4130+ "0 AS toid, "
4131+ "0 AS tfrozenxid, "
4132+ "'p' AS relpersistence, "
41074133"NULL AS reloftype, "
41084134"NULL::oid AS owning_tab, "
41094135"NULL::int4 AS owning_col, "
@@ -4149,6 +4175,8 @@ getTables(int *numTables)
41494175i_relhasrules = PQfnumber (res ,"relhasrules" );
41504176i_relhasoids = PQfnumber (res ,"relhasoids" );
41514177i_relfrozenxid = PQfnumber (res ,"relfrozenxid" );
4178+ i_toastoid = PQfnumber (res ,"toid" );
4179+ i_toastfrozenxid = PQfnumber (res ,"tfrozenxid" );
41524180i_relpersistence = PQfnumber (res ,"relpersistence" );
41534181i_owning_tab = PQfnumber (res ,"owning_tab" );
41544182i_owning_col = PQfnumber (res ,"owning_col" );
@@ -4190,6 +4218,8 @@ getTables(int *numTables)
41904218tblinfo [i ].hastriggers = (strcmp (PQgetvalue (res ,i ,i_relhastriggers ),"t" )== 0 );
41914219tblinfo [i ].hasoids = (strcmp (PQgetvalue (res ,i ,i_relhasoids ),"t" )== 0 );
41924220tblinfo [i ].frozenxid = atooid (PQgetvalue (res ,i ,i_relfrozenxid ));
4221+ tblinfo [i ].toast_oid = atooid (PQgetvalue (res ,i ,i_toastoid ));
4222+ tblinfo [i ].toast_frozenxid = atooid (PQgetvalue (res ,i ,i_toastfrozenxid ));
41934223if (PQgetisnull (res ,i ,i_reloftype ))
41944224tblinfo [i ].reloftype = NULL ;
41954225else
@@ -12221,13 +12251,23 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1222112251}
1222212252}
1222312253
12224- appendPQExpBuffer (q ,"\n-- For binary upgrade, set relfrozenxid\n" );
12254+ appendPQExpBuffer (q ,"\n-- For binary upgrade, setheap's relfrozenxid\n" );
1222512255appendPQExpBuffer (q ,"UPDATE pg_catalog.pg_class\n"
1222612256"SET relfrozenxid = '%u'\n"
1222712257"WHERE oid = " ,
1222812258tbinfo -> frozenxid );
1222912259appendStringLiteralAH (q ,fmtId (tbinfo -> dobj .name ),fout );
1223012260appendPQExpBuffer (q ,"::pg_catalog.regclass;\n" );
12261+
12262+ if (tbinfo -> toast_oid )
12263+ {
12264+ /* We preserve the toast oids, so we can use it during restore */
12265+ appendPQExpBuffer (q ,"\n-- For binary upgrade, set toast's relfrozenxid\n" );
12266+ appendPQExpBuffer (q ,"UPDATE pg_catalog.pg_class\n"
12267+ "SET relfrozenxid = '%u'\n"
12268+ "WHERE oid = '%u';\n" ,
12269+ tbinfo -> toast_frozenxid ,tbinfo -> toast_oid );
12270+ }
1223112271}
1223212272
1223312273/* Loop dumping statistics and storage statements */