Line data Source code
1 : /*
2 : * pg_upgrade_support.c
3 : *
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.
7 : *
8 : * Copyright (c) 2010-2017, PostgreSQL Global Development Group
9 : * src/backend/utils/adt/pg_upgrade_support.c
10 : */
11 :
12 : #include "postgres.h"
13 :
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"
21 :
22 :
23 : #define CHECK_IS_BINARY_UPGRADE \
24 : do { \
25 : if (!IsBinaryUpgrade) \
26 : ereport(ERROR, \
27 : (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \
28 : (errmsg("function can only be called when server is in binary upgrade mode")))); \
29 : } while (0)
30 :
31 : Datum
32 0 : binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
33 : {
34 0 : Oid typoid = PG_GETARG_OID(0);
35 :
36 0 : CHECK_IS_BINARY_UPGRADE;
37 0 : binary_upgrade_next_pg_type_oid = typoid;
38 :
39 0 : PG_RETURN_VOID();
40 : }
41 :
42 : Datum
43 0 : binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
44 : {
45 0 : Oid typoid = PG_GETARG_OID(0);
46 :
47 0 : CHECK_IS_BINARY_UPGRADE;
48 0 : binary_upgrade_next_array_pg_type_oid = typoid;
49 :
50 0 : PG_RETURN_VOID();
51 : }
52 :
53 : Datum
54 0 : binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
55 : {
56 0 : Oid typoid = PG_GETARG_OID(0);
57 :
58 0 : CHECK_IS_BINARY_UPGRADE;
59 0 : binary_upgrade_next_toast_pg_type_oid = typoid;
60 :
61 0 : PG_RETURN_VOID();
62 : }
63 :
64 : Datum
65 0 : binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
66 : {
67 0 : Oid reloid = PG_GETARG_OID(0);
68 :
69 0 : CHECK_IS_BINARY_UPGRADE;
70 0 : binary_upgrade_next_heap_pg_class_oid = reloid;
71 :
72 0 : PG_RETURN_VOID();
73 : }
74 :
75 : Datum
76 0 : binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
77 : {
78 0 : Oid reloid = PG_GETARG_OID(0);
79 :
80 0 : CHECK_IS_BINARY_UPGRADE;
81 0 : binary_upgrade_next_index_pg_class_oid = reloid;
82 :
83 0 : PG_RETURN_VOID();
84 : }
85 :
86 : Datum
87 0 : binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
88 : {
89 0 : Oid reloid = PG_GETARG_OID(0);
90 :
91 0 : CHECK_IS_BINARY_UPGRADE;
92 0 : binary_upgrade_next_toast_pg_class_oid = reloid;
93 :
94 0 : PG_RETURN_VOID();
95 : }
96 :
97 : Datum
98 0 : binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
99 : {
100 0 : Oid enumoid = PG_GETARG_OID(0);
101 :
102 0 : CHECK_IS_BINARY_UPGRADE;
103 0 : binary_upgrade_next_pg_enum_oid = enumoid;
104 :
105 0 : PG_RETURN_VOID();
106 : }
107 :
108 : Datum
109 0 : binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
110 : {
111 0 : Oid authoid = PG_GETARG_OID(0);
112 :
113 0 : CHECK_IS_BINARY_UPGRADE;
114 0 : binary_upgrade_next_pg_authid_oid = authoid;
115 0 : PG_RETURN_VOID();
116 : }
117 :
118 : Datum
119 0 : binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
120 : {
121 : text *extName;
122 : text *schemaName;
123 : bool relocatable;
124 : text *extVersion;
125 : Datum extConfig;
126 : Datum extCondition;
127 : List *requiredExtensions;
128 :
129 0 : CHECK_IS_BINARY_UPGRADE;
130 :
131 : /* We must check these things before dereferencing the arguments */
132 0 : if (PG_ARGISNULL(0) ||
133 0 : PG_ARGISNULL(1) ||
134 0 : PG_ARGISNULL(2) ||
135 0 : PG_ARGISNULL(3))
136 0 : elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
137 :
138 0 : extName = PG_GETARG_TEXT_PP(0);
139 0 : schemaName = PG_GETARG_TEXT_PP(1);
140 0 : relocatable = PG_GETARG_BOOL(2);
141 0 : extVersion = PG_GETARG_TEXT_PP(3);
142 :
143 0 : if (PG_ARGISNULL(4))
144 0 : extConfig = PointerGetDatum(NULL);
145 : else
146 0 : extConfig = PG_GETARG_DATUM(4);
147 :
148 0 : if (PG_ARGISNULL(5))
149 0 : extCondition = PointerGetDatum(NULL);
150 : else
151 0 : extCondition = PG_GETARG_DATUM(5);
152 :
153 0 : requiredExtensions = NIL;
154 0 : if (!PG_ARGISNULL(6))
155 : {
156 0 : ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
157 : Datum *textDatums;
158 : int ndatums;
159 : int i;
160 :
161 0 : deconstruct_array(textArray,
162 : TEXTOID, -1, false, 'i',
163 : &textDatums, NULL, &ndatums);
164 0 : for (i = 0; i < ndatums; i++)
165 : {
166 0 : char *extName = TextDatumGetCString(textDatums[i]);
167 0 : Oid extOid = get_extension_oid(extName, false);
168 :
169 0 : requiredExtensions = lappend_oid(requiredExtensions, extOid);
170 : }
171 : }
172 :
173 0 : InsertExtensionTuple(text_to_cstring(extName),
174 : GetUserId(),
175 0 : get_namespace_oid(text_to_cstring(schemaName), false),
176 : relocatable,
177 0 : text_to_cstring(extVersion),
178 : extConfig,
179 : extCondition,
180 : requiredExtensions);
181 :
182 0 : PG_RETURN_VOID();
183 : }
184 :
185 : Datum
186 0 : binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
187 : {
188 0 : bool record_init_privs = PG_GETARG_BOOL(0);
189 :
190 0 : CHECK_IS_BINARY_UPGRADE;
191 0 : binary_upgrade_record_init_privs = record_init_privs;
192 :
193 0 : PG_RETURN_VOID();
194 : }
|