4 * server-side functions to set backend global variables
5 * to control oid and relfilenode assignment, and do other special
6 * hacks needed for pg_upgrade.
8 * Copyright (c) 2010-2016, PostgreSQL Global Development Group
9 * src/backend/utils/adt/pg_upgrade_support.c
14 #include "catalog/binary_upgrade.h"
15 #include "catalog/namespace.h"
16 #include "catalog/pg_type.h"
17 #include "commands/extension.h"
18 #include "miscadmin.h"
19 #include "utils/array.h"
20 #include "utils/builtins.h"
23 Datum binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS);
24 Datum binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
25 Datum binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
26 Datum binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS);
27 Datum binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS);
28 Datum binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
29 Datum binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS);
30 Datum binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS);
31 Datum binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS);
34 #define CHECK_IS_BINARY_UPGRADE \
36 if (!IsBinaryUpgrade) \
38 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \
39 (errmsg("function can only be called when server is in binary upgrade mode")))); \
43 binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
45 Oid typoid = PG_GETARG_OID(0);
47 CHECK_IS_BINARY_UPGRADE;
48 binary_upgrade_next_pg_type_oid = typoid;
54 binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
56 Oid typoid = PG_GETARG_OID(0);
58 CHECK_IS_BINARY_UPGRADE;
59 binary_upgrade_next_array_pg_type_oid = typoid;
65 binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
67 Oid typoid = PG_GETARG_OID(0);
69 CHECK_IS_BINARY_UPGRADE;
70 binary_upgrade_next_toast_pg_type_oid = typoid;
76 binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
78 Oid reloid = PG_GETARG_OID(0);
80 CHECK_IS_BINARY_UPGRADE;
81 binary_upgrade_next_heap_pg_class_oid = reloid;
87 binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
89 Oid reloid = PG_GETARG_OID(0);
91 CHECK_IS_BINARY_UPGRADE;
92 binary_upgrade_next_index_pg_class_oid = reloid;
98 binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
100 Oid reloid = PG_GETARG_OID(0);
102 CHECK_IS_BINARY_UPGRADE;
103 binary_upgrade_next_toast_pg_class_oid = reloid;
109 binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
111 Oid enumoid = PG_GETARG_OID(0);
113 CHECK_IS_BINARY_UPGRADE;
114 binary_upgrade_next_pg_enum_oid = enumoid;
120 binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
122 Oid authoid = PG_GETARG_OID(0);
124 CHECK_IS_BINARY_UPGRADE;
125 binary_upgrade_next_pg_authid_oid = authoid;
130 binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
132 text *extName = PG_GETARG_TEXT_PP(0);
133 text *schemaName = PG_GETARG_TEXT_PP(1);
134 bool relocatable = PG_GETARG_BOOL(2);
135 text *extVersion = PG_GETARG_TEXT_PP(3);
138 List *requiredExtensions;
140 CHECK_IS_BINARY_UPGRADE;
143 extConfig = PointerGetDatum(NULL);
145 extConfig = PG_GETARG_DATUM(4);
148 extCondition = PointerGetDatum(NULL);
150 extCondition = PG_GETARG_DATUM(5);
152 requiredExtensions = NIL;
153 if (!PG_ARGISNULL(6))
155 ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
160 deconstruct_array(textArray,
161 TEXTOID, -1, false, 'i',
162 &textDatums, NULL, &ndatums);
163 for (i = 0; i < ndatums; i++)
165 text *txtname = DatumGetTextPP(textDatums[i]);
166 char *extName = text_to_cstring(txtname);
167 Oid extOid = get_extension_oid(extName, false);
169 requiredExtensions = lappend_oid(requiredExtensions, extOid);
173 InsertExtensionTuple(text_to_cstring(extName),
175 get_namespace_oid(text_to_cstring(schemaName), false),
177 text_to_cstring(extVersion),