diff options
author | Bruce Momjian <bruce@momjian.us> | 2009-12-27 14:50:46 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2009-12-27 14:50:46 +0000 |
commit | e5b457c2ac0f5b843f53bd5719a620e7fcc4961d (patch) | |
tree | d5e5ca6ec217323ab02fc243d83927606567e32e /src/backend | |
parent | 1fd9883ff49fdc4008c6a17936441b74696ff1a9 (diff) | |
download | postgresql-e5b457c2ac0f5b843f53bd5719a620e7fcc4961d.tar.gz postgresql-e5b457c2ac0f5b843f53bd5719a620e7fcc4961d.zip |
Add backend and pg_dump code to allow preservation of pg_enum oids, for
use in binary upgrades.
Bump catalog version for detection by pg_migrator of new backend API.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/pg_enum.c | 43 | ||||
-rw-r--r-- | src/backend/commands/typecmds.c | 4 |
2 files changed, 31 insertions, 16 deletions
diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c index 9a3d533c146..689ecd4830d 100644 --- a/src/backend/catalog/pg_enum.c +++ b/src/backend/catalog/pg_enum.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.11 2009/12/24 22:17:58 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.12 2009/12/27 14:50:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,8 @@ static int oid_cmp(const void *p1, const void *p2); * vals is a list of Value strings. */ void -EnumValuesCreate(Oid enumTypeOid, List *vals) +EnumValuesCreate(Oid enumTypeOid, List *vals, + Oid binary_upgrade_next_pg_enum_oid) { Relation pg_enum; TupleDesc tupDesc; @@ -58,25 +59,39 @@ EnumValuesCreate(Oid enumTypeOid, List *vals) tupDesc = pg_enum->rd_att; /* - * Allocate oids. While this method does not absolutely guarantee that we - * generate no duplicate oids (since we haven't entered each oid into the - * table before allocating the next), trouble could only occur if the oid - * counter wraps all the way around before we finish. Which seems - * unlikely. + * Allocate oids */ oids = (Oid *) palloc(num_elems * sizeof(Oid)); - for (elemno = 0; elemno < num_elems; elemno++) + if (OidIsValid(binary_upgrade_next_pg_enum_oid)) + { + if (num_elems != 1) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("EnumValuesCreate() can only set a single OID"))); + oids[0] = binary_upgrade_next_pg_enum_oid; + binary_upgrade_next_pg_enum_oid = InvalidOid; + } + else { /* - * The pg_enum.oid is stored in user tables. This oid must be - * preserved by binary upgrades. + * While this method does not absolutely guarantee that we generate + * no duplicate oids (since we haven't entered each oid into the + * table before allocating the next), trouble could only occur if + * the oid counter wraps all the way around before we finish. Which + * seems unlikely. */ - oids[elemno] = GetNewOid(pg_enum); + for (elemno = 0; elemno < num_elems; elemno++) + { + /* + * The pg_enum.oid is stored in user tables. This oid must be + * preserved by binary upgrades. + */ + oids[elemno] = GetNewOid(pg_enum); + } + /* sort them, just in case counter wrapped from high to low */ + qsort(oids, num_elems, sizeof(Oid), oid_cmp); } - /* sort them, just in case counter wrapped from high to low */ - qsort(oids, num_elems, sizeof(Oid), oid_cmp); - /* and make the entries */ memset(nulls, false, sizeof(nulls)); diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 11990c0e106..a815752ecbb 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.141 2009/12/24 22:09:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.142 2009/12/27 14:50:43 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -1161,7 +1161,7 @@ DefineEnum(CreateEnumStmt *stmt) false); /* Type NOT NULL */ /* Enter the enum's values into pg_enum */ - EnumValuesCreate(enumTypeOid, stmt->vals); + EnumValuesCreate(enumTypeOid, stmt->vals, InvalidOid); /* * Create the array type that goes with it. |