mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +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:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user