PostgreSQL Source Code git master
Macros | Functions
pg_upgrade_support.c File Reference
#include "postgres.h"
#include "access/relation.h"
#include "access/table.h"
#include "catalog/binary_upgrade.h"
#include "catalog/heap.h"
#include "catalog/namespace.h"
#include "catalog/pg_subscription_rel.h"
#include "catalog/pg_type.h"
#include "commands/extension.h"
#include "miscadmin.h"
#include "replication/logical.h"
#include "replication/logicallauncher.h"
#include "replication/origin.h"
#include "replication/worker_internal.h"
#include "storage/lmgr.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/pg_lsn.h"
Include dependency graph for pg_upgrade_support.c:

Go to the source code of this file.

Macros

 

Functions

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
bool IsBinaryUpgrade
Definition: globals.c:121

Definition at line 34 of file pg_upgrade_support.c.

Function Documentation

binary_upgrade_add_sub_rel_state()

Datum binary_upgrade_add_sub_rel_state ( PG_FUNCTION_ARGS  )

Definition at line 325 of file pg_upgrade_support.c.

326{
327 Relation subrel;
328 Relation rel;
329 Oid subid;
330 char *subname;
331 Oid relid;
332 char relstate;
333 XLogRecPtr sublsn;
334
336
337 /* We must check these things before dereferencing the arguments */
338 if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
339 elog(ERROR, "null argument to binary_upgrade_add_sub_rel_state is not allowed");
340
342 relid = PG_GETARG_OID(1);
343 relstate = PG_GETARG_CHAR(2);
345
346 subrel = table_open(SubscriptionRelationId, RowExclusiveLock);
347 subid = get_subscription_oid(subname, false);
348 rel = relation_open(relid, AccessShareLock);
349
350 /*
351 * Since there are no concurrent ALTER/DROP SUBSCRIPTION commands during
352 * the upgrade process, and the apply worker (which builds cache based on
353 * the subscription catalog) is not running, the locks can be released
354 * immediately.
355 */
356 AddSubscriptionRelState(subid, relid, relstate, sublsn, false);
359
361}
#define elog(elevel,...)
Definition: elog.h:226
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#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:3842
#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
Definition: postgres_ext.h:32
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
Definition: rel.h:56
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, 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_create_conflict_detection_slot()

Datum binary_upgrade_create_conflict_detection_slot ( PG_FUNCTION_ARGS  )

Definition at line 422 of file pg_upgrade_support.c.

423{
425
427
429
431}
void CreateConflictDetectionSlot(void)
Definition: launcher.c:1512
void ReplicationSlotRelease(void)
Definition: slot.c:731

References CHECK_IS_BINARY_UPGRADE, CreateConflictDetectionSlot(), PG_RETURN_VOID, and ReplicationSlotRelease().

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;
188 text *schemaName;
189 bool relocatable;
190 text *extVersion;
191 Datum extConfig;
192 Datum extCondition;
193 List *requiredExtensions;
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
204 extName = PG_GETARG_TEXT_PP(0);
205 schemaName = PG_GETARG_TEXT_PP(1);
206 relocatable = PG_GETARG_BOOL(2);
207 extVersion = PG_GETARG_TEXT_PP(3);
208
209 if (PG_ARGISNULL(4))
210 extConfig = PointerGetDatum(NULL);
211 else
212 extConfig = PG_GETARG_DATUM(4);
213
214 if (PG_ARGISNULL(5))
215 extCondition = PointerGetDatum(NULL);
216 else
217 extCondition = PG_GETARG_DATUM(5);
218
219 requiredExtensions = NIL;
220 if (!PG_ARGISNULL(6))
221 {
222 ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6);
223 Datum *textDatums;
224 int ndatums;
225 int i;
226
227 deconstruct_array_builtin(textArray, TEXTOID, &textDatums, NULL, &ndatums);
228 for (i = 0; i < ndatums; i++)
229 {
230 char *extName = TextDatumGetCString(textDatums[i]);
231 Oid extOid = get_extension_oid(extName, false);
232
233 requiredExtensions = lappend_oid(requiredExtensions, extOid);
234 }
235 }
236
238 GetUserId(),
239 get_namespace_oid(text_to_cstring(schemaName), false),
240 relocatable,
241 text_to_cstring(extVersion),
242 extConfig,
243 extCondition,
244 requiredExtensions);
245
247}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:263
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3697
#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:2063
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:167
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
i
int i
Definition: isn.c:77
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
Oid GetUserId(void)
Definition: miscinit.c:469
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:332
uint64_t Datum
Definition: postgres.h:70
Definition: array.h:93
Definition: pg_list.h:54
Definition: c.h:692

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_logical_slot_has_caught_up()

Datum binary_upgrade_logical_slot_has_caught_up ( PG_FUNCTION_ARGS  )

Definition at line 285 of file pg_upgrade_support.c.

286{
287 Name slot_name;
288 XLogRecPtr end_of_wal;
289 bool found_pending_wal;
290
292
293 /*
294 * Binary upgrades only allowed super-user connections so we must have
295 * permission to use replication slots.
296 */
298
299 slot_name = PG_GETARG_NAME(0);
300
301 /* Acquire the given slot */
302 ReplicationSlotAcquire(NameStr(*slot_name), true, true);
303
305
306 /* Slots must be valid as otherwise we won't be able to scan the WAL */
308
309 end_of_wal = GetFlushRecPtr(NULL);
310 found_pending_wal = LogicalReplicationSlotHasPendingWal(end_of_wal);
311
312 /* Clean up */
314
315 PG_RETURN_BOOL(!found_pending_wal);
316}
#define NameStr(name)
Definition: c.h:751
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
Assert(PointerIsAligned(start, uint64))
bool LogicalReplicationSlotHasPendingWal(XLogRecPtr end_of_wal)
Definition: logical.c:1999
bool has_rolreplication(Oid roleid)
Definition: miscinit.c:688
void ReplicationSlotAcquire(const char *name, bool nowait, bool error_if_invalid)
Definition: slot.c:593
ReplicationSlot * MyReplicationSlot
Definition: slot.c:148
@ RS_INVAL_NONE
Definition: slot.h:60
#define SlotIsLogical(slot)
Definition: slot.h:255
ReplicationSlotInvalidationCause invalidated
Definition: slot.h:110
ReplicationSlotPersistentData data
Definition: slot.h:192
Definition: c.h:746
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition: xlog.c:6551

References Assert(), CHECK_IS_BINARY_UPGRADE, ReplicationSlot::data, GetFlushRecPtr(), GetUserId(), has_rolreplication(), ReplicationSlotPersistentData::invalidated, LogicalReplicationSlotHasPendingWal(), MyReplicationSlot, NameStr, PG_GETARG_NAME, PG_RETURN_BOOL, ReplicationSlotAcquire(), ReplicationSlotRelease(), RS_INVAL_NONE, and SlotIsLogical.

binary_upgrade_replorigin_advance()

Datum binary_upgrade_replorigin_advance ( PG_FUNCTION_ARGS  )

Definition at line 369 of file pg_upgrade_support.c.

370{
371 Relation rel;
372 Oid subid;
373 char *subname;
374 char originname[NAMEDATALEN];
375 RepOriginId node;
376 XLogRecPtr remote_commit;
377
379
380 /*
381 * We must ensure a non-NULL subscription name before dereferencing the
382 * arguments.
383 */
384 if (PG_ARGISNULL(0))
385 elog(ERROR, "null argument to binary_upgrade_replorigin_advance is not allowed");
386
388 remote_commit = PG_ARGISNULL(1) ? InvalidXLogRecPtr : PG_GETARG_LSN(1);
389
390 rel = table_open(SubscriptionRelationId, RowExclusiveLock);
391 subid = get_subscription_oid(subname, false);
392
393 ReplicationOriginNameForLogicalRep(subid, InvalidOid, originname, sizeof(originname));
394
395 /* Lock to prevent the replication origin from vanishing */
396 LockRelationOid(ReplicationOriginRelationId, RowExclusiveLock);
397 node = replorigin_by_name(originname, false);
398
399 /*
400 * The server will be stopped after setting up the objects in the new
401 * cluster and the origins will be flushed during the shutdown checkpoint.
402 * This will ensure that the latest LSN values for origin will be
403 * available after the upgrade.
404 */
405 replorigin_advance(node, remote_commit, InvalidXLogRecPtr,
406 false /* backward */ ,
407 false /* WAL log */ );
408
409 UnlockRelationOid(ReplicationOriginRelationId, RowExclusiveLock);
411
413}
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
RepOriginId replorigin_by_name(const char *roname, bool missing_ok)
Definition: origin.c:226
void replorigin_advance(RepOriginId node, XLogRecPtr remote_commit, XLogRecPtr local_commit, bool go_backward, bool wal_log)
Definition: origin.c:911
#define NAMEDATALEN
#define InvalidOid
Definition: postgres_ext.h:37
uint16 RepOriginId
Definition: xlogdefs.h:68

References CHECK_IS_BINARY_UPGRADE, elog, ERROR, 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{
263 Oid table_id = PG_GETARG_OID(0);
266 char *cattname = text_to_cstring(attname);
267 char *cvalue = text_to_cstring(value);
268
270 SetAttrMissing(table_id, cattname, cvalue);
271
273}
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
void SetAttrMissing(Oid relid, char *attname, char *value)
Definition: heap.c:2086
static struct @169 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 65 of file pg_upgrade_support.c.

66{
67 Oid typoid = PG_GETARG_OID(0);
68
71
73}
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 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  )

Definition at line 87 of file pg_upgrade_support.c.

88{
89 Oid typoid = PG_GETARG_OID(0);
90
93
95}
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 76 of file pg_upgrade_support.c.

77{
78 Oid typoid = PG_GETARG_OID(0);
79
82
84}
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 175 of file pg_upgrade_support.c.

176{
177 Oid authoid = PG_GETARG_OID(0);
178
182}
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 164 of file pg_upgrade_support.c.

165{
166 Oid enumoid = PG_GETARG_OID(0);
167
170
172}
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 43 of file pg_upgrade_support.c.

44{
45 Oid tbspoid = PG_GETARG_OID(0);
46
49
51}
Oid binary_upgrade_next_pg_tablespace_oid
Definition: tablespace.c:87

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 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  )

Definition at line 250 of file pg_upgrade_support.c.

251{
252 bool record_init_privs = PG_GETARG_BOOL(0);
253
255 binary_upgrade_record_init_privs = record_init_privs;
256
258}
bool binary_upgrade_record_init_privs
Definition: aclchk.c:109

References binary_upgrade_record_init_privs, CHECK_IS_BINARY_UPGRADE, PG_GETARG_BOOL, and PG_RETURN_VOID.

AltStyle によって変換されたページ (->オリジナル) /