PostgreSQL Source Code  git master
pg_upgrade_support.c File Reference
#include "postgres.h"
#include "catalog/binary_upgrade.h"
#include "catalog/heap.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"
Include dependency graph for pg_upgrade_support.c:

Go to the source code of this file.

Macros

#define CHECK_IS_BINARY_UPGRADE
 

Functions

Datum binary_upgrade_set_next_pg_tablespace_oid (PG_FUNCTION_ARGS)
 
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_multirange_pg_type_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_multirange_array_pg_type_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_heap_pg_class_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_heap_relfilenode (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_index_pg_class_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_index_relfilenode (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_toast_pg_class_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_toast_relfilenode (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)
 
Datum binary_upgrade_set_record_init_privs (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_missing_value (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ CHECK_IS_BINARY_UPGRADE

#define CHECK_IS_BINARY_UPGRADE
Value:
do { \
ereport(ERROR, \
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \
errmsg("function can only be called when server is in binary upgrade mode"))); \
} while (0)
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
bool IsBinaryUpgrade
Definition: globals.c:114

Definition at line 24 of file pg_upgrade_support.c.

Function Documentation

◆ binary_upgrade_create_empty_extension()

Datum binary_upgrade_create_empty_extension ( PG_FUNCTION_ARGS  )

Definition at line 175 of file pg_upgrade_support.c.

176 {
177  text *extName;
178  text *schemaName;
179  bool relocatable;
180  text *extVersion;
181  Datum extConfig;
182  Datum extCondition;
183  List *requiredExtensions;
184 
186 
187  /* We must check these things before dereferencing the arguments */
188  if (PG_ARGISNULL(0) ||
189  PG_ARGISNULL(1) ||
190  PG_ARGISNULL(2) ||
191  PG_ARGISNULL(3))
192  elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
193 
194  extName = PG_GETARG_TEXT_PP(0);
195  schemaName = PG_GETARG_TEXT_PP(1);
196  relocatable = PG_GETARG_BOOL(2);
197  extVersion = PG_GETARG_TEXT_PP(3);
198 
199  if (PG_ARGISNULL(4))
200  extConfig = PointerGetDatum(NULL);
201  else
202  extConfig = PG_GETARG_DATUM(4);
203 
204  if (PG_ARGISNULL(5))
205  extCondition = PointerGetDatum(NULL);
206  else
207  extCondition = PG_GETARG_DATUM(5);
208 
209  requiredExtensions = NIL;
210  if (!PG_ARGISNULL(6))
211  {
212  ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
213  Datum *textDatums;
214  int ndatums;
215  int i;
216 
217  deconstruct_array_builtin(textArray, TEXTOID, &textDatums, NULL, &ndatums);
218  for (i = 0; i < ndatums; i++)
219  {
220  char *extName = TextDatumGetCString(textDatums[i]);
221  Oid extOid = get_extension_oid(extName, false);
222 
223  requiredExtensions = lappend_oid(requiredExtensions, extOid);
224  }
225  }
226 
228  GetUserId(),
229  get_namespace_oid(text_to_cstring(schemaName), false),
230  relocatable,
231  text_to_cstring(extVersion),
232  extConfig,
233  extCondition,
234  requiredExtensions);
235 
236  PG_RETURN_VOID();
237 }
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:256
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3642
#define TextDatumGetCString(d)
Definition: builtins.h:86
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition: extension.c:1802
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:142
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
int i
Definition: isn.c:73
List * lappend_oid(List *list, Oid datum)
Definition: list.c:374
Oid GetUserId(void)
Definition: miscinit.c:497
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3086
#define NIL
Definition: pg_list.h:66
#define CHECK_IS_BINARY_UPGRADE
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
uintptr_t Datum
Definition: postgres.h:412
unsigned int Oid
Definition: postgres_ext.h:31
Definition: pg_list.h:52
Definition: c.h:623
char * text_to_cstring(const text *t)
Definition: varlena.c:222

References CHECK_IS_BINARY_UPGRADE, deconstruct_array_builtin(), elog(), ERROR, get_extension_oid(), get_namespace_oid(), GetUserId(), i, InsertExtensionTuple(), lappend_oid(), NIL, PG_ARGISNULL, PG_GETARG_ARRAYTYPE_P, PG_GETARG_BOOL, PG_GETARG_DATUM, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PointerGetDatum(), text_to_cstring(), and TextDatumGetCString.

◆ binary_upgrade_set_missing_value()

Datum binary_upgrade_set_missing_value ( PG_FUNCTION_ARGS  )

Definition at line 251 of file pg_upgrade_support.c.

252 {
253  Oid table_id = PG_GETARG_OID(0);
256  char *cattname = text_to_cstring(attname);
257  char *cvalue = text_to_cstring(value);
258 
260  SetAttrMissing(table_id, cattname, cvalue);
261 
262  PG_RETURN_VOID();
263 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition: heap.c:2003
static struct @143 value
NameData attname
Definition: pg_attribute.h:41

References attname, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, PG_GETARG_TEXT_P, PG_RETURN_VOID, SetAttrMissing(), text_to_cstring(), and value.

◆ binary_upgrade_set_next_array_pg_type_oid()

Datum binary_upgrade_set_next_array_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 55 of file pg_upgrade_support.c.

56 {
57  Oid typoid = PG_GETARG_OID(0);
58 
61 
63 }
Oid binary_upgrade_next_array_pg_type_oid
Definition: typecmds.c:109

References binary_upgrade_next_array_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_heap_pg_class_oid()

Datum binary_upgrade_set_next_heap_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 88 of file pg_upgrade_support.c.

89 {
90  Oid reloid = PG_GETARG_OID(0);
91 
94 
96 }
Oid binary_upgrade_next_heap_pg_class_oid
Definition: heap.c:79

References binary_upgrade_next_heap_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_heap_relfilenode()

Datum binary_upgrade_set_next_heap_relfilenode ( PG_FUNCTION_ARGS  )

Definition at line 99 of file pg_upgrade_support.c.

100 {
101  RelFileNumber relfilenumber = PG_GETARG_OID(0);
102 
105 
106  PG_RETURN_VOID();
107 }
RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber
Definition: heap.c:81
Oid RelFileNumber
Definition: relpath.h:25

References binary_upgrade_next_heap_pg_class_relfilenumber, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_index_pg_class_oid()

Datum binary_upgrade_set_next_index_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 110 of file pg_upgrade_support.c.

111 {
112  Oid reloid = PG_GETARG_OID(0);
113 
116 
117  PG_RETURN_VOID();
118 }
Oid binary_upgrade_next_index_pg_class_oid
Definition: index.c:89

References binary_upgrade_next_index_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_index_relfilenode()

Datum binary_upgrade_set_next_index_relfilenode ( PG_FUNCTION_ARGS  )

Definition at line 121 of file pg_upgrade_support.c.

122 {
123  RelFileNumber relfilenumber = PG_GETARG_OID(0);
124 
127 
128  PG_RETURN_VOID();
129 }
RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber
Definition: index.c:90

References binary_upgrade_next_index_pg_class_relfilenumber, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_multirange_array_pg_type_oid()

Datum binary_upgrade_set_next_multirange_array_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 77 of file pg_upgrade_support.c.

78 {
79  Oid typoid = PG_GETARG_OID(0);
80 
83 
85 }
Oid binary_upgrade_next_mrng_array_pg_type_oid
Definition: typecmds.c:111

References binary_upgrade_next_mrng_array_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_multirange_pg_type_oid()

Datum binary_upgrade_set_next_multirange_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 66 of file pg_upgrade_support.c.

67 {
68  Oid typoid = PG_GETARG_OID(0);
69 
72 
74 }
Oid binary_upgrade_next_mrng_pg_type_oid
Definition: typecmds.c:110

References binary_upgrade_next_mrng_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_pg_authid_oid()

Datum binary_upgrade_set_next_pg_authid_oid ( PG_FUNCTION_ARGS  )

Definition at line 165 of file pg_upgrade_support.c.

166 {
167  Oid authoid = PG_GETARG_OID(0);
168 
171  PG_RETURN_VOID();
172 }
Oid binary_upgrade_next_pg_authid_oid
Definition: user.c:70

References binary_upgrade_next_pg_authid_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_pg_enum_oid()

Datum binary_upgrade_set_next_pg_enum_oid ( PG_FUNCTION_ARGS  )

Definition at line 154 of file pg_upgrade_support.c.

155 {
156  Oid enumoid = PG_GETARG_OID(0);
157 
160 
161  PG_RETURN_VOID();
162 }
Oid binary_upgrade_next_pg_enum_oid
Definition: pg_enum.c:36

References binary_upgrade_next_pg_enum_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_pg_tablespace_oid()

Datum binary_upgrade_set_next_pg_tablespace_oid ( PG_FUNCTION_ARGS  )

Definition at line 33 of file pg_upgrade_support.c.

34 {
35  Oid tbspoid = PG_GETARG_OID(0);
36 
39 
41 }
Oid binary_upgrade_next_pg_tablespace_oid
Definition: tablespace.c:93

References binary_upgrade_next_pg_tablespace_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_pg_type_oid()

Datum binary_upgrade_set_next_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 44 of file pg_upgrade_support.c.

45 {
46  Oid typoid = PG_GETARG_OID(0);
47 
50 
52 }
Oid binary_upgrade_next_pg_type_oid
Definition: pg_type.c:42

References binary_upgrade_next_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_toast_pg_class_oid()

Datum binary_upgrade_set_next_toast_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 132 of file pg_upgrade_support.c.

133 {
134  Oid reloid = PG_GETARG_OID(0);
135 
138 
139  PG_RETURN_VOID();
140 }
Oid binary_upgrade_next_toast_pg_class_oid
Definition: heap.c:80

References binary_upgrade_next_toast_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_next_toast_relfilenode()

Datum binary_upgrade_set_next_toast_relfilenode ( PG_FUNCTION_ARGS  )

Definition at line 143 of file pg_upgrade_support.c.

144 {
145  RelFileNumber relfilenumber = PG_GETARG_OID(0);
146 
149 
150  PG_RETURN_VOID();
151 }
RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber
Definition: heap.c:82

References binary_upgrade_next_toast_pg_class_relfilenumber, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

◆ binary_upgrade_set_record_init_privs()

Datum binary_upgrade_set_record_init_privs ( PG_FUNCTION_ARGS  )

Definition at line 240 of file pg_upgrade_support.c.

241 {
242  bool record_init_privs = PG_GETARG_BOOL(0);
243 
245  binary_upgrade_record_init_privs = record_init_privs;
246 
247  PG_RETURN_VOID();
248 }
bool binary_upgrade_record_init_privs
Definition: aclchk.c:105

References binary_upgrade_record_init_privs, CHECK_IS_BINARY_UPGRADE, PG_GETARG_BOOL, and PG_RETURN_VOID.