aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_upgrade_support.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2015-03-10 22:33:25 -0400
committerPeter Eisentraut <peter_e@gmx.net>2015-04-14 19:26:37 -0400
commit30982be4e5019684e1772dd9170aaa53f5a8e894 (patch)
treeee83c2fa412fb58cfb12c0a74211fb76b8b5eed7 /src/backend/utils/adt/pg_upgrade_support.c
parent936546dcbc24ad1f2b3d33e73aa5c5fde4d2be84 (diff)
downloadpostgresql-30982be4e5019684e1772dd9170aaa53f5a8e894.tar.gz
postgresql-30982be4e5019684e1772dd9170aaa53f5a8e894.zip
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>
Diffstat (limited to 'src/backend/utils/adt/pg_upgrade_support.c')
-rw-r--r--src/backend/utils/adt/pg_upgrade_support.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pg_upgrade_support.c b/src/backend/utils/adt/pg_upgrade_support.c
new file mode 100644
index 00000000000..d69fa53567b
--- /dev/null
+++ b/src/backend/utils/adt/pg_upgrade_support.c
@@ -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();
+}