PostgreSQL Source Code git master
Loading...
Searching...
No Matches
slotfuncs.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * slotfuncs.c
4 * Support functions for replication slots
5 *
6 * Copyright (c) 2012-2026, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/backend/replication/slotfuncs.c
10 *
11 *-------------------------------------------------------------------------
12 */
13#include "postgres.h"
14
15#include "access/htup_details.h"
17#include "access/xlogrecovery.h"
18#include "access/xlogutils.h"
19#include "funcapi.h"
20#include "replication/logical.h"
21#include "replication/slot.h"
23#include "storage/proc.h"
24#include "utils/builtins.h"
25#include "utils/guc.h"
26#include "utils/pg_lsn.h"
27
28/*
29 * Map SlotSyncSkipReason enum values to human-readable names.
30 */
31static const char *SlotSyncSkipReasonNames[] = {
32 [SS_SKIP_NONE] = "none",
33 [SS_SKIP_WAL_NOT_FLUSHED] = "wal_not_flushed",
34 [SS_SKIP_WAL_OR_ROWS_REMOVED] = "wal_or_rows_removed",
35 [SS_SKIP_NO_CONSISTENT_SNAPSHOT] = "no_consistent_snapshot",
36 [SS_SKIP_INVALID] = "slot_invalidated"
37};
38
39/*
40 * Helper function for creating a new physical replication slot with
41 * given arguments. Note that this function doesn't release the created
42 * slot.
43 *
44 * If restart_lsn is a valid value, we use it without WAL reservation
45 * routine. So the caller must guarantee that WAL is available.
46 */
47static void
49 bool temporary, XLogRecPtr restart_lsn)
50{
52
53 /* acquire replication slot, this will check for conflicting names */
55 temporary ? RS_TEMPORARY : RS_PERSISTENT, false,
56 false, false);
57
59 {
60 /* Reserve WAL as the user asked for it */
61 if (!XLogRecPtrIsValid(restart_lsn))
63 else
64 MyReplicationSlot->data.restart_lsn = restart_lsn;
65
66 /* Write this slot to disk */
69 }
70}
71
72/*
73 * SQL function for creating a new physical (streaming replication)
74 * replication slot.
75 */
78{
81 bool temporary = PG_GETARG_BOOL(2);
82 Datum values[2];
83 bool nulls[2];
84 TupleDesc tupdesc;
85 HeapTuple tuple;
86 Datum result;
87
88 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
89 elog(ERROR, "return type must be a row type");
90
92
94
97 temporary,
99
101 nulls[0] = false;
102
104 {
106 nulls[1] = false;
107 }
108 else
109 nulls[1] = true;
110
111 tuple = heap_form_tuple(tupdesc, values, nulls);
112 result = HeapTupleGetDatum(tuple);
113
115
116 PG_RETURN_DATUM(result);
117}
118
119
120/*
121 * Helper function for creating a new logical replication slot with
122 * given arguments. Note that this function doesn't release the created
123 * slot.
124 *
125 * When find_startpoint is false, the slot's confirmed_flush is not set; it's
126 * caller's responsibility to ensure it's set to something sensible.
127 */
128static void
130 bool temporary, bool two_phase,
131 bool failover,
132 XLogRecPtr restart_lsn,
133 bool find_startpoint)
134{
136
138
139 /*
140 * Acquire a logical decoding slot, this will check for conflicting names.
141 * Initially create persistent slot as ephemeral - that allows us to
142 * nicely handle errors during initialization because it'll get dropped if
143 * this transaction fails. We'll make it persistent at the end. Temporary
144 * slots can be created as temporary from beginning as they get dropped on
145 * error as well.
146 */
148 temporary ? RS_TEMPORARY : RS_EPHEMERAL, two_phase,
149 failover, false);
150
151 /*
152 * Ensure the logical decoding is enabled before initializing the logical
153 * decoding context.
154 */
157
158 /*
159 * Create logical decoding context to find start point or, if we don't
160 * need it, to 1) bump slot's restart_lsn and xmin 2) check plugin sanity.
161 *
162 * Note: when !find_startpoint this is still important, because it's at
163 * this point that the output plugin is validated.
164 */
166 false, /* just catalogs is OK */
167 restart_lsn,
168 XL_ROUTINE(.page_read = read_local_xlog_page,
169 .segment_open = wal_segment_open,
170 .segment_close = wal_segment_close),
171 NULL, NULL, NULL);
172
173 /*
174 * If caller needs us to determine the decoding start point, do so now.
175 * This might take a while.
176 */
177 if (find_startpoint)
179
180 /* don't need the decoding context anymore */
182}
183
184/*
185 * SQL function for creating a new logical replication slot.
186 */
187Datum
189{
192 bool temporary = PG_GETARG_BOOL(2);
193 bool two_phase = PG_GETARG_BOOL(3);
194 bool failover = PG_GETARG_BOOL(4);
195 Datum result;
196 TupleDesc tupdesc;
197 HeapTuple tuple;
198 Datum values[2];
199 bool nulls[2];
200
201 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
202 elog(ERROR, "return type must be a row type");
203
205
207
209 NameStr(*plugin),
210 temporary,
211 two_phase,
212 failover,
214 true);
215
218
219 memset(nulls, 0, sizeof(nulls));
220
221 tuple = heap_form_tuple(tupdesc, values, nulls);
222 result = HeapTupleGetDatum(tuple);
223
224 /* ok, slot is now fully created, mark it as persistent if needed */
225 if (!temporary)
228
229 PG_RETURN_DATUM(result);
230}
231
232
233/*
234 * SQL function for dropping a replication slot.
235 */
236Datum
249
250/*
251 * pg_get_replication_slots - SQL SRF showing all replication slots
252 * that currently exist on the database cluster.
253 */
254Datum
256{
257#define PG_GET_REPLICATION_SLOTS_COLS 21
258 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
260 int slotno;
261
262 /*
263 * We don't require any special permission to see this function's data
264 * because nothing should be sensitive. The most critical being the slot
265 * name, which shouldn't contain anything particularly sensitive.
266 */
267
268 InitMaterializedSRF(fcinfo, 0);
269
271
274 {
280 int i;
282
283 if (!slot->in_use)
284 continue;
285
286 /* Copy slot contents while holding spinlock, then examine at leisure */
287 SpinLockAcquire(&slot->mutex);
288 slot_contents = *slot;
289 SpinLockRelease(&slot->mutex);
290
291 memset(values, 0, sizeof(values));
292 memset(nulls, 0, sizeof(nulls));
293
294 i = 0;
295 values[i++] = NameGetDatum(&slot_contents.data.name);
296
297 if (slot_contents.data.database == InvalidOid)
298 nulls[i++] = true;
299 else
300 values[i++] = NameGetDatum(&slot_contents.data.plugin);
301
302 if (slot_contents.data.database == InvalidOid)
303 values[i++] = CStringGetTextDatum("physical");
304 else
305 values[i++] = CStringGetTextDatum("logical");
306
307 if (slot_contents.data.database == InvalidOid)
308 nulls[i++] = true;
309 else
310 values[i++] = ObjectIdGetDatum(slot_contents.data.database);
311
312 values[i++] = BoolGetDatum(slot_contents.data.persistency == RS_TEMPORARY);
314
315 if (slot_contents.active_proc != INVALID_PROC_NUMBER)
316 values[i++] = Int32GetDatum(GetPGProcByNumber(slot_contents.active_proc)->pid);
317 else
318 nulls[i++] = true;
319
320 if (slot_contents.data.xmin != InvalidTransactionId)
322 else
323 nulls[i++] = true;
324
325 if (slot_contents.data.catalog_xmin != InvalidTransactionId)
326 values[i++] = TransactionIdGetDatum(slot_contents.data.catalog_xmin);
327 else
328 nulls[i++] = true;
329
330 if (XLogRecPtrIsValid(slot_contents.data.restart_lsn))
331 values[i++] = LSNGetDatum(slot_contents.data.restart_lsn);
332 else
333 nulls[i++] = true;
334
335 if (XLogRecPtrIsValid(slot_contents.data.confirmed_flush))
336 values[i++] = LSNGetDatum(slot_contents.data.confirmed_flush);
337 else
338 nulls[i++] = true;
339
340 /*
341 * If the slot has not been invalidated, test availability from
342 * restart_lsn.
343 */
344 if (slot_contents.data.invalidated != RS_INVAL_NONE)
346 else
347 walstate = GetWALAvailability(slot_contents.data.restart_lsn);
348
349 switch (walstate)
350 {
352 nulls[i++] = true;
353 break;
354
356 values[i++] = CStringGetTextDatum("reserved");
357 break;
358
360 values[i++] = CStringGetTextDatum("extended");
361 break;
362
364 values[i++] = CStringGetTextDatum("unreserved");
365 break;
366
367 case WALAVAIL_REMOVED:
368
369 /*
370 * If we read the restart_lsn long enough ago, maybe that file
371 * has been removed by now. However, the walsender could have
372 * moved forward enough that it jumped to another file after
373 * we looked. If checkpointer signalled the process to
374 * termination, then it's definitely lost; but if a process is
375 * still alive, then "unreserved" seems more appropriate.
376 *
377 * If we do change it, save the state for safe_wal_size below.
378 */
379 if (XLogRecPtrIsValid(slot_contents.data.restart_lsn))
380 {
381 ProcNumber procno;
382
383 SpinLockAcquire(&slot->mutex);
384 procno = slot->active_proc;
385 slot_contents.data.restart_lsn = slot->data.restart_lsn;
386 SpinLockRelease(&slot->mutex);
387 if (procno != INVALID_PROC_NUMBER)
388 {
389 values[i++] = CStringGetTextDatum("unreserved");
391 break;
392 }
393 }
394 values[i++] = CStringGetTextDatum("lost");
395 break;
396 }
397
398 /*
399 * safe_wal_size is only computed for slots that have not been lost,
400 * and only if there's a configured maximum size.
401 */
403 nulls[i++] = true;
404 else
405 {
411
413
414 /* determine how many segments can be kept by slots */
416 /* ditto for wal_keep_size */
418
419 /* if currpos reaches failLSN, we lose our segment */
422
424 }
425
426 values[i++] = BoolGetDatum(slot_contents.data.two_phase);
427
428 if (slot_contents.data.two_phase &&
429 XLogRecPtrIsValid(slot_contents.data.two_phase_at))
430 values[i++] = LSNGetDatum(slot_contents.data.two_phase_at);
431 else
432 nulls[i++] = true;
433
434 if (slot_contents.inactive_since > 0)
435 values[i++] = TimestampTzGetDatum(slot_contents.inactive_since);
436 else
437 nulls[i++] = true;
438
439 cause = slot_contents.data.invalidated;
440
442 nulls[i++] = true;
443 else
444 {
445 /*
446 * rows_removed and wal_level_insufficient are the only two
447 * reasons for the logical slot's conflict with recovery.
448 */
449 if (cause == RS_INVAL_HORIZON ||
450 cause == RS_INVAL_WAL_LEVEL)
451 values[i++] = BoolGetDatum(true);
452 else
453 values[i++] = BoolGetDatum(false);
454 }
455
456 if (cause == RS_INVAL_NONE)
457 nulls[i++] = true;
458 else
460
461 values[i++] = BoolGetDatum(slot_contents.data.failover);
462
463 values[i++] = BoolGetDatum(slot_contents.data.synced);
464
465 if (slot_contents.slotsync_skip_reason == SS_SKIP_NONE)
466 nulls[i++] = true;
467 else
469
471
472 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
473 values, nulls);
474 }
475
477
478 return (Datum) 0;
479}
480
481/*
482 * Helper function for advancing our physical replication slot forward.
483 *
484 * The LSN position to move to is compared simply to the slot's restart_lsn,
485 * knowing that any position older than that would be removed by successive
486 * checkpoints.
487 */
488static XLogRecPtr
490{
493
495
496 if (startlsn < moveto)
497 {
501 retlsn = moveto;
502
503 /*
504 * Dirty the slot so as it is written out at the next checkpoint. Note
505 * that the LSN position advanced may still be lost in the event of a
506 * crash, but this makes the data consistent after a clean shutdown.
507 */
509
510 /*
511 * Wake up logical walsenders holding logical failover slots after
512 * updating the restart_lsn of the physical slot.
513 */
515 }
516
517 return retlsn;
518}
519
520/*
521 * Advance our logical replication slot forward. See
522 * LogicalSlotAdvanceAndCheckSnapState for details.
523 */
524static XLogRecPtr
529
530/*
531 * SQL function for moving the position in a replication slot.
532 */
533Datum
535{
536 Name slotname = PG_GETARG_NAME(0);
540 TupleDesc tupdesc;
541 Datum values[2];
542 bool nulls[2];
543 HeapTuple tuple;
544 Datum result;
545
547
549
553 errmsg("invalid target WAL LSN")));
554
555 /* Build a tuple descriptor for our result type */
556 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
557 elog(ERROR, "return type must be a row type");
558
559 /*
560 * We can't move slot past what's been flushed/replayed so clamp the
561 * target position accordingly.
562 */
563 if (!RecoveryInProgress())
565 else
567
568 /* Acquire the slot so we "own" it */
569 ReplicationSlotAcquire(NameStr(*slotname), true, true);
570
571 /* A slot whose restart_lsn has never been reserved cannot be advanced */
575 errmsg("replication slot \"%s\" cannot be advanced",
576 NameStr(*slotname)),
577 errdetail("This slot has never previously reserved WAL, or it has been invalidated.")));
578
579 /*
580 * Check if the slot is not moving backwards. Physical slots rely simply
581 * on restart_lsn as a minimum point, while logical slots have confirmed
582 * consumption up to confirmed_flush, meaning that in both cases data
583 * older than that is not available anymore.
584 */
587 else
589
590 if (moveto < minlsn)
593 errmsg("cannot advance replication slot to %X/%08X, minimum is %X/%08X",
595
596 /* Do the actual slot update, depending on the slot type */
599 else
601
603 nulls[0] = false;
604
605 /*
606 * Recompute the minimum LSN and xmin across all slots to adjust with the
607 * advancing potentially done.
608 */
611
613
614 /* Return the reached position. */
616 nulls[1] = false;
617
618 tuple = heap_form_tuple(tupdesc, values, nulls);
619 result = HeapTupleGetDatum(tuple);
620
621 PG_RETURN_DATUM(result);
622}
623
624/*
625 * Helper function of copying a replication slot.
626 */
627static Datum
629{
632 ReplicationSlot *src = NULL;
636 bool src_islogical;
637 bool temporary;
638 char *plugin;
639 Datum values[2];
640 bool nulls[2];
641 Datum result;
642 TupleDesc tupdesc;
643 HeapTuple tuple;
644
645 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
646 elog(ERROR, "return type must be a row type");
647
649
650 if (logical_slot)
652 else
654
656
657 /*
658 * We need to prevent the source slot's reserved WAL from being removed,
659 * but we don't want to lock that slot for very long, and it can advance
660 * in the meantime. So obtain the source slot's data, and create a new
661 * slot using its restart_lsn. Afterwards we lock the source slot again
662 * and verify that the data we copied (name, type) has not changed
663 * incompatibly. No inconvenient WAL removal can occur once the new slot
664 * is created -- but since WAL removal could have occurred before we
665 * managed to create the new slot, we advance the new slot's restart_lsn
666 * to the source slot's updated restart_lsn the second time we lock it.
667 */
668 for (int i = 0; i < max_replication_slots; i++)
669 {
671
672 if (s->in_use && strcmp(NameStr(s->data.name), NameStr(*src_name)) == 0)
673 {
674 /* Copy the slot contents while holding spinlock */
678 src = s;
679 break;
680 }
681 }
682
684
685 if (src == NULL)
688 errmsg("replication slot \"%s\" does not exist", NameStr(*src_name))));
689
691 src_restart_lsn = first_slot_contents.data.restart_lsn;
692 temporary = (first_slot_contents.data.persistency == RS_TEMPORARY);
694
695 /* Check type of replication slot */
700 errmsg("cannot copy physical replication slot \"%s\" as a logical replication slot",
701 NameStr(*src_name)) :
702 errmsg("cannot copy logical replication slot \"%s\" as a physical replication slot",
703 NameStr(*src_name))));
704
705 /* Copying non-reserved slot doesn't make sense */
709 errmsg("cannot copy a replication slot that doesn't reserve WAL")));
710
711 /* Cannot copy an invalidated replication slot */
712 if (first_slot_contents.data.invalidated != RS_INVAL_NONE)
715 errmsg("cannot copy invalidated replication slot \"%s\"",
716 NameStr(*src_name)));
717
718 /* Overwrite params from optional arguments */
719 if (PG_NARGS() >= 3)
720 temporary = PG_GETARG_BOOL(2);
721 if (PG_NARGS() >= 4)
722 {
725 }
726
727 /* Create new slot and acquire it */
728 if (logical_slot)
729 {
730 /*
731 * We must not try to read WAL, since we haven't reserved it yet --
732 * hence pass find_startpoint false. confirmed_flush will be set
733 * below, by copying from the source slot.
734 *
735 * We don't copy the failover option to prevent potential issues with
736 * slot synchronization. For instance, if a slot was synchronized to
737 * the standby, then dropped on the primary, and immediately recreated
738 * by copying from another existing slot with much earlier restart_lsn
739 * and confirmed_flush_lsn, the slot synchronization would only
740 * observe the LSN of the same slot moving backward. As slot
741 * synchronization does not copy the restart_lsn and
742 * confirmed_flush_lsn backward (see update_local_synced_slot() for
743 * details), if a failover happens before the primary's slot catches
744 * up, logical replication cannot continue using the synchronized slot
745 * on the promoted standby because the slot retains the restart_lsn
746 * and confirmed_flush_lsn that are much later than expected.
747 */
749 plugin,
750 temporary,
751 false,
752 false,
754 false);
755 }
756 else
758 true,
759 temporary,
761
762 /*
763 * Update the destination slot to current values of the source slot;
764 * recheck that the source slot is still the one we saw previously.
765 */
766 {
773 bool copy_islogical;
774 char *copy_name;
775
776 /* Copy data of source slot again */
777 SpinLockAcquire(&src->mutex);
779 SpinLockRelease(&src->mutex);
780
782 copy_effective_catalog_xmin = second_slot_contents.effective_catalog_xmin;
783
785 copy_catalog_xmin = second_slot_contents.data.catalog_xmin;
786 copy_restart_lsn = second_slot_contents.data.restart_lsn;
787 copy_confirmed_flush = second_slot_contents.data.confirmed_flush;
788
789 /* for existence check */
792
793 /*
794 * Check if the source slot still exists and is valid. We regard it as
795 * invalid if the type of replication slot or name has been changed,
796 * or the restart_lsn either is invalid or has gone backward. (The
797 * restart_lsn could go backwards if the source slot is dropped and
798 * copied from an older slot during installation.)
799 *
800 * Since erroring out will release and drop the destination slot we
801 * don't need to release it here.
802 */
807 (errmsg("could not copy replication slot \"%s\"",
808 NameStr(*src_name)),
809 errdetail("The source replication slot was modified incompatibly during the copy operation.")));
810
811 /* The source slot must have a consistent snapshot */
815 errmsg("cannot copy unfinished logical replication slot \"%s\"",
816 NameStr(*src_name)),
817 errhint("Retry when the source replication slot's confirmed_flush_lsn is valid.")));
818
819 /*
820 * Copying an invalid slot doesn't make sense. Note that the source
821 * slot can become invalid after we create the new slot and copy the
822 * data of source slot. This is possible because the operations in
823 * InvalidateObsoleteReplicationSlots() are not serialized with this
824 * function. Even though we can't detect such a case here, the copied
825 * slot will become invalid in the next checkpoint cycle.
826 */
827 if (second_slot_contents.data.invalidated != RS_INVAL_NONE)
829 errmsg("cannot copy replication slot \"%s\"",
830 NameStr(*src_name)),
831 errdetail("The source replication slot was invalidated during the copy operation."));
832
833 /* Install copied values again */
837
843
848
849#ifdef USE_ASSERT_CHECKING
850 /* Check that the restart_lsn is available */
851 {
852 XLogSegNo segno;
853
856 }
857#endif
858 }
859
860 /* target slot fully created, mark as persistent if needed */
861 if (logical_slot && !temporary)
863
864 /* All done. Set up the return values */
866 nulls[0] = false;
868 {
870 nulls[1] = false;
871 }
872 else
873 nulls[1] = true;
874
875 tuple = heap_form_tuple(tupdesc, values, nulls);
876 result = HeapTupleGetDatum(tuple);
877
879
880 PG_RETURN_DATUM(result);
881}
882
883/* The wrappers below are all to appease opr_sanity */
884Datum
889
890Datum
895
896Datum
901
902Datum
907
908Datum
913
914/*
915 * Synchronize failover enabled replication slots to a standby server
916 * from the primary server.
917 */
918Datum
920{
922 char *err;
924
926
927 if (!RecoveryInProgress())
930 errmsg("replication slots can only be synchronized to a standby server"));
931
933
934 /* Load the libpq-specific functions */
935 load_file("libpqwalreceiver", false);
936
938
940 if (cluster_name[0])
941 appendStringInfo(&app_name, "%s_slotsync", cluster_name);
942 else
943 appendStringInfoString(&app_name, "slotsync");
944
945 /* Connect to the primary server. */
946 wrconn = walrcv_connect(PrimaryConnInfo, false, false, false,
947 app_name.data, &err);
948
949 if (!wrconn)
952 errmsg("synchronization worker \"%s\" could not connect to the primary server: %s",
953 app_name.data, err));
954
955 pfree(app_name.data);
956
958
960
962}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define NameStr(name)
Definition c.h:765
#define Min(x, y)
Definition c.h:997
#define Max(x, y)
Definition c.h:991
#define Assert(condition)
Definition c.h:873
uint64_t uint64
Definition c.h:547
uint32 TransactionId
Definition c.h:666
#define OidIsValid(objectId)
Definition c.h:788
void load_file(const char *filename, bool restricted)
Definition dfmgr.c:149
int errdetail(const char *fmt,...)
Definition elog.c:1217
int errhint(const char *fmt,...)
Definition elog.c:1331
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
void err(int eval, const char *fmt,...)
Definition err.c:43
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_NARGS()
Definition fmgr.h:203
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition funcapi.c:76
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
char * cluster_name
Definition guc_tables.c:563
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
int i
Definition isn.c:77
XLogRecPtr LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto, bool *found_consistent_snapshot)
Definition logical.c:2094
void FreeDecodingContext(LogicalDecodingContext *ctx)
Definition logical.c:668
void DecodingContextFindStartpoint(LogicalDecodingContext *ctx)
Definition logical.c:624
LogicalDecodingContext * CreateInitDecodingContext(const char *plugin, List *output_plugin_options, bool need_full_snapshot, XLogRecPtr restart_lsn, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition logical.c:321
void CheckLogicalDecodingRequirements(void)
Definition logical.c:111
bool IsLogicalDecodingEnabled(void)
Definition logicalctl.c:205
void EnsureLogicalDecodingEnabled(void)
Definition logicalctl.c:306
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1176
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1793
@ LW_SHARED
Definition lwlock.h:113
void pfree(void *pointer)
Definition mcxt.c:1616
#define NIL
Definition pg_list.h:68
#define PG_GETARG_LSN(n)
Definition pg_lsn.h:36
static Datum LSNGetDatum(XLogRecPtr X)
Definition pg_lsn.h:31
static bool two_phase
static bool failover
static const char * plugin
static Datum Int64GetDatum(int64 X)
Definition postgres.h:423
static Datum TransactionIdGetDatum(TransactionId X)
Definition postgres.h:302
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Datum NameGetDatum(const NameData *X)
Definition postgres.h:403
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
#define InvalidOid
static int fb(int x)
#define GetPGProcByNumber(n)
Definition proc.h:461
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int ProcNumber
Definition procnumber.h:24
void ReplicationSlotAcquire(const char *name, bool nowait, bool error_if_invalid)
Definition slot.c:621
void ReplicationSlotCreate(const char *name, bool db_specific, ReplicationSlotPersistency persistency, bool two_phase, bool failover, bool synced)
Definition slot.c:379
void ReplicationSlotMarkDirty(void)
Definition slot.c:1176
void ReplicationSlotReserveWal(void)
Definition slot.c:1696
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
Definition slot.c:1218
void ReplicationSlotPersist(void)
Definition slot.c:1193
ReplicationSlot * MyReplicationSlot
Definition slot.c:148
void ReplicationSlotDrop(const char *name, bool nowait)
Definition slot.c:912
void ReplicationSlotSave(void)
Definition slot.c:1158
void CheckSlotPermissions(void)
Definition slot.c:1679
void ReplicationSlotRelease(void)
Definition slot.c:761
int max_replication_slots
Definition slot.c:151
ReplicationSlotCtlData * ReplicationSlotCtl
Definition slot.c:145
void ReplicationSlotsComputeRequiredLSN(void)
Definition slot.c:1300
void CheckSlotRequirements(void)
Definition slot.c:1657
const char * GetSlotInvalidationCauseName(ReplicationSlotInvalidationCause cause)
Definition slot.c:2935
@ RS_PERSISTENT
Definition slot.h:45
@ RS_EPHEMERAL
Definition slot.h:46
@ RS_TEMPORARY
Definition slot.h:47
#define SlotIsPhysical(slot)
Definition slot.h:287
ReplicationSlotInvalidationCause
Definition slot.h:59
@ RS_INVAL_HORIZON
Definition slot.h:64
@ RS_INVAL_WAL_LEVEL
Definition slot.h:66
@ RS_INVAL_NONE
Definition slot.h:60
#define SlotIsLogical(slot)
Definition slot.h:288
@ SS_SKIP_WAL_NOT_FLUSHED
Definition slot.h:83
@ SS_SKIP_NO_CONSISTENT_SNAPSHOT
Definition slot.h:87
@ SS_SKIP_NONE
Definition slot.h:82
@ SS_SKIP_INVALID
Definition slot.h:89
@ SS_SKIP_WAL_OR_ROWS_REMOVED
Definition slot.h:85
Datum pg_get_replication_slots(PG_FUNCTION_ARGS)
Definition slotfuncs.c:255
Datum pg_copy_physical_replication_slot_a(PG_FUNCTION_ARGS)
Definition slotfuncs.c:903
static void create_logical_replication_slot(char *name, char *plugin, bool temporary, bool two_phase, bool failover, XLogRecPtr restart_lsn, bool find_startpoint)
Definition slotfuncs.c:129
Datum pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
Definition slotfuncs.c:188
#define PG_GET_REPLICATION_SLOTS_COLS
static Datum copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot)
Definition slotfuncs.c:628
Datum pg_copy_logical_replication_slot_c(PG_FUNCTION_ARGS)
Definition slotfuncs.c:897
Datum pg_create_physical_replication_slot(PG_FUNCTION_ARGS)
Definition slotfuncs.c:77
Datum pg_copy_logical_replication_slot_a(PG_FUNCTION_ARGS)
Definition slotfuncs.c:885
Datum pg_copy_physical_replication_slot_b(PG_FUNCTION_ARGS)
Definition slotfuncs.c:909
static const char * SlotSyncSkipReasonNames[]
Definition slotfuncs.c:31
Datum pg_sync_replication_slots(PG_FUNCTION_ARGS)
Definition slotfuncs.c:919
Datum pg_copy_logical_replication_slot_b(PG_FUNCTION_ARGS)
Definition slotfuncs.c:891
static XLogRecPtr pg_logical_replication_slot_advance(XLogRecPtr moveto)
Definition slotfuncs.c:525
static XLogRecPtr pg_physical_replication_slot_advance(XLogRecPtr moveto)
Definition slotfuncs.c:489
Datum pg_replication_slot_advance(PG_FUNCTION_ARGS)
Definition slotfuncs.c:534
static void create_physical_replication_slot(char *name, bool immediately_reserve, bool temporary, XLogRecPtr restart_lsn)
Definition slotfuncs.c:48
Datum pg_drop_replication_slot(PG_FUNCTION_ARGS)
Definition slotfuncs.c:237
void SyncReplicationSlots(WalReceiverConn *wrconn)
Definition slotsync.c:1920
char * CheckAndGetDbnameFromConninfo(void)
Definition slotsync.c:1116
bool ValidateSlotSyncParams(int elevel)
Definition slotsync.c:1143
#define SpinLockRelease(lock)
Definition spin.h:61
#define SpinLockAcquire(lock)
Definition spin.h:59
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
ReplicationSlot replication_slots[1]
Definition slot.h:299
TransactionId catalog_xmin
Definition slot.h:122
TransactionId effective_catalog_xmin
Definition slot.h:210
slock_t mutex
Definition slot.h:183
bool in_use
Definition slot.h:186
TransactionId effective_xmin
Definition slot.h:209
ProcNumber active_proc
Definition slot.h:192
ReplicationSlotPersistentData data
Definition slot.h:213
Definition c.h:760
#define InvalidTransactionId
Definition transam.h:31
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:784
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52
const char * name
static WalReceiverConn * wrconn
Definition walreceiver.c:94
#define walrcv_connect(conninfo, replication, logical, must_use_password, appname, err)
#define walrcv_disconnect(conn)
void PhysicalWakeupLogicalWalSnd(void)
Definition walsender.c:1759
bool RecoveryInProgress(void)
Definition xlog.c:6460
XLogSegNo XLogGetLastRemovedSegno(void)
Definition xlog.c:3795
int wal_keep_size_mb
Definition xlog.c:119
int wal_segment_size
Definition xlog.c:146
WALAvailability GetWALAvailability(XLogRecPtr targetLSN)
Definition xlog.c:8002
int max_slot_wal_keep_size_mb
Definition xlog.c:138
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
Definition xlog.c:6625
XLogRecPtr GetXLogWriteRecPtr(void)
Definition xlog.c:9614
WALAvailability
Definition xlog.h:199
@ WALAVAIL_REMOVED
Definition xlog.h:205
@ WALAVAIL_RESERVED
Definition xlog.h:201
@ WALAVAIL_UNRESERVED
Definition xlog.h:204
@ WALAVAIL_EXTENDED
Definition xlog.h:202
@ WALAVAIL_INVALID_LSN
Definition xlog.h:200
#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest)
#define XLogMBVarToSegs(mbvar, wal_segsz_bytes)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
#define XLogRecPtrIsValid(r)
Definition xlogdefs.h:29
#define LSN_FORMAT_ARGS(lsn)
Definition xlogdefs.h:47
uint64 XLogRecPtr
Definition xlogdefs.h:21
#define InvalidXLogRecPtr
Definition xlogdefs.h:28
uint64 XLogSegNo
Definition xlogdefs.h:52
#define XL_ROUTINE(...)
Definition xlogreader.h:117
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
char * PrimaryConnInfo
void wal_segment_close(XLogReaderState *state)
Definition xlogutils.c:831
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition xlogutils.c:806
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition xlogutils.c:845