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_type_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_array_pg_type_oid (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_set_next_toast_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

#define CHECK_IS_BINARY_UPGRADE

Function Documentation

◆ binary_upgrade_create_empty_extension()

Datum binary_upgrade_create_empty_extension ( PG_FUNCTION_ARGS  )

Definition at line 120 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.

121 {
122  text *extName;
123  text *schemaName;
124  bool relocatable;
125  text *extVersion;
126  Datum extConfig;
127  Datum extCondition;
128  List *requiredExtensions;
129 
131 
132  /* We must check these things before dereferencing the arguments */
133  if (PG_ARGISNULL(0) ||
134  PG_ARGISNULL(1) ||
135  PG_ARGISNULL(2) ||
136  PG_ARGISNULL(3))
137  elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
138 
139  extName = PG_GETARG_TEXT_PP(0);
140  schemaName = PG_GETARG_TEXT_PP(1);
141  relocatable = PG_GETARG_BOOL(2);
142  extVersion = PG_GETARG_TEXT_PP(3);
143 
144  if (PG_ARGISNULL(4))
145  extConfig = PointerGetDatum(NULL);
146  else
147  extConfig = PG_GETARG_DATUM(4);
148 
149  if (PG_ARGISNULL(5))
150  extCondition = PointerGetDatum(NULL);
151  else
152  extCondition = PG_GETARG_DATUM(5);
153 
154  requiredExtensions = NIL;
155  if (!PG_ARGISNULL(6))
156  {
157  ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
158  Datum *textDatums;
159  int ndatums;
160  int i;
161 
162  deconstruct_array(textArray,
163  TEXTOID, -1, false, 'i',
164  &textDatums, NULL, &ndatums);
165  for (i = 0; i < ndatums; i++)
166  {
167  char *extName = TextDatumGetCString(textDatums[i]);
168  Oid extOid = get_extension_oid(extName, false);
169 
170  requiredExtensions = lappend_oid(requiredExtensions, extOid);
171  }
172  }
173 
175  GetUserId(),
176  get_namespace_oid(text_to_cstring(schemaName), false),
177  relocatable,
178  text_to_cstring(extVersion),
179  extConfig,
180  extCondition,
181  requiredExtensions);
182 
183  PG_RETURN_VOID();
184 }
#define NIL
Definition: pg_list.h:65
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3035
Oid GetUserId(void)
Definition: miscinit.c:380
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
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:303
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define ERROR
Definition: elog.h:43
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#define PG_ARGISNULL(n)
Definition: fmgr.h:204
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition: extension.c:1767
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3461
char * text_to_cstring(const text *t)
Definition: varlena.c:204
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:138
#define elog(elevel,...)
Definition: elog.h:226
int i
Definition: c.h:549
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 198 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.

199 {
200  Oid table_id = PG_GETARG_OID(0);
203  char *cattname = text_to_cstring(attname);
204  char *cvalue = text_to_cstring(value);
205 
207  SetAttrMissing(table_id, cattname, cvalue);
208 
209  PG_RETURN_VOID();
210 }
static struct @144 value
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition: heap.c:2065
unsigned int Oid
Definition: postgres_ext.h:31
NameData attname
Definition: pg_attribute.h:40
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
char * text_to_cstring(const text *t)
Definition: varlena.c:204
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:330
Definition: c.h:549
#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 44 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.

45 {
46  Oid typoid = PG_GETARG_OID(0);
47 
50 
52 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
Oid binary_upgrade_next_array_pg_type_oid
Definition: typecmds.c:87
#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 66 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.

67 {
68  Oid reloid = PG_GETARG_OID(0);
69 
72 
74 }
Oid binary_upgrade_next_heap_pg_class_oid
Definition: heap.c:93
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#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 77 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.

78 {
79  Oid reloid = PG_GETARG_OID(0);
80 
83 
85 }
Oid binary_upgrade_next_index_pg_class_oid
Definition: index.c:85
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#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 110 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_authid_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

111 {
112  Oid authoid = PG_GETARG_OID(0);
113 
116  PG_RETURN_VOID();
117 }
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:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#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 99 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_enum_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

100 {
101  Oid enumoid = PG_GETARG_OID(0);
102 
105 
106  PG_RETURN_VOID();
107 }
unsigned int Oid
Definition: postgres_ext.h:31
Oid binary_upgrade_next_pg_enum_oid
Definition: pg_enum.c:37
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#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 33 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

34 {
35  Oid typoid = PG_GETARG_OID(0);
36 
39 
41 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
Oid binary_upgrade_next_pg_type_oid
Definition: pg_type.c:40
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#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 88 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.

89 {
90  Oid reloid = PG_GETARG_OID(0);
91 
94 
96 }
Oid binary_upgrade_next_toast_pg_class_oid
Definition: heap.c:94
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_next_toast_pg_type_oid()

Datum binary_upgrade_set_next_toast_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 55 of file pg_upgrade_support.c.

References binary_upgrade_next_toast_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

56 {
57  Oid typoid = PG_GETARG_OID(0);
58 
61 
63 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_VOID()
Definition: fmgr.h:339
Oid binary_upgrade_next_toast_pg_type_oid
Definition: toasting.c:38
#define CHECK_IS_BINARY_UPGRADE

◆ binary_upgrade_set_record_init_privs()

Datum binary_upgrade_set_record_init_privs ( PG_FUNCTION_ARGS  )

Definition at line 187 of file pg_upgrade_support.c.

References binary_upgrade_record_init_privs, CHECK_IS_BINARY_UPGRADE, PG_GETARG_BOOL, and PG_RETURN_VOID.

188 {
189  bool record_init_privs = PG_GETARG_BOOL(0);
190 
192  binary_upgrade_record_init_privs = record_init_privs;
193 
194  PG_RETURN_VOID();
195 }
bool binary_upgrade_record_init_privs
Definition: aclchk.c:102
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#define CHECK_IS_BINARY_UPGRADE