Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f98fbc7

Browse files
committed
Preserve relfilenodes:
Add support to pg_dump --binary-upgrade to preserve all relfilenodes, for use by pg_migrator.
1 parent 3ccb97b commit f98fbc7

File tree

9 files changed

+152
-73
lines changed

9 files changed

+152
-73
lines changed

src/backend/catalog/heap.c

+25-8
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.364 2010/01/02 16:57:36 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.365 2010/01/06 03:03:58 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -96,6 +96,9 @@ static Node *cookConstraint(ParseState *pstate,
9696
char *relname);
9797
static List *insert_ordered_unique_oid(List *list, Oid datum);
9898

99+
Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
100+
Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
101+
99102

100103
/* ----------------------------------------------------------------
101104
* XXX UGLY HARD CODED BADNESS FOLLOWS XXX
@@ -942,15 +945,29 @@ heap_create_with_catalog(const char *relname,
942945
errmsg("only shared relations can be placed in pg_global tablespace")));
943946
}
944947

945-
/*
946-
* Allocate an OID for the relation, unless we were told what to use.
947-
*
948-
* The OID will be the relfilenode as well, so make sure it doesn't
949-
* collide with either pg_class OIDs or existing physical files.
950-
*/
951-
if (!OidIsValid(relid))
948+
if ((relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE) &&
949+
OidIsValid(binary_upgrade_next_heap_relfilenode))
950+
{
951+
relid = binary_upgrade_next_heap_relfilenode;
952+
binary_upgrade_next_heap_relfilenode = InvalidOid;
953+
}
954+
else if (relkind == RELKIND_TOASTVALUE &&
955+
OidIsValid(binary_upgrade_next_toast_relfilenode))
956+
{
957+
relid = binary_upgrade_next_toast_relfilenode;
958+
binary_upgrade_next_toast_relfilenode = InvalidOid;
959+
}
960+
else if (!OidIsValid(relid))
961+
{
962+
/*
963+
* Allocate an OID for the relation, unless we were told what to use.
964+
*
965+
* The OID will be the relfilenode as well, so make sure it doesn't
966+
* collide with either pg_class OIDs or existing physical files.
967+
*/
952968
relid = GetNewRelFileNode(reltablespace, shared_relation,
953969
pg_class_desc);
970+
}
954971

955972
/*
956973
* Determine the relation's initial permissions.

src/backend/catalog/index.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.328 2010/01/02 16:57:36 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.329 2010/01/06 03:03:58 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -79,6 +79,9 @@ typedef struct
7979
tups_inserted;
8080
} v_i_state;
8181

82+
/* For simple relation creation, this is the toast index relfilenode */
83+
Oid binary_upgrade_next_index_relfilenode = InvalidOid;
84+
8285
/* non-export function prototypes */
8386
static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
8487
IndexInfo *indexInfo,
@@ -640,15 +643,22 @@ index_create(Oid heapRelationId,
640643
accessMethodObjectId,
641644
classObjectId);
642645

643-
/*
644-
* Allocate an OID for the index, unless we were told what to use.
645-
*
646-
* The OID will be the relfilenode as well, so make sure it doesn't
647-
* collide with either pg_class OIDs or existing physical files.
648-
*/
649-
if (!OidIsValid(indexRelationId))
646+
if (OidIsValid(binary_upgrade_next_index_relfilenode))
647+
{
648+
indexRelationId = binary_upgrade_next_index_relfilenode;
649+
binary_upgrade_next_index_relfilenode = InvalidOid;
650+
}
651+
else if (!OidIsValid(indexRelationId))
652+
{
653+
/*
654+
* Allocate an OID for the index, unless we were told what to use.
655+
*
656+
* The OID will be the relfilenode as well, so make sure it doesn't
657+
* collide with either pg_class OIDs or existing physical files.
658+
*/
650659
indexRelationId = GetNewRelFileNode(tableSpaceId, shared_relation,
651660
pg_class);
661+
}
652662

653663
/*
654664
* create the index relation's relcache entry and physical disk file. (If

src/backend/catalog/toasting.c

+13-22
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.26 2010/01/02 16:57:36 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.27 2010/01/06 03:03:58 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,22 +32,17 @@
3232
#include "utils/syscache.h"
3333

3434
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
35+
extern Oid binary_upgrade_next_toast_relfilenode;
3536

3637
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
37-
Datum reloptions, bool force);
38+
Datum reloptions);
3839
static bool needs_toast_table(Relation rel);
3940

4041

4142
/*
4243
* AlterTableCreateToastTable
4344
* If the table needs a toast table, and doesn't already have one,
44-
* then create a toast table for it. (With the force option, make
45-
* a toast table even if it appears unnecessary.)
46-
*
47-
* The caller can also specify the OID to be used for the toast table.
48-
* Usually, toastOid should be InvalidOid to allow a free OID to be assigned.
49-
* (This option, as well as the force option, is not used by core Postgres,
50-
* but is provided to support pg_migrator.)
45+
* then create a toast table for it.
5146
*
5247
* reloptions for the toast table can be passed, too. Pass (Datum) 0
5348
* for default reloptions.
@@ -57,8 +52,7 @@ static bool needs_toast_table(Relation rel);
5752
* to end with CommandCounterIncrement if it makes any changes.
5853
*/
5954
void
60-
AlterTableCreateToastTable(Oid relOid, Oid toastOid,
61-
Datum reloptions, bool force)
55+
AlterTableCreateToastTable(Oid relOid, Datum reloptions)
6256
{
6357
Relation rel;
6458

@@ -70,7 +64,7 @@ AlterTableCreateToastTable(Oid relOid, Oid toastOid,
7064
rel = heap_open(relOid, AccessExclusiveLock);
7165

7266
/* create_toast_table does all the work */
73-
(void) create_toast_table(rel, toastOid, InvalidOid, reloptions, force);
67+
(void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions);
7468

7569
heap_close(rel, NoLock);
7670
}
@@ -96,7 +90,7 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
9690
relName)));
9791

9892
/* create_toast_table does all the work */
99-
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0, false))
93+
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0))
10094
elog(ERROR, "\"%s\" does not require a toast table",
10195
relName);
10296

@@ -108,12 +102,11 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
108102
* create_toast_table --- internal workhorse
109103
*
110104
* rel is already opened and exclusive-locked
111-
* toastOid and toastIndexOid are normally InvalidOid, but
112-
* either or both can be nonzero to specify caller-assigned OIDs
105+
* toastOid and toastIndexOid are normally InvalidOid, but during
106+
* bootstrap they can be nonzero to specify hand-assigned OIDs
113107
*/
114108
static bool
115-
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
116-
Datum reloptions, bool force)
109+
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptions)
117110
{
118111
Oid relOid = RelationGetRelid(rel);
119112
HeapTuple reltup;
@@ -152,12 +145,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
152145

153146
/*
154147
* Check to see whether the table actually needs a TOAST table.
155-
*
156-
* Caller can optionally override this check. (Note: at present no
157-
* callers in core Postgres do so, but this option is needed by
158-
* pg_migrator.)
148+
* If the relfilenode is specified, force toast file creation.
159149
*/
160-
if (!force && !needs_toast_table(rel))
150+
if (!needs_toast_table(rel) &&
151+
!OidIsValid(binary_upgrade_next_toast_relfilenode))
161152
return false;
162153

163154
/*

src/backend/commands/cluster.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.189 2010/01/02 16:57:37 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.190 2010/01/06 03:04:00 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -743,7 +743,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
743743
if (isNull)
744744
reloptions = (Datum) 0;
745745
}
746-
AlterTableCreateToastTable(OIDNewHeap, InvalidOid, reloptions, false);
746+
AlterTableCreateToastTable(OIDNewHeap, reloptions);
747747

748748
if (OidIsValid(toastid))
749749
ReleaseSysCache(tuple);

src/backend/commands/tablecmds.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.313 2010/01/02 16:57:37 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.314 2010/01/06 03:04:00 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2614,8 +2614,7 @@ ATRewriteCatalogs(List **wqueue)
26142614
(tab->subcmds[AT_PASS_ADD_COL] ||
26152615
tab->subcmds[AT_PASS_ALTER_TYPE] ||
26162616
tab->subcmds[AT_PASS_COL_ATTRS]))
2617-
AlterTableCreateToastTable(tab->relid, InvalidOid,
2618-
(Datum) 0, false);
2617+
AlterTableCreateToastTable(tab->relid, (Datum) 0);
26192618
}
26202619
}
26212620

src/backend/executor/execMain.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.339 2010/01/02 16:57:40 momjian Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.340 2010/01/06 03:04:01 momjian Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -2194,7 +2194,7 @@ OpenIntoRel(QueryDesc *queryDesc)
21942194

21952195
(void) heap_reloptions(RELKIND_TOASTVALUE, reloptions, true);
21962196

2197-
AlterTableCreateToastTable(intoRelationId, InvalidOid, reloptions, false);
2197+
AlterTableCreateToastTable(intoRelationId, reloptions);
21982198

21992199
/*
22002200
* And open the constructed table for writing.

src/backend/tcop/utility.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.327 2010/01/05 21:53:58 rhaas Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.328 2010/01/06 03:04:01 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -492,14 +492,10 @@ standard_ProcessUtility(Node *parsetree,
492492
"toast",
493493
validnsps,
494494
true, false);
495-
(void) heap_reloptions(RELKIND_TOASTVALUE,
496-
toast_options,
495+
(void) heap_reloptions(RELKIND_TOASTVALUE, toast_options,
497496
true);
498497

499-
AlterTableCreateToastTable(relOid,
500-
InvalidOid,
501-
toast_options,
502-
false);
498+
AlterTableCreateToastTable(relOid, toast_options);
503499
}
504500
else
505501
{

0 commit comments

Comments
 (0)