1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Fix pg_upgrade to handle extensions.

This follows my proposal of yesterday, namely that we try to recreate the
previous state of the extension exactly, instead of allowing CREATE
EXTENSION to run a SQL script that might create some entirely-incompatible
on-disk state.  In --binary-upgrade mode, pg_dump won't issue CREATE
EXTENSION at all, but instead uses a kluge function provided by
pg_upgrade_support to recreate the pg_extension row (and extension-level
pg_depend entries) without creating any member objects.  The member objects
are then restored in the same way as if they weren't members, in particular
using pg_upgrade's normal hacks to preserve OIDs that need to be preserved.
Then, for each member object, ALTER EXTENSION ADD is issued to recreate the
pg_depend entry that marks it as an extension member.

In passing, fix breakage in pg_upgrade's enum-type support: somebody didn't
fix it when the noise word VALUE got added to ALTER TYPE ADD.  Also,
rationalize parsetree representation of COMMENT ON DOMAIN and fix
get_object_address() to allow OBJECT_DOMAIN.
This commit is contained in:
Tom Lane
2011-02-09 19:17:33 -05:00
parent 2e2d56fea9
commit caddcb8f4b
10 changed files with 544 additions and 183 deletions

View File

@ -139,6 +139,7 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
address = get_object_address_unqualified(objtype, objname);
break;
case OBJECT_TYPE:
case OBJECT_DOMAIN:
address.classId = TypeRelationId;
address.objectId =
typenameTypeId(NULL, makeTypeNameFromNameList(objname));

View File

@ -105,6 +105,7 @@ CommentObject(CommentStmt *stmt)
strVal(linitial(stmt->objname)));
break;
case OBJECT_TYPE:
case OBJECT_DOMAIN:
if (!pg_type_ownercheck(address.objectId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
format_type_be(address.objectId));

View File

@ -648,13 +648,7 @@ CreateExtension(CreateExtensionStmt *stmt)
ExtensionControlFile *control;
List *requiredExtensions;
List *requiredSchemas;
Relation rel;
Datum values[Natts_pg_extension];
bool nulls[Natts_pg_extension];
HeapTuple tuple;
Oid extensionOid;
ObjectAddress myself;
ObjectAddress nsp;
ListCell *lc;
/* Must be super user */
@ -801,7 +795,58 @@ CreateExtension(CreateExtensionStmt *stmt)
}
/*
* Insert new tuple into pg_extension.
* Insert new tuple into pg_extension, and create dependency entries.
*/
extensionOid = InsertExtensionTuple(control->name, extowner,
schemaOid, control->relocatable,
control->version,
PointerGetDatum(NULL),
PointerGetDatum(NULL),
requiredExtensions);
/*
* Apply any comment on extension
*/
if (control->comment != NULL)
CreateComments(extensionOid, ExtensionRelationId, 0, control->comment);
/*
* Finally, execute the extension script to create the member objects
*/
execute_extension_script(extensionOid, control, requiredSchemas,
schemaName, schemaOid);
}
/*
* InsertExtensionTuple
*
* Insert the new pg_extension row, and create extension's dependency entries.
* Return the OID assigned to the new row.
*
* This is exported for the benefit of pg_upgrade, which has to create a
* pg_extension entry (and the extension-level dependencies) without
* actually running the extension's script.
*
* extConfig and extCondition should be arrays or PointerGetDatum(NULL).
* We declare them as plain Datum to avoid needing array.h in extension.h.
*/
Oid
InsertExtensionTuple(const char *extName, Oid extOwner,
Oid schemaOid, bool relocatable, const char *extVersion,
Datum extConfig, Datum extCondition,
List *requiredExtensions)
{
Oid extensionOid;
Relation rel;
Datum values[Natts_pg_extension];
bool nulls[Natts_pg_extension];
HeapTuple tuple;
ObjectAddress myself;
ObjectAddress nsp;
ListCell *lc;
/*
* Build and insert the pg_extension tuple
*/
rel = heap_open(ExtensionRelationId, RowExclusiveLock);
@ -809,19 +854,26 @@ CreateExtension(CreateExtensionStmt *stmt)
memset(nulls, 0, sizeof(nulls));
values[Anum_pg_extension_extname - 1] =
DirectFunctionCall1(namein, CStringGetDatum(control->name));
values[Anum_pg_extension_extowner - 1] = ObjectIdGetDatum(extowner);
DirectFunctionCall1(namein, CStringGetDatum(extName));
values[Anum_pg_extension_extowner - 1] = ObjectIdGetDatum(extOwner);
values[Anum_pg_extension_extnamespace - 1] = ObjectIdGetDatum(schemaOid);
values[Anum_pg_extension_extrelocatable - 1] = BoolGetDatum(control->relocatable);
values[Anum_pg_extension_extrelocatable - 1] = BoolGetDatum(relocatable);
if (control->version == NULL)
if (extVersion == NULL)
nulls[Anum_pg_extension_extversion - 1] = true;
else
values[Anum_pg_extension_extversion - 1] =
CStringGetTextDatum(control->version);
CStringGetTextDatum(extVersion);
nulls[Anum_pg_extension_extconfig - 1] = true;
nulls[Anum_pg_extension_extcondition - 1] = true;
if (extConfig == PointerGetDatum(NULL))
nulls[Anum_pg_extension_extconfig - 1] = true;
else
values[Anum_pg_extension_extconfig - 1] = extConfig;
if (extCondition == PointerGetDatum(NULL))
nulls[Anum_pg_extension_extcondition - 1] = true;
else
values[Anum_pg_extension_extcondition - 1] = extCondition;
tuple = heap_form_tuple(rel->rd_att, values, nulls);
@ -831,16 +883,10 @@ CreateExtension(CreateExtensionStmt *stmt)
heap_freetuple(tuple);
heap_close(rel, RowExclusiveLock);
/*
* Apply any comment on extension
*/
if (control->comment != NULL)
CreateComments(extensionOid, ExtensionRelationId, 0, control->comment);
/*
* Record dependencies on owner, schema, and prerequisite extensions
*/
recordDependencyOnOwner(ExtensionRelationId, extensionOid, extowner);
recordDependencyOnOwner(ExtensionRelationId, extensionOid, extOwner);
myself.classId = ExtensionRelationId;
myself.objectId = extensionOid;
@ -864,11 +910,7 @@ CreateExtension(CreateExtensionStmt *stmt)
recordDependencyOn(&myself, &otherext, DEPENDENCY_NORMAL);
}
/*
* Finally, execute the extension script to create the member objects
*/
execute_extension_script(extensionOid, control, requiredSchemas,
schemaName, schemaOid);
return extensionOid;
}

View File

@ -4790,7 +4790,7 @@ comment_type:
| INDEX { $$ = OBJECT_INDEX; }
| SEQUENCE { $$ = OBJECT_SEQUENCE; }
| TABLE { $$ = OBJECT_TABLE; }
| DOMAIN_P { $$ = OBJECT_TYPE; }
| DOMAIN_P { $$ = OBJECT_DOMAIN; }
| TYPE_P { $$ = OBJECT_TYPE; }
| VIEW { $$ = OBJECT_VIEW; }
| CONVERSION_P { $$ = OBJECT_CONVERSION; }

View File

@ -463,6 +463,7 @@ AssignDumpId(DumpableObject *dobj)
dobj->name = NULL; /* must be set later */
dobj->namespace = NULL; /* may be set later */
dobj->dump = true; /* default assumption */
dobj->ext_member = false; /* default assumption */
dobj->dependencies = NULL;
dobj->nDeps = 0;
dobj->allocDeps = 0;

File diff suppressed because it is too large Load Diff

View File

@ -128,6 +128,7 @@ typedef struct _dumpableObject
char *name; /* object name (should never be NULL) */
struct _namespaceInfo *namespace; /* containing namespace, or NULL */
bool dump; /* true if we want to dump this object */
bool ext_member; /* true if object is member of extension */
DumpId *dependencies; /* dumpIds of objects this one depends on */
int nDeps; /* number of valid dependencies */
int allocDeps; /* allocated size of dependencies[] */
@ -144,6 +145,8 @@ typedef struct _extensionInfo
{
DumpableObject dobj;
char *namespace; /* schema containing extension's objects */
bool relocatable;
char *extversion;
char *extconfig; /* info about configuration tables */
char *extcondition;
} ExtensionInfo;

View File

@ -32,6 +32,11 @@ extern void CreateExtension(CreateExtensionStmt *stmt);
extern void RemoveExtensions(DropStmt *stmt);
extern void RemoveExtensionById(Oid extId);
extern Oid InsertExtensionTuple(const char *extName, Oid extOwner,
Oid schemaOid, bool relocatable, const char *extVersion,
Datum extConfig, Datum extCondition,
List *requiredExtensions);
extern void ExecAlterExtensionAddStmt(AlterExtensionAddStmt *stmt);
extern Oid get_extension_oid(const char *extname, bool missing_ok);