PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_upgrade_support.c File Reference
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)
 
Datum binary_upgrade_check_logical_slot_pending_wal (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_add_sub_rel_state (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_replorigin_advance (PG_FUNCTION_ARGS)
 
Datum binary_upgrade_create_conflict_detection_slot (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ CHECK_IS_BINARY_UPGRADE

#define CHECK_IS_BINARY_UPGRADE
Value:
do { \
errmsg("function can only be called when server is in binary upgrade mode"))); \
} while (0)
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
bool IsBinaryUpgrade
Definition globals.c:121
static int fb(int x)

Definition at line 34 of file pg_upgrade_support.c.

35 { \
39 errmsg("function can only be called when server is in binary upgrade mode"))); \
40} while (0)

Function Documentation

◆ binary_upgrade_add_sub_rel_state()

Datum binary_upgrade_add_sub_rel_state ( PG_FUNCTION_ARGS  )

Definition at line 331 of file pg_upgrade_support.c.

332{
334 Relation rel;
335 Oid subid;
336 char *subname;
337 Oid relid;
338 char relstate;
340
342
343 /* We must check these things before dereferencing the arguments */
344 if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
345 elog(ERROR, "null argument to binary_upgrade_add_sub_rel_state is not allowed");
346
348 relid = PG_GETARG_OID(1);
349 relstate = PG_GETARG_CHAR(2);
351
353 subid = get_subscription_oid(subname, false);
354 rel = relation_open(relid, AccessShareLock);
355
356 /*
357 * Since there are no concurrent ALTER/DROP SUBSCRIPTION commands during
358 * the upgrade process, and the apply worker (which builds cache based on
359 * the subscription catalog) is not running, the locks can be released
360 * immediately.
361 */
362 AddSubscriptionRelState(subid, relid, relstate, sublsn, false);
365
367}
#define elog(elevel,...)
Definition elog.h:226
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_GETARG_CHAR(n)
Definition fmgr.h:273
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define AccessShareLock
Definition lockdefs.h:36
#define RowExclusiveLock
Definition lockdefs.h:38
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition lsyscache.c:3825
#define PG_GETARG_LSN(n)
Definition pg_lsn.h:36
void AddSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn, bool retain_lock)
NameData subname
#define CHECK_IS_BINARY_UPGRADE
unsigned int Oid
void relation_close(Relation relation, LOCKMODE lockmode)
Definition relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition relation.c:47
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
char * text_to_cstring(const text *t)
Definition varlena.c:214
uint64 XLogRecPtr
Definition xlogdefs.h:21
#define InvalidXLogRecPtr
Definition xlogdefs.h:28

References AccessShareLock, AddSubscriptionRelState(), CHECK_IS_BINARY_UPGRADE, elog, ERROR, fb(), get_subscription_oid(), InvalidXLogRecPtr, PG_ARGISNULL, PG_GETARG_CHAR, PG_GETARG_LSN, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_VOID, relation_close(), relation_open(), RowExclusiveLock, subname, table_close(), table_open(), and text_to_cstring().

◆ binary_upgrade_check_logical_slot_pending_wal()

Datum binary_upgrade_check_logical_slot_pending_wal ( PG_FUNCTION_ARGS  )

Definition at line 285 of file pg_upgrade_support.c.

286{
287 Name slot_name;
288 XLogRecPtr end_of_wal;
291
293
294 /*
295 * Binary upgrades only allowed super-user connections so we must have
296 * permission to use replication slots.
297 */
299
300 slot_name = PG_GETARG_NAME(0);
302
303 /* Acquire the given slot */
304 ReplicationSlotAcquire(NameStr(*slot_name), true, true);
305
307
308 /* Slots must be valid as otherwise we won't be able to scan the WAL */
310
311 end_of_wal = GetFlushRecPtr(NULL);
314
315 /* Clean up */
317
320 else
322}
#define NameStr(name)
Definition c.h:765
#define Assert(condition)
Definition c.h:873
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
XLogRecPtr LogicalReplicationSlotCheckPendingWal(XLogRecPtr end_of_wal, XLogRecPtr scan_cutoff_lsn)
Definition logical.c:1998
Oid GetUserId(void)
Definition miscinit.c:469
bool has_rolreplication(Oid roleid)
Definition miscinit.c:688
#define PG_RETURN_LSN(x)
Definition pg_lsn.h:37
void ReplicationSlotAcquire(const char *name, bool nowait, bool error_if_invalid)
Definition slot.c:620
ReplicationSlot * MyReplicationSlot
Definition slot.c:148
void ReplicationSlotRelease(void)
Definition slot.c:758
@ RS_INVAL_NONE
Definition slot.h:60
#define SlotIsLogical(slot)
Definition slot.h:285
ReplicationSlotInvalidationCause invalidated
Definition slot.h:128
ReplicationSlotPersistentData data
Definition slot.h:210
Definition c.h:760
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition xlog.c:6625
#define XLogRecPtrIsValid(r)
Definition xlogdefs.h:29

References Assert, CHECK_IS_BINARY_UPGRADE, ReplicationSlot::data, fb(), GetFlushRecPtr(), GetUserId(), has_rolreplication(), ReplicationSlotPersistentData::invalidated, LogicalReplicationSlotCheckPendingWal(), MyReplicationSlot, NameStr, PG_GETARG_LSN, PG_GETARG_NAME, PG_RETURN_LSN, PG_RETURN_NULL, ReplicationSlotAcquire(), ReplicationSlotRelease(), RS_INVAL_NONE, SlotIsLogical, and XLogRecPtrIsValid.

◆ binary_upgrade_create_conflict_detection_slot()

Datum binary_upgrade_create_conflict_detection_slot ( PG_FUNCTION_ARGS  )

◆ binary_upgrade_create_empty_extension()

Datum binary_upgrade_create_empty_extension ( PG_FUNCTION_ARGS  )

Definition at line 185 of file pg_upgrade_support.c.

186{
187 text *extName;
189 bool relocatable;
194
196
197 /* We must check these things before dereferencing the arguments */
198 if (PG_ARGISNULL(0) ||
199 PG_ARGISNULL(1) ||
200 PG_ARGISNULL(2) ||
201 PG_ARGISNULL(3))
202 elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
203
206 relocatable = PG_GETARG_BOOL(2);
208
209 if (PG_ARGISNULL(4))
211 else
213
214 if (PG_ARGISNULL(5))
216 else
218
220 if (!PG_ARGISNULL(6))
221 {
224 int ndatums;
225 int i;
226
228 for (i = 0; i < ndatums; i++)
229 {
232
234 }
235 }
236
238 GetUserId(),
240 relocatable,
242 extConfig,
245
247}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
#define TextDatumGetCString(d)
Definition builtins.h:98
ObjectAddress InsertExtensionTuple(const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
Definition extension.c:2111
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition extension.c:206
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
int i
Definition isn.c:77
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3605
#define NIL
Definition pg_list.h:68
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
uint64_t Datum
Definition postgres.h:70
Definition pg_list.h:54
Definition c.h:706

References CHECK_IS_BINARY_UPGRADE, deconstruct_array_builtin(), elog, ERROR, fb(), 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_replorigin_advance()

Datum binary_upgrade_replorigin_advance ( PG_FUNCTION_ARGS  )

Definition at line 375 of file pg_upgrade_support.c.

376{
377 Relation rel;
378 Oid subid;
379 char *subname;
381 ReplOriginId node;
383
385
386 /*
387 * We must ensure a non-NULL subscription name before dereferencing the
388 * arguments.
389 */
390 if (PG_ARGISNULL(0))
391 elog(ERROR, "null argument to binary_upgrade_replorigin_advance is not allowed");
392
395
397 subid = get_subscription_oid(subname, false);
398
400
401 /* Lock to prevent the replication origin from vanishing */
403 node = replorigin_by_name(originname, false);
404
405 /*
406 * The server will be stopped after setting up the objects in the new
407 * cluster and the origins will be flushed during the shutdown checkpoint.
408 * This will ensure that the latest LSN values for origin will be
409 * available after the upgrade.
410 */
412 false /* backward */ ,
413 false /* WAL log */ );
414
417
419}
void ReplicationOriginNameForLogicalRep(Oid suboid, Oid relid, char *originname, Size szoriginname)
Definition worker.c:641
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition lmgr.c:229
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition lmgr.c:107
ReplOriginId replorigin_by_name(const char *roname, bool missing_ok)
Definition origin.c:231
void replorigin_advance(ReplOriginId node, XLogRecPtr remote_commit, XLogRecPtr local_commit, bool go_backward, bool wal_log)
Definition origin.c:918
#define NAMEDATALEN
#define InvalidOid
uint16 ReplOriginId
Definition xlogdefs.h:69

References CHECK_IS_BINARY_UPGRADE, elog, ERROR, fb(), get_subscription_oid(), InvalidOid, InvalidXLogRecPtr, LockRelationOid(), NAMEDATALEN, PG_ARGISNULL, PG_GETARG_LSN, PG_GETARG_TEXT_PP, PG_RETURN_VOID, ReplicationOriginNameForLogicalRep(), replorigin_advance(), replorigin_by_name(), RowExclusiveLock, subname, table_close(), table_open(), text_to_cstring(), and UnlockRelationOid().

◆ binary_upgrade_set_missing_value()

Datum binary_upgrade_set_missing_value ( PG_FUNCTION_ARGS  )

Definition at line 261 of file pg_upgrade_support.c.

262{
268
271
273}
#define PG_GETARG_TEXT_P(n)
Definition fmgr.h:337
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition heap.c:2086
static struct @172 value
NameData attname

References attname, CHECK_IS_BINARY_UPGRADE, fb(), 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  )

◆ binary_upgrade_set_next_heap_pg_class_oid()

Datum binary_upgrade_set_next_heap_pg_class_oid ( PG_FUNCTION_ARGS  )

Definition at line 98 of file pg_upgrade_support.c.

99{
100 Oid reloid = PG_GETARG_OID(0);
101
104
106}
Oid binary_upgrade_next_heap_pg_class_oid
Definition heap.c:81

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

110{
111 RelFileNumber relfilenumber = PG_GETARG_OID(0);
112
115
117}
RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber
Definition heap.c:83
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 120 of file pg_upgrade_support.c.

121{
122 Oid reloid = PG_GETARG_OID(0);
123
126
128}
Oid binary_upgrade_next_index_pg_class_oid
Definition index.c:85

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

132{
133 RelFileNumber relfilenumber = PG_GETARG_OID(0);
134
137
139}
RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber
Definition index.c:86

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  )

◆ binary_upgrade_set_next_multirange_pg_type_oid()

Datum binary_upgrade_set_next_multirange_pg_type_oid ( PG_FUNCTION_ARGS  )

◆ binary_upgrade_set_next_pg_authid_oid()

Datum binary_upgrade_set_next_pg_authid_oid ( PG_FUNCTION_ARGS  )

◆ binary_upgrade_set_next_pg_enum_oid()

Datum binary_upgrade_set_next_pg_enum_oid ( PG_FUNCTION_ARGS  )

◆ binary_upgrade_set_next_pg_tablespace_oid()

Datum binary_upgrade_set_next_pg_tablespace_oid ( PG_FUNCTION_ARGS  )

◆ binary_upgrade_set_next_pg_type_oid()

Datum binary_upgrade_set_next_pg_type_oid ( PG_FUNCTION_ARGS  )

Definition at line 54 of file pg_upgrade_support.c.

55{
56 Oid typoid = PG_GETARG_OID(0);
57
60
62}
Oid binary_upgrade_next_pg_type_oid
Definition pg_type.c:41

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

143{
144 Oid reloid = PG_GETARG_OID(0);
145
148
150}
Oid binary_upgrade_next_toast_pg_class_oid
Definition heap.c:82

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

154{
155 RelFileNumber relfilenumber = PG_GETARG_OID(0);
156
159
161}
RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber
Definition heap.c:84

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  )