diff options
| author | Bruce Momjian <bruce@momjian.us> | 2011-04-08 11:59:14 -0400 | 
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2011-04-08 11:59:38 -0400 | 
| commit | 00bf707113a297aa85c38beda8fb1247fe4bd304 (patch) | |
| tree | 9e3a53545ebdd5d6862ae149e4170a465352b77b /src | |
| parent | a5c629f373a8125cd7682083a290fff452db3757 (diff) | |
Have pg_upgrade properly preserve relfrozenxid in toast tables.
This fixes a pg_upgrade bug that could lead to query errors when clog
files are improperly removed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 36 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dump.h | 2 | 
2 files changed, 35 insertions, 3 deletions
| diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index f93affd089f..8721e6573db 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -3409,6 +3409,8 @@ getTables(int *numTables)  	int			i_relhasrules;  	int			i_relhasoids;  	int			i_relfrozenxid; +	int			i_toastoid; +	int			i_toastfrozenxid;  	int			i_owning_tab;  	int			i_owning_col;  	int			i_reltablespace; @@ -3451,7 +3453,8 @@ getTables(int *numTables)  						  "(%s c.relowner) AS rolname, "  						  "c.relchecks, c.relhastriggers, "  						  "c.relhasindex, c.relhasrules, c.relhasoids, " -						  "c.relfrozenxid, " +						  "c.relfrozenxid, tc.oid AS toid, " +						  "tc.relfrozenxid AS tfrozenxid, "  						  "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "  						  "d.refobjid AS owning_tab, "  						  "d.refobjsubid AS owning_col, " @@ -3484,7 +3487,8 @@ getTables(int *numTables)  						  "(%s c.relowner) AS rolname, "  						  "c.relchecks, c.relhastriggers, "  						  "c.relhasindex, c.relhasrules, c.relhasoids, " -						  "c.relfrozenxid, " +						  "c.relfrozenxid, tc.oid AS toid, " +						  "tc.relfrozenxid AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "d.refobjid AS owning_tab, "  						  "d.refobjsubid AS owning_col, " @@ -3518,6 +3522,8 @@ getTables(int *numTables)  						  "relchecks, (reltriggers <> 0) AS relhastriggers, "  						  "relhasindex, relhasrules, relhasoids, "  						  "relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "d.refobjid AS owning_tab, "  						  "d.refobjsubid AS owning_col, " @@ -3550,6 +3556,8 @@ getTables(int *numTables)  						  "relchecks, (reltriggers <> 0) AS relhastriggers, "  						  "relhasindex, relhasrules, relhasoids, "  						  "0 AS relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "d.refobjid AS owning_tab, "  						  "d.refobjsubid AS owning_col, " @@ -3582,6 +3590,8 @@ getTables(int *numTables)  						  "relchecks, (reltriggers <> 0) AS relhastriggers, "  						  "relhasindex, relhasrules, relhasoids, "  						  "0 AS relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "d.refobjid AS owning_tab, "  						  "d.refobjsubid AS owning_col, " @@ -3610,6 +3620,8 @@ getTables(int *numTables)  						  "relchecks, (reltriggers <> 0) AS relhastriggers, "  						  "relhasindex, relhasrules, relhasoids, "  						  "0 AS relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "NULL::oid AS owning_tab, "  						  "NULL::int4 AS owning_col, " @@ -3633,6 +3645,8 @@ getTables(int *numTables)  						  "relhasindex, relhasrules, "  						  "'t'::bool AS relhasoids, "  						  "0 AS relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "NULL::oid AS owning_tab, "  						  "NULL::int4 AS owning_col, " @@ -3666,6 +3680,8 @@ getTables(int *numTables)  						  "relhasindex, relhasrules, "  						  "'t'::bool AS relhasoids, "  						  "0 as relfrozenxid, " +						  "0 AS toid, " +						  "0 AS tfrozenxid, "  						  "NULL AS reloftype, "  						  "NULL::oid AS owning_tab, "  						  "NULL::int4 AS owning_col, " @@ -3711,6 +3727,8 @@ getTables(int *numTables)  	i_relhasrules = PQfnumber(res, "relhasrules");  	i_relhasoids = PQfnumber(res, "relhasoids");  	i_relfrozenxid = PQfnumber(res, "relfrozenxid"); +	i_toastoid = PQfnumber(res, "toid"); +	i_toastfrozenxid = PQfnumber(res, "tfrozenxid");  	i_owning_tab = PQfnumber(res, "owning_tab");  	i_owning_col = PQfnumber(res, "owning_col");  	i_reltablespace = PQfnumber(res, "reltablespace"); @@ -3750,6 +3768,8 @@ getTables(int *numTables)  		tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);  		tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);  		tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid)); +		tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid)); +		tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid));  		if (PQgetisnull(res, i, i_reloftype))  			tblinfo[i].reloftype = NULL;  		else @@ -10852,13 +10872,23 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)  				}  			} -			appendPQExpBuffer(q, "\n-- For binary upgrade, set relfrozenxid.\n"); +			appendPQExpBuffer(q, "\n-- For binary upgrade, set heap's relfrozenxid\n");  			appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"  							  "SET relfrozenxid = '%u'\n"  							  "WHERE oid = ",  							  tbinfo->frozenxid);  			appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);  			appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); + +			if (tbinfo->toast_oid) +			{ +				/* We preserve the toast oids, so we can use it during restore */ +				appendPQExpBuffer(q, "\n-- For binary upgrade, set toast's relfrozenxid\n"); +				appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" +								  "SET relfrozenxid = '%u'\n" +								  "WHERE oid = '%u';\n", +								  tbinfo->toast_frozenxid, tbinfo->toast_oid); +			}  		}  		/* Loop dumping statistics and storage statements */ diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index c309f69f726..1dc715739e6 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -228,6 +228,8 @@ typedef struct _tableInfo  	bool		hastriggers;	/* does it have any triggers? */  	bool		hasoids;		/* does it have OIDs? */  	uint32		frozenxid;		/* for restore frozen xid */ +	Oid			toast_oid;		/* for restore toast frozen xid */ +	uint32		toast_frozenxid;/* for restore toast frozen xid */  	int			ncheck;			/* # of CHECK expressions */  	char	   *reloftype;		/* underlying type for typed table */  	/* these two are set only if table is a sequence owned by a column: */ | 
