Skip to content

Commit c44327a

Browse files
committed
Binary upgrade:
Modify pg_dump --binary-upgrade and add backend support routines to support the preservation of pg_type oids when doing a binary upgrade. This allows user-defined composite types and arrays to be binary upgraded.
1 parent 668e37d commit c44327a

File tree

6 files changed

+226
-27
lines changed

6 files changed

+226
-27
lines changed

src/backend/catalog/heap.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.361 2009/12/07 05:22:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.362 2009/12/24 22:09:23 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1001,13 +1001,7 @@ heap_create_with_catalog(const char *relname,
10011001
if (IsUnderPostmaster && (relkind == RELKIND_RELATION ||
10021002
relkind == RELKIND_VIEW ||
10031003
relkind == RELKIND_COMPOSITE_TYPE))
1004-
{
1005-
/* OK, so pre-assign a type OID for the array type */
1006-
Relation pg_type = heap_open(TypeRelationId, AccessShareLock);
1007-
1008-
new_array_oid = GetNewOid(pg_type);
1009-
heap_close(pg_type, AccessShareLock);
1010-
}
1004+
new_array_oid = AssignTypeArrayOid();
10111005

10121006
/*
10131007
* Since defining a relation also defines a complex type, we add a new

src/backend/catalog/pg_type.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.127 2009/08/16 18:14:34 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.128 2009/12/24 22:09:23 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,6 +32,7 @@
3232
#include "utils/rel.h"
3333
#include "utils/syscache.h"
3434

35+
Oid binary_upgrade_next_pg_type_oid = InvalidOid;
3536

3637
/* ----------------------------------------------------------------
3738
* TypeShellMake
@@ -119,6 +120,12 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
119120
*/
120121
tup = heap_form_tuple(tupDesc, values, nulls);
121122

123+
if (OidIsValid(binary_upgrade_next_pg_type_oid))
124+
{
125+
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
126+
binary_upgrade_next_pg_type_oid = InvalidOid;
127+
}
128+
122129
/*
123130
* insert the tuple in the relation and get the tuple's oid.
124131
*/
@@ -409,10 +416,16 @@ TypeCreate(Oid newTypeOid,
409416
values,
410417
nulls);
411418

412-
/* Force the OID if requested by caller, else heap_insert does it */
419+
/* Force the OID if requested by caller */
413420
if (OidIsValid(newTypeOid))
414421
HeapTupleSetOid(tup, newTypeOid);
415-
422+
else if (OidIsValid(binary_upgrade_next_pg_type_oid))
423+
{
424+
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
425+
binary_upgrade_next_pg_type_oid = InvalidOid;
426+
}
427+
/* else allow system to assign oid */
428+
416429
typeObjectId = simple_heap_insert(pg_type_desc, tup);
417430
}
418431

src/backend/catalog/toasting.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.22 2009/12/23 02:35:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.23 2009/12/24 22:09:23 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,6 +31,7 @@
3131
#include "utils/builtins.h"
3232
#include "utils/syscache.h"
3333

34+
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
3435

3536
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
3637
Datum reloptions, bool force);
@@ -121,6 +122,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
121122
Relation class_rel;
122123
Oid toast_relid;
123124
Oid toast_idxid;
125+
Oid toast_typid = InvalidOid;
124126
Oid namespaceid;
125127
char toast_relname[NAMEDATALEN];
126128
char toast_idxname[NAMEDATALEN];
@@ -199,11 +201,17 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
199201
else
200202
namespaceid = PG_TOAST_NAMESPACE;
201203

204+
if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
205+
{
206+
toast_typid = binary_upgrade_next_pg_type_toast_oid;
207+
binary_upgrade_next_pg_type_toast_oid = InvalidOid;
208+
}
209+
202210
toast_relid = heap_create_with_catalog(toast_relname,
203211
namespaceid,
204212
rel->rd_rel->reltablespace,
205213
toastOid,
206-
InvalidOid,
214+
toast_typid,
207215
rel->rd_rel->relowner,
208216
tupdesc,
209217
NIL,

src/backend/commands/typecmds.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.140 2009/12/19 00:47:57 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.141 2009/12/24 22:09:23 momjian Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -74,6 +74,7 @@ typedef struct
7474
/* atts[] is of allocated length RelationGetNumberOfAttributes(rel) */
7575
} RelToCheck;
7676

77+
Oid binary_upgrade_next_pg_type_array_oid = InvalidOid;
7778

7879
static Oid findTypeInputFunction(List *procname, Oid typeOid);
7980
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
@@ -143,7 +144,6 @@ DefineType(List *names, List *parameters)
143144
Oid array_oid;
144145
Oid typoid;
145146
Oid resulttype;
146-
Relation pg_type;
147147
ListCell *pl;
148148

149149
/*
@@ -522,10 +522,7 @@ DefineType(List *names, List *parameters)
522522
NameListToString(analyzeName));
523523
#endif
524524

525-
/* Preassign array type OID so we can insert it in pg_type.typarray */
526-
pg_type = heap_open(TypeRelationId, AccessShareLock);
527-
array_oid = GetNewOid(pg_type);
528-
heap_close(pg_type, AccessShareLock);
525+
array_oid = AssignTypeArrayOid();
529526

530527
/*
531528
* now have TypeCreate do all the real work.
@@ -1101,7 +1098,6 @@ DefineEnum(CreateEnumStmt *stmt)
11011098
AclResult aclresult;
11021099
Oid old_type_oid;
11031100
Oid enumArrayOid;
1104-
Relation pg_type;
11051101

11061102
/* Convert list of names to a name and namespace */
11071103
enumNamespace = QualifiedNameGetCreationNamespace(stmt->typeName,
@@ -1129,10 +1125,7 @@ DefineEnum(CreateEnumStmt *stmt)
11291125
errmsg("type \"%s\" already exists", enumName)));
11301126
}
11311127

1132-
/* Preassign array type OID so we can insert it in pg_type.typarray */
1133-
pg_type = heap_open(TypeRelationId, AccessShareLock);
1134-
enumArrayOid = GetNewOid(pg_type);
1135-
heap_close(pg_type, AccessShareLock);
1128+
enumArrayOid = AssignTypeArrayOid();
11361129

11371130
/* Create the pg_type entry */
11381131
enumTypeOid =
@@ -1470,6 +1463,33 @@ findTypeAnalyzeFunction(List *procname, Oid typeOid)
14701463
return procOid;
14711464
}
14721465

1466+
/*
1467+
* AssignTypeArrayOid
1468+
*
1469+
* Pre-assign the type's array OID for use in pg_type.typarray
1470+
*/
1471+
Oid
1472+
AssignTypeArrayOid(void)
1473+
{
1474+
Oid type_array_oid;
1475+
1476+
/* Pre-assign the type's array OID for use in pg_type.typarray */
1477+
if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
1478+
{
1479+
type_array_oid = binary_upgrade_next_pg_type_array_oid;
1480+
binary_upgrade_next_pg_type_array_oid = InvalidOid;
1481+
}
1482+
else
1483+
{
1484+
Relation pg_type = heap_open(TypeRelationId, AccessShareLock);
1485+
1486+
type_array_oid = GetNewOid(pg_type);
1487+
heap_close(pg_type, AccessShareLock);
1488+
}
1489+
1490+
return type_array_oid;
1491+
}
1492+
14731493

14741494
/*-------------------------------------------------------------------
14751495
* DefineCompositeType

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy