1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Preserve relfilenodes:

Add support to pg_dump --binary-upgrade to preserve all relfilenodes,
for use by pg_migrator.
This commit is contained in:
Bruce Momjian
2010-01-06 03:04:03 +00:00
parent 3ccb97b2e4
commit f98fbc78c3
9 changed files with 152 additions and 73 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.364 2010/01/02 16:57:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.365 2010/01/06 03:03:58 momjian Exp $
*
*
* INTERFACE ROUTINES
@@ -96,6 +96,9 @@ static Node *cookConstraint(ParseState *pstate,
char *relname);
static List *insert_ordered_unique_oid(List *list, Oid datum);
Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
/* ----------------------------------------------------------------
* XXX UGLY HARD CODED BADNESS FOLLOWS XXX
@@ -942,15 +945,29 @@ heap_create_with_catalog(const char *relname,
errmsg("only shared relations can be placed in pg_global tablespace")));
}
/*
* Allocate an OID for the relation, unless we were told what to use.
*
* The OID will be the relfilenode as well, so make sure it doesn't
* collide with either pg_class OIDs or existing physical files.
*/
if (!OidIsValid(relid))
if ((relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE) &&
OidIsValid(binary_upgrade_next_heap_relfilenode))
{
relid = binary_upgrade_next_heap_relfilenode;
binary_upgrade_next_heap_relfilenode = InvalidOid;
}
else if (relkind == RELKIND_TOASTVALUE &&
OidIsValid(binary_upgrade_next_toast_relfilenode))
{
relid = binary_upgrade_next_toast_relfilenode;
binary_upgrade_next_toast_relfilenode = InvalidOid;
}
else if (!OidIsValid(relid))
{
/*
* Allocate an OID for the relation, unless we were told what to use.
*
* The OID will be the relfilenode as well, so make sure it doesn't
* collide with either pg_class OIDs or existing physical files.
*/
relid = GetNewRelFileNode(reltablespace, shared_relation,
pg_class_desc);
}
/*
* Determine the relation's initial permissions.

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.328 2010/01/02 16:57:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.329 2010/01/06 03:03:58 momjian Exp $
*
*
* INTERFACE ROUTINES
@@ -79,6 +79,9 @@ typedef struct
tups_inserted;
} v_i_state;
/* For simple relation creation, this is the toast index relfilenode */
Oid binary_upgrade_next_index_relfilenode = InvalidOid;
/* non-export function prototypes */
static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
IndexInfo *indexInfo,
@@ -640,15 +643,22 @@ index_create(Oid heapRelationId,
accessMethodObjectId,
classObjectId);
/*
* Allocate an OID for the index, unless we were told what to use.
*
* The OID will be the relfilenode as well, so make sure it doesn't
* collide with either pg_class OIDs or existing physical files.
*/
if (!OidIsValid(indexRelationId))
if (OidIsValid(binary_upgrade_next_index_relfilenode))
{
indexRelationId = binary_upgrade_next_index_relfilenode;
binary_upgrade_next_index_relfilenode = InvalidOid;
}
else if (!OidIsValid(indexRelationId))
{
/*
* Allocate an OID for the index, unless we were told what to use.
*
* The OID will be the relfilenode as well, so make sure it doesn't
* collide with either pg_class OIDs or existing physical files.
*/
indexRelationId = GetNewRelFileNode(tableSpaceId, shared_relation,
pg_class);
}
/*
* create the index relation's relcache entry and physical disk file. (If

View File

@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.26 2010/01/02 16:57:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.27 2010/01/06 03:03:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -32,22 +32,17 @@
#include "utils/syscache.h"
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
extern Oid binary_upgrade_next_toast_relfilenode;
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
Datum reloptions, bool force);
Datum reloptions);
static bool needs_toast_table(Relation rel);
/*
* AlterTableCreateToastTable
* If the table needs a toast table, and doesn't already have one,
* then create a toast table for it. (With the force option, make
* a toast table even if it appears unnecessary.)
*
* The caller can also specify the OID to be used for the toast table.
* Usually, toastOid should be InvalidOid to allow a free OID to be assigned.
* (This option, as well as the force option, is not used by core Postgres,
* but is provided to support pg_migrator.)
* then create a toast table for it.
*
* reloptions for the toast table can be passed, too. Pass (Datum) 0
* for default reloptions.
@@ -57,8 +52,7 @@ static bool needs_toast_table(Relation rel);
* to end with CommandCounterIncrement if it makes any changes.
*/
void
AlterTableCreateToastTable(Oid relOid, Oid toastOid,
Datum reloptions, bool force)
AlterTableCreateToastTable(Oid relOid, Datum reloptions)
{
Relation rel;
@@ -70,7 +64,7 @@ AlterTableCreateToastTable(Oid relOid, Oid toastOid,
rel = heap_open(relOid, AccessExclusiveLock);
/* create_toast_table does all the work */
(void) create_toast_table(rel, toastOid, InvalidOid, reloptions, force);
(void) create_toast_table(rel, InvalidOid, InvalidOid, reloptions);
heap_close(rel, NoLock);
}
@@ -96,7 +90,7 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
relName)));
/* create_toast_table does all the work */
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0, false))
if (!create_toast_table(rel, toastOid, toastIndexOid, (Datum) 0))
elog(ERROR, "\"%s\" does not require a toast table",
relName);
@@ -108,12 +102,11 @@ BootstrapToastTable(char *relName, Oid toastOid, Oid toastIndexOid)
* create_toast_table --- internal workhorse
*
* rel is already opened and exclusive-locked
* toastOid and toastIndexOid are normally InvalidOid, but
* either or both can be nonzero to specify caller-assigned OIDs
* toastOid and toastIndexOid are normally InvalidOid, but during
* bootstrap they can be nonzero to specify hand-assigned OIDs
*/
static bool
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
Datum reloptions, bool force)
create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptions)
{
Oid relOid = RelationGetRelid(rel);
HeapTuple reltup;
@@ -152,12 +145,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
/*
* Check to see whether the table actually needs a TOAST table.
*
* Caller can optionally override this check. (Note: at present no
* callers in core Postgres do so, but this option is needed by
* pg_migrator.)
* If the relfilenode is specified, force toast file creation.
*/
if (!force && !needs_toast_table(rel))
if (!needs_toast_table(rel) &&
!OidIsValid(binary_upgrade_next_toast_relfilenode))
return false;
/*

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.189 2010/01/02 16:57:37 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.190 2010/01/06 03:04:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -743,7 +743,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace)
if (isNull)
reloptions = (Datum) 0;
}
AlterTableCreateToastTable(OIDNewHeap, InvalidOid, reloptions, false);
AlterTableCreateToastTable(OIDNewHeap, reloptions);
if (OidIsValid(toastid))
ReleaseSysCache(tuple);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.313 2010/01/02 16:57:37 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.314 2010/01/06 03:04:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2614,8 +2614,7 @@ ATRewriteCatalogs(List **wqueue)
(tab->subcmds[AT_PASS_ADD_COL] ||
tab->subcmds[AT_PASS_ALTER_TYPE] ||
tab->subcmds[AT_PASS_COL_ATTRS]))
AlterTableCreateToastTable(tab->relid, InvalidOid,
(Datum) 0, false);
AlterTableCreateToastTable(tab->relid, (Datum) 0);
}
}

View File

@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.339 2010/01/02 16:57:40 momjian Exp $
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.340 2010/01/06 03:04:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2194,7 +2194,7 @@ OpenIntoRel(QueryDesc *queryDesc)
(void) heap_reloptions(RELKIND_TOASTVALUE, reloptions, true);
AlterTableCreateToastTable(intoRelationId, InvalidOid, reloptions, false);
AlterTableCreateToastTable(intoRelationId, reloptions);
/*
* And open the constructed table for writing.

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.327 2010/01/05 21:53:58 rhaas Exp $
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.328 2010/01/06 03:04:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -492,14 +492,10 @@ standard_ProcessUtility(Node *parsetree,
"toast",
validnsps,
true, false);
(void) heap_reloptions(RELKIND_TOASTVALUE,
toast_options,
(void) heap_reloptions(RELKIND_TOASTVALUE, toast_options,
true);
AlterTableCreateToastTable(relOid,
InvalidOid,
toast_options,
false);
AlterTableCreateToastTable(relOid, toast_options);
}
else
{