diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-09 19:17:33 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-09 19:18:08 -0500 |
| commit | caddcb8f4b96ce48b612e7c987ecde654d624616 (patch) | |
| tree | 36567671ef6c06350ca1d897fdc2ad49e8a5a7db /contrib/pg_upgrade_support | |
| parent | 2e2d56fea97f43cf8c40a87143bc10356e4ed4d4 (diff) | |
| download | postgresql-caddcb8f4b96ce48b612e7c987ecde654d624616.tar.gz | |
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.
Diffstat (limited to 'contrib/pg_upgrade_support')
| -rw-r--r-- | contrib/pg_upgrade_support/pg_upgrade_support.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/contrib/pg_upgrade_support/pg_upgrade_support.c b/contrib/pg_upgrade_support/pg_upgrade_support.c index b499ff80e6..8b0e474dce 100644 --- a/contrib/pg_upgrade_support/pg_upgrade_support.c +++ b/contrib/pg_upgrade_support/pg_upgrade_support.c @@ -1,8 +1,9 @@ /* - * pg_upgrade_sysoids.c + * pg_upgrade_support.c * * server-side functions to set backend global variables - * to control oid and relfilenode assignment + * to control oid and relfilenode assignment, and do other special + * hacks needed for pg_upgrade. * * Copyright (c) 2010-2011, PostgreSQL Global Development Group * contrib/pg_upgrade_support/pg_upgrade_support.c @@ -12,7 +13,13 @@ #include "fmgr.h" #include "catalog/dependency.h" +#include "catalog/namespace.h" #include "catalog/pg_class.h" +#include "catalog/pg_type.h" +#include "commands/extension.h" +#include "miscadmin.h" +#include "utils/array.h" +#include "utils/builtins.h" /* THIS IS USED ONLY FOR PG >= 9.0 */ @@ -42,6 +49,8 @@ Datum set_next_toast_pg_class_oid(PG_FUNCTION_ARGS); Datum set_next_pg_enum_oid(PG_FUNCTION_ARGS); Datum set_next_pg_authid_oid(PG_FUNCTION_ARGS); +Datum create_empty_extension(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(set_next_pg_type_oid); PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid); PG_FUNCTION_INFO_V1(set_next_toast_pg_type_oid); @@ -53,6 +62,8 @@ PG_FUNCTION_INFO_V1(set_next_toast_pg_class_oid); PG_FUNCTION_INFO_V1(set_next_pg_enum_oid); PG_FUNCTION_INFO_V1(set_next_pg_authid_oid); +PG_FUNCTION_INFO_V1(create_empty_extension); + Datum set_next_pg_type_oid(PG_FUNCTION_ARGS) @@ -133,3 +144,61 @@ set_next_pg_authid_oid(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } +Datum +create_empty_extension(PG_FUNCTION_ARGS) +{ + text *extName = PG_GETARG_TEXT_PP(0); + text *schemaName = PG_GETARG_TEXT_PP(1); + bool relocatable = PG_GETARG_BOOL(2); + char *extVersion; + Datum extConfig; + Datum extCondition; + List *requiredExtensions; + + if (PG_ARGISNULL(3)) + extVersion = NULL; + else + extVersion = text_to_cstring(PG_GETARG_TEXT_PP(3)); + + if (PG_ARGISNULL(4)) + extConfig = PointerGetDatum(NULL); + else + extConfig = PG_GETARG_DATUM(4); + + if (PG_ARGISNULL(5)) + extCondition = PointerGetDatum(NULL); + else + extCondition = PG_GETARG_DATUM(5); + + requiredExtensions = NIL; + if (!PG_ARGISNULL(6)) + { + ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6); + Datum *textDatums; + int ndatums; + int i; + + deconstruct_array(textArray, + TEXTOID, -1, false, 'i', + &textDatums, NULL, &ndatums); + for (i = 0; i < ndatums; i++) + { + text *txtname = DatumGetTextPP(textDatums[i]); + char *extName = text_to_cstring(txtname); + Oid extOid = get_extension_oid(extName, false); + + requiredExtensions = lappend_oid(requiredExtensions, extOid); + } + } + + InsertExtensionTuple(text_to_cstring(extName), + GetUserId(), + get_namespace_oid(text_to_cstring(schemaName), false), + relocatable, + extVersion, + extConfig, + extCondition, + requiredExtensions); + + PG_RETURN_VOID(); +} |
