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/index.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_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_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)
 
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

Function Documentation

◆ binary_upgrade_create_empty_extension()

Datum binary_upgrade_create_empty_extension ( PG_FUNCTION_ARGS  )

Definition at line 132 of file pg_upgrade_support.c.

References CHECK_IS_BINARY_UPGRADE, deconstruct_array(), 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.

133 {
134  text *extName;
135  text *schemaName;
136  bool relocatable;
137  text *extVersion;
138  Datum extConfig;
139  Datum extCondition;
140  List *requiredExtensions;
141 
143 
144  /* We must check these things before dereferencing the arguments */
145  if (PG_ARGISNULL(0) ||
146  PG_ARGISNULL(1) ||
147  PG_ARGISNULL(2) ||
148  PG_ARGISNULL(3))
149  elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
150 
151  extName = PG_GETARG_TEXT_PP(0);
152  schemaName = PG_GETARG_TEXT_PP(1);
153  relocatable = PG_GETARG_BOOL(2);
154  extVersion = PG_GETARG_TEXT_PP(3);
155 
156  if (PG_ARGISNULL(4))
157  extConfig = PointerGetDatum(NULL);
158  else
159  extConfig = PG_GETARG_DATUM(4);
160 
161  if (PG_ARGISNULL(5))
162  extCondition = PointerGetDatum(NULL);
163  else
164  extCondition = PG_GETARG_DATUM(5);
165 
166  requiredExtensions = NIL;
167  if (!PG_ARGISNULL(6))
168  {
169  ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
170  Datum *textDatums;
171  int ndatums;
172  int i;
173 
174  deconstruct_array(textArray,
175  TEXTOID, -1, false, TYPALIGN_INT,
176  &textDatums, NULL, &ndatums);
177  for (i = 0; i < ndatums; i++)
178  {
179  char *extName = TextDatumGetCString(textDatums[i]);
180  Oid extOid = get_extension_oid(extName, false);
181 
182  requiredExtensions = lappend_oid(requiredExtensions, extOid);
183  }
184  }
185 
187  GetUserId(),
188  get_namespace_oid(text_to_cstring(schemaName), false),
189  relocatable,
190  text_to_cstring(extVersion),
191  extConfig,
192  extCondition,
193  requiredExtensions);
194 
195  PG_RETURN_VOID();
196 }
#define NIL
Definition: pg_list.h:65
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3042
Oid GetUserId(void)
Definition: miscinit.c:478
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:256
#define ERROR
Definition: elog.h:45
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition: extension.c:1787
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3488
char * text_to_cstring(const text *t)
Definition: varlena.c:222
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
#define elog(elevel,...)
Definition: elog.h:227
int i
Definition: c.h:621
Definition: pg_list.h:50
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_missing_value()

Datum binary_upgrade_set_missing_value ( PG_FUNCTION_ARGS  )

Definition at line 210 of file pg_upgrade_support.c.

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

211 {
212  Oid table_id = PG_GETARG_OID(0);
215  char *cattname = text_to_cstring(attname);
216  char *cvalue = text_to_cstring(value);
217 
219  SetAttrMissing(table_id, cattname, cvalue);
220 
221  PG_RETURN_VOID();
222 }
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition: heap.c:2140
unsigned int Oid
Definition: postgres_ext.h:31
static struct @141 value
NameData attname
Definition: pg_attribute.h:41
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
char * text_to_cstring(const text *t)
Definition: varlena.c:222
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
Definition: c.h:621
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_array_pg_type_oid()

Datum binary_upgrade_set_next_array_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 45 of file pg_upgrade_support.c.

References binary_upgrade_next_array_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

46 {
47  Oid typoid = PG_GETARG_OID(0);
48 
51 
53 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
Oid binary_upgrade_next_array_pg_type_oid
Definition: typecmds.c:109
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_heap_pg_class_oid()

Datum binary_upgrade_set_next_heap_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 78 of file pg_upgrade_support.c.

References binary_upgrade_next_heap_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

79 {
80  Oid reloid = PG_GETARG_OID(0);
81 
84 
86 }
Oid binary_upgrade_next_heap_pg_class_oid
Definition: heap.c:92
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_index_pg_class_oid()

Datum binary_upgrade_set_next_index_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 89 of file pg_upgrade_support.c.

References binary_upgrade_next_index_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

90 {
91  Oid reloid = PG_GETARG_OID(0);
92 
95 
97 }
Oid binary_upgrade_next_index_pg_class_oid
Definition: index.c:89
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ 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 67 of file pg_upgrade_support.c.

References binary_upgrade_next_mrng_array_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

68 {
69  Oid typoid = PG_GETARG_OID(0);
70 
73 
75 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
Oid binary_upgrade_next_mrng_array_pg_type_oid
Definition: typecmds.c:111
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_multirange_pg_type_oid()

Datum binary_upgrade_set_next_multirange_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 56 of file pg_upgrade_support.c.

References binary_upgrade_next_mrng_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

57 {
58  Oid typoid = PG_GETARG_OID(0);
59 
62 
64 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
Oid binary_upgrade_next_mrng_pg_type_oid
Definition: typecmds.c:110
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_pg_authid_oid()

Datum binary_upgrade_set_next_pg_authid_oid ( PG_FUNCTION_ARGS  )

Definition at line 122 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_authid_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

123 {
124  Oid authoid = PG_GETARG_OID(0);
125 
128  PG_RETURN_VOID();
129 }
Oid binary_upgrade_next_pg_authid_oid
Definition: user.c:42
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_pg_enum_oid()

Datum binary_upgrade_set_next_pg_enum_oid ( PG_FUNCTION_ARGS  )

Definition at line 111 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_enum_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

112 {
113  Oid enumoid = PG_GETARG_OID(0);
114 
117 
118  PG_RETURN_VOID();
119 }
unsigned int Oid
Definition: postgres_ext.h:31
Oid binary_upgrade_next_pg_enum_oid
Definition: pg_enum.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_pg_type_oid()

Datum binary_upgrade_set_next_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 34 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

35 {
36  Oid typoid = PG_GETARG_OID(0);
37 
40 
42 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
Oid binary_upgrade_next_pg_type_oid
Definition: pg_type.c:45
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_toast_pg_class_oid()

Datum binary_upgrade_set_next_toast_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 100 of file pg_upgrade_support.c.

References binary_upgrade_next_toast_pg_class_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

101 {
102  Oid reloid = PG_GETARG_OID(0);
103 
106 
107  PG_RETURN_VOID();
108 }
Oid binary_upgrade_next_toast_pg_class_oid
Definition: heap.c:93
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_record_init_privs()

Datum binary_upgrade_set_record_init_privs ( PG_FUNCTION_ARGS  )

Definition at line 199 of file pg_upgrade_support.c.

References binary_upgrade_record_init_privs, CHECK_IS_BINARY_UPGRADE, PG_GETARG_BOOL, and PG_RETURN_VOID.

200 {
201  bool record_init_privs = PG_GETARG_BOOL(0);
202 
204  binary_upgrade_record_init_privs = record_init_privs;
205 
206  PG_RETURN_VOID();
207 }
bool binary_upgrade_record_init_privs
Definition: aclchk.c:101
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define CHECK_IS_BINARY_UPGRADE