1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-19 23:22:23 +03:00

Integrate pg_upgrade_support module into backend

Previously, these functions were created in a schema "binary_upgrade",
which was deleted after pg_upgrade was finished.  Because we don't want
to keep that schema around permanently, move them to pg_catalog but
rename them with a binary_upgrade_... prefix.

The provided functions are only small wrappers around global variables
that were added specifically for pg_upgrade use, so keeping the module
separate does not create any modularity.

The functions still check that they are only called in binary upgrade
mode, so it is not possible to call these during normal operation.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
This commit is contained in:
Peter Eisentraut
2015-03-10 22:33:25 -04:00
parent 936546dcbc
commit 30982be4e5
20 changed files with 61 additions and 208 deletions

View File

@@ -0,0 +1,183 @@
/*
* pg_upgrade_support.c
*
* server-side functions to set backend global variables
* to control oid and relfilenode assignment, and do other special
* hacks needed for pg_upgrade.
*
* Copyright (c) 2010-2015, PostgreSQL Global Development Group
* src/backend/utils/adt/pg_upgrade_support.c
*/
#include "postgres.h"
#include "catalog/binary_upgrade.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "commands/extension.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
Datum binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS);
Datum binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS);
#define CHECK_IS_BINARY_UPGRADE \
do { \
if (!IsBinaryUpgrade) \
ereport(ERROR, \
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \
(errmsg("function can only be called when server is in binary upgrade mode")))); \
} while (0)
Datum
binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_array_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_toast_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_heap_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_index_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_toast_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
{
Oid enumoid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_pg_enum_oid = enumoid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
{
Oid authoid = PG_GETARG_OID(0);
CHECK_IS_BINARY_UPGRADE;
binary_upgrade_next_pg_authid_oid = authoid;
PG_RETURN_VOID();
}
Datum
binary_upgrade_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);
text *extVersion = PG_GETARG_TEXT_PP(3);
Datum extConfig;
Datum extCondition;
List *requiredExtensions;
CHECK_IS_BINARY_UPGRADE;
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,
text_to_cstring(extVersion),
extConfig,
extCondition,
requiredExtensions);
PG_RETURN_VOID();
}