PostgreSQL Source Code  git master
pg_upgrade_support.c
Go to the documentation of this file.
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-2020, 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/heap.h"
16 #include "catalog/namespace.h"
17 #include "catalog/pg_type.h"
18 #include "commands/extension.h"
19 #include "miscadmin.h"
20 #include "utils/array.h"
21 #include "utils/builtins.h"
22 
23 
24 #define CHECK_IS_BINARY_UPGRADE \
25 do { \
26  if (!IsBinaryUpgrade) \
27  ereport(ERROR, \
28  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \
29  errmsg("function can only be called when server is in binary upgrade mode"))); \
30 } while (0)
31 
32 Datum
34 {
35  Oid typoid = PG_GETARG_OID(0);
36 
39 
41 }
42 
43 Datum
45 {
46  Oid typoid = PG_GETARG_OID(0);
47 
50 
52 }
53 
54 Datum
56 {
57  Oid reloid = PG_GETARG_OID(0);
58 
61 
63 }
64 
65 Datum
67 {
68  Oid reloid = PG_GETARG_OID(0);
69 
72 
74 }
75 
76 Datum
78 {
79  Oid reloid = PG_GETARG_OID(0);
80 
83 
85 }
86 
87 Datum
89 {
90  Oid enumoid = PG_GETARG_OID(0);
91 
94 
96 }
97 
98 Datum
100 {
101  Oid authoid = PG_GETARG_OID(0);
102 
105  PG_RETURN_VOID();
106 }
107 
108 Datum
110 {
111  text *extName;
112  text *schemaName;
113  bool relocatable;
114  text *extVersion;
115  Datum extConfig;
116  Datum extCondition;
117  List *requiredExtensions;
118 
120 
121  /* We must check these things before dereferencing the arguments */
122  if (PG_ARGISNULL(0) ||
123  PG_ARGISNULL(1) ||
124  PG_ARGISNULL(2) ||
125  PG_ARGISNULL(3))
126  elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
127 
128  extName = PG_GETARG_TEXT_PP(0);
129  schemaName = PG_GETARG_TEXT_PP(1);
130  relocatable = PG_GETARG_BOOL(2);
131  extVersion = PG_GETARG_TEXT_PP(3);
132 
133  if (PG_ARGISNULL(4))
134  extConfig = PointerGetDatum(NULL);
135  else
136  extConfig = PG_GETARG_DATUM(4);
137 
138  if (PG_ARGISNULL(5))
139  extCondition = PointerGetDatum(NULL);
140  else
141  extCondition = PG_GETARG_DATUM(5);
142 
143  requiredExtensions = NIL;
144  if (!PG_ARGISNULL(6))
145  {
146  ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
147  Datum *textDatums;
148  int ndatums;
149  int i;
150 
151  deconstruct_array(textArray,
152  TEXTOID, -1, false, TYPALIGN_INT,
153  &textDatums, NULL, &ndatums);
154  for (i = 0; i < ndatums; i++)
155  {
156  char *extName = TextDatumGetCString(textDatums[i]);
157  Oid extOid = get_extension_oid(extName, false);
158 
159  requiredExtensions = lappend_oid(requiredExtensions, extOid);
160  }
161  }
162 
164  GetUserId(),
165  get_namespace_oid(text_to_cstring(schemaName), false),
166  relocatable,
167  text_to_cstring(extVersion),
168  extConfig,
169  extCondition,
170  requiredExtensions);
171 
172  PG_RETURN_VOID();
173 }
174 
175 Datum
177 {
178  bool record_init_privs = PG_GETARG_BOOL(0);
179 
181  binary_upgrade_record_init_privs = record_init_privs;
182 
183  PG_RETURN_VOID();
184 }
185 
186 Datum
188 {
189  Oid table_id = PG_GETARG_OID(0);
192  char *cattname = text_to_cstring(attname);
193  char *cvalue = text_to_cstring(value);
194 
196  SetAttrMissing(table_id, cattname, cvalue);
197 
198  PG_RETURN_VOID();
199 }
#define NIL
Definition: pg_list.h:65
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
Oid binary_upgrade_next_pg_authid_oid
Definition: user.c:42
Oid binary_upgrade_next_heap_pg_class_oid
Definition: heap.c:92
bool binary_upgrade_record_init_privs
Definition: aclchk.c:101
Oid GetUserId(void)
Definition: miscinit.c:450
Oid binary_upgrade_next_toast_pg_class_oid
Definition: heap.c:93
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
Oid binary_upgrade_next_index_pg_class_oid
Definition: index.c:85
Datum binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition: heap.c:2137
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:357
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
Datum binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
Oid binary_upgrade_next_pg_enum_oid
Definition: pg_enum.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
Oid binary_upgrade_next_pg_type_oid
Definition: pg_type.c:40
Datum binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
#define TextDatumGetCString(d)
Definition: builtins.h:88
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
#define PG_RETURN_VOID()
Definition: fmgr.h:348
Datum binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
Datum binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition: extension.c:1774
Oid binary_upgrade_next_array_pg_type_oid
Definition: typecmds.c:107
Datum binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3483
char * text_to_cstring(const text *t)
Definition: varlena.c:205
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
Datum binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
Datum binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:335
#define elog(elevel,...)
Definition: elog.h:214
int i
Definition: c.h:562
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
Datum binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
Datum binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
Definition: pg_list.h:50
#define CHECK_IS_BINARY_UPGRADE