PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_upgrade_support.c File Reference
#include "postgres.h"
#include "catalog/binary_upgrade.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)
 

Macro Definition Documentation

#define CHECK_IS_BINARY_UPGRADE
Value:
do { \
(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:575
bool IsBinaryUpgrade
Definition: globals.c:102
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

Definition at line 23 of file pg_upgrade_support.c.

Referenced by binary_upgrade_create_empty_extension(), binary_upgrade_set_next_array_pg_type_oid(), binary_upgrade_set_next_heap_pg_class_oid(), binary_upgrade_set_next_index_pg_class_oid(), binary_upgrade_set_next_pg_authid_oid(), binary_upgrade_set_next_pg_enum_oid(), binary_upgrade_set_next_pg_type_oid(), binary_upgrade_set_next_toast_pg_class_oid(), binary_upgrade_set_next_toast_pg_type_oid(), and binary_upgrade_set_record_init_privs().

Function Documentation

Datum binary_upgrade_create_empty_extension ( PG_FUNCTION_ARGS  )

Definition at line 119 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, NULL, PG_ARGISNULL, PG_GETARG_ARRAYTYPE_P, PG_GETARG_BOOL, PG_GETARG_DATUM, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PointerGetDatum, text_to_cstring(), TextDatumGetCString, and TEXTOID.

120 {
121  text *extName;
122  text *schemaName;
123  bool relocatable;
124  text *extVersion;
125  Datum extConfig;
126  Datum extCondition;
127  List *requiredExtensions;
128 
130 
131  /* We must check these things before dereferencing the arguments */
132  if (PG_ARGISNULL(0) ||
133  PG_ARGISNULL(1) ||
134  PG_ARGISNULL(2) ||
135  PG_ARGISNULL(3))
136  elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
137 
138  extName = PG_GETARG_TEXT_PP(0);
139  schemaName = PG_GETARG_TEXT_PP(1);
140  relocatable = PG_GETARG_BOOL(2);
141  extVersion = PG_GETARG_TEXT_PP(3);
142 
143  if (PG_ARGISNULL(4))
144  extConfig = PointerGetDatum(NULL);
145  else
146  extConfig = PG_GETARG_DATUM(4);
147 
148  if (PG_ARGISNULL(5))
149  extCondition = PointerGetDatum(NULL);
150  else
151  extCondition = PG_GETARG_DATUM(5);
152 
153  requiredExtensions = NIL;
154  if (!PG_ARGISNULL(6))
155  {
156  ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
157  Datum *textDatums;
158  int ndatums;
159  int i;
160 
161  deconstruct_array(textArray,
162  TEXTOID, -1, false, 'i',
163  &textDatums, NULL, &ndatums);
164  for (i = 0; i < ndatums; i++)
165  {
166  char *extName = TextDatumGetCString(textDatums[i]);
167  Oid extOid = get_extension_oid(extName, false);
168 
169  requiredExtensions = lappend_oid(requiredExtensions, extOid);
170  }
171  }
172 
174  GetUserId(),
175  get_namespace_oid(text_to_cstring(schemaName), false),
176  relocatable,
177  text_to_cstring(extVersion),
178  extConfig,
179  extCondition,
180  requiredExtensions);
181 
182  PG_RETURN_VOID();
183 }
#define NIL
Definition: pg_list.h:69
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3005
Oid GetUserId(void)
Definition: miscinit.c:284
#define TEXTOID
Definition: pg_type.h:324
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:239
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define ERROR
Definition: elog.h:43
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define PG_ARGISNULL(n)
Definition: fmgr.h:174
#define NULL
Definition: c.h:229
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition: extension.c:1741
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3475
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:135
int i
Definition: c.h:439
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_array_pg_type_oid ( PG_FUNCTION_ARGS  )

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

44 {
45  Oid typoid = PG_GETARG_OID(0);
46 
49 
51 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Oid binary_upgrade_next_array_pg_type_oid
Definition: typecmds.c:86
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_heap_pg_class_oid ( PG_FUNCTION_ARGS  )

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

66 {
67  Oid reloid = PG_GETARG_OID(0);
68 
71 
73 }
Oid binary_upgrade_next_heap_pg_class_oid
Definition: heap.c:86
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_index_pg_class_oid ( PG_FUNCTION_ARGS  )

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

77 {
78  Oid reloid = PG_GETARG_OID(0);
79 
82 
84 }
Oid binary_upgrade_next_index_pg_class_oid
Definition: index.c:77
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_pg_authid_oid ( PG_FUNCTION_ARGS  )

Definition at line 109 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_authid_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

110 {
111  Oid authoid = PG_GETARG_OID(0);
112 
115  PG_RETURN_VOID();
116 }
Oid binary_upgrade_next_pg_authid_oid
Definition: user.c:43
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_pg_enum_oid ( PG_FUNCTION_ARGS  )

Definition at line 98 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_enum_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

99 {
100  Oid enumoid = PG_GETARG_OID(0);
101 
104 
105  PG_RETURN_VOID();
106 }
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:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 32 of file pg_upgrade_support.c.

References binary_upgrade_next_pg_type_oid, CHECK_IS_BINARY_UPGRADE, PG_GETARG_OID, and PG_RETURN_VOID.

33 {
34  Oid typoid = PG_GETARG_OID(0);
35 
38 
40 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Oid binary_upgrade_next_pg_type_oid
Definition: pg_type.c:40
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_toast_pg_class_oid ( PG_FUNCTION_ARGS  )

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

88 {
89  Oid reloid = PG_GETARG_OID(0);
90 
93 
95 }
Oid binary_upgrade_next_toast_pg_class_oid
Definition: heap.c:87
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_next_toast_pg_type_oid ( PG_FUNCTION_ARGS  )

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

55 {
56  Oid typoid = PG_GETARG_OID(0);
57 
60 
62 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Oid binary_upgrade_next_toast_pg_type_oid
Definition: toasting.c:37
#define CHECK_IS_BINARY_UPGRADE
Datum binary_upgrade_set_record_init_privs ( PG_FUNCTION_ARGS  )

Definition at line 186 of file pg_upgrade_support.c.

References binary_upgrade_record_init_privs, CHECK_IS_BINARY_UPGRADE, PG_GETARG_BOOL, and PG_RETURN_VOID.

187 {
188  bool record_init_privs = PG_GETARG_BOOL(0);
189 
191  binary_upgrade_record_init_privs = record_init_privs;
192 
193  PG_RETURN_VOID();
194 }
bool binary_upgrade_record_init_privs
Definition: aclchk.c:102
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:239
#define PG_RETURN_VOID()
Definition: fmgr.h:309
#define CHECK_IS_BINARY_UPGRADE