78 const char *prefix,
Size message_size,
const char *message);
95 const char *prefix,
Size message_size,
const char *message);
122 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
123 errmsg(
"logical decoding requires \"wal_level\" >= \"logical\"")));
127 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
128 errmsg(
"logical decoding requires a database connection")));
142 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
143 errmsg(
"logical decoding on standby requires \"wal_level\" >= \"logical\" on the primary")));
155 bool need_full_snapshot,
172 "Logical decoding context",
211 (
errcode(ERRCODE_OUT_OF_MEMORY),
213 errdetail(
"Failed while allocating a WAL reading processor.")));
296 ctx->
write = do_write;
333 List *output_plugin_options,
334 bool need_full_snapshot,
358 elog(
ERROR,
"cannot perform logical decoding without an acquired slot");
361 elog(
ERROR,
"cannot initialize logical decoding without a specified plugin");
366 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
367 errmsg(
"cannot use physical replication slot for logical decoding")));
371 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
372 errmsg(
"replication slot \"%s\" was not created in this database",
378 (
errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
379 errmsg(
"cannot create logical replication slot in transaction that has performed writes")));
432 if (need_full_snapshot)
444 need_full_snapshot,
false,
true,
445 xl_routine, prepare_write, do_write,
499 List *output_plugin_options,
515 elog(
ERROR,
"cannot perform logical decoding without an acquired slot");
520 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
521 errmsg(
"cannot use physical replication slot for logical decoding")));
530 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
531 errmsg(
"replication slot \"%s\" was not created in this database",
541 errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
542 errmsg(
"cannot use replication slot \"%s\" for logical decoding",
544 errdetail(
"This replication slot is being synchronized from the primary server."),
545 errhint(
"Specify another replication slot."));
556 else if (start_lsn < slot->
data.confirmed_flush)
570 elog(
LOG,
"%X/%08X has been already streamed, forwarding to %X/%08X",
579 fast_forward,
false, xl_routine, prepare_write,
580 do_write, update_progress);
611 (
errmsg(
"starting logical decoding for slot \"%s\"",
613 errdetail(
"Streaming transactions committing after %X/%08X, reading WAL from %X/%08X.",
640 elog(
DEBUG1,
"searching for logical decoding starting point, starting at %X/%08X",
652 elog(
ERROR,
"could not find logical decoding starting point: %s",
err);
654 elog(
ERROR,
"could not find logical decoding starting point");
695 elog(
ERROR,
"writes are only accepted in commit, begin and change callbacks");
708 elog(
ERROR,
"OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
740 if (plugin_init == NULL)
741 elog(
ERROR,
"output plugins have to declare the _PG_output_plugin_init symbol");
744 plugin_init(callbacks);
747 elog(
ERROR,
"output plugins have to register a begin callback");
749 elog(
ERROR,
"output plugins have to register a change callback");
751 elog(
ERROR,
"output plugins have to register a commit callback");
761 errcontext(
"slot \"%s\", output plugin \"%s\", in the %s callback, associated LSN %X/%08X",
764 state->callback_name,
767 errcontext(
"slot \"%s\", output plugin \"%s\", in the %s callback",
770 state->callback_name);
783 state.callback_name =
"startup";
811 state.callback_name =
"shutdown";
845 state.callback_name =
"begin";
877 state.callback_name =
"commit";
918 state.callback_name =
"begin_prepare";
937 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
938 errmsg(
"logical replication at prepare time requires a %s callback",
939 "begin_prepare_cb")));
963 state.callback_name =
"prepare";
982 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
983 errmsg(
"logical replication at prepare time requires a %s callback",
1008 state.callback_name =
"commit_prepared";
1027 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1028 errmsg(
"logical replication at prepare time requires a %s callback",
1029 "commit_prepared_cb")));
1054 state.callback_name =
"rollback_prepared";
1073 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1074 errmsg(
"logical replication at prepare time requires a %s callback",
1075 "rollback_prepared_cb")));
1097 state.callback_name =
"change";
1098 state.report_location = change->
lsn;
1139 state.callback_name =
"truncate";
1140 state.report_location = change->
lsn;
1178 state.callback_name =
"filter_prepare";
1209 state.callback_name =
"filter_by_origin";
1232 const char *prefix,
Size message_size,
const char *message)
1245 state.callback_name =
"message";
1246 state.report_location = message_lsn;
1260 message_size, message);
1281 state.callback_name =
"stream_start";
1282 state.report_location = first_lsn;
1305 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1306 errmsg(
"logical streaming requires a %s callback",
1307 "stream_start_cb")));
1330 state.callback_name =
"stream_stop";
1331 state.report_location = last_lsn;
1354 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1355 errmsg(
"logical streaming requires a %s callback",
1356 "stream_stop_cb")));
1379 state.callback_name =
"stream_abort";
1380 state.report_location = abort_lsn;
1395 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1396 errmsg(
"logical streaming requires a %s callback",
1397 "stream_abort_cb")));
1424 state.callback_name =
"stream_prepare";
1440 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1441 errmsg(
"logical streaming at prepare time requires a %s callback",
1442 "stream_prepare_cb")));
1465 state.callback_name =
"stream_commit";
1481 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1482 errmsg(
"logical streaming requires a %s callback",
1483 "stream_commit_cb")));
1506 state.callback_name =
"stream_change";
1507 state.report_location = change->
lsn;
1530 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1531 errmsg(
"logical streaming requires a %s callback",
1532 "stream_change_cb")));
1543 const char *prefix,
Size message_size,
const char *message)
1560 state.callback_name =
"stream_message";
1561 state.report_location = message_lsn;
1575 message_size, message);
1583 int nrelations,
Relation relations[],
1601 state.callback_name =
"stream_truncate";
1602 state.report_location = change->
lsn;
1640 state.callback_name =
"update_progress_txn";
1641 state.report_location = lsn;
1678 bool updated_xmin =
false;
1680 bool got_new_xmin =
false;
1701 else if (current_lsn <= slot->
data.confirmed_flush)
1707 updated_xmin =
true;
1723 got_new_xmin =
true;
1728 elog(
DEBUG1,
"got new catalog xmin %u at %X/%08X", xmin,
1746 bool updated_lsn =
false;
1758 if (restart_lsn <= slot->
data.restart_lsn)
1767 else if (current_lsn <= slot->
data.confirmed_flush)
1788 elog(
DEBUG1,
"got new restart lsn %X/%08X at %X/%08X",
1803 elog(
DEBUG1,
"failed to increase restart lsn: proposed %X/%08X, after %X/%08X, current candidate %X/%08X, current after %X/%08X, flushed up to %X/%08X",
1828 bool updated_xmin =
false;
1829 bool updated_restart =
false;
1870 updated_xmin =
true;
1882 updated_restart =
true;
1888 if (updated_xmin || updated_restart)
1890#ifdef USE_INJECTION_POINTS
1904 elog(
DEBUG1,
"updated xmin: %u restart: %u", updated_xmin, updated_restart);
1961 elog(
DEBUG2,
"UpdateDecodingStats: updating stats %p %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64,
2001 bool has_pending_wal =
false;
2040 elog(
ERROR,
"could not find record for logical decoding: %s", errm);
2063 return has_pending_wal;
2082 bool *found_consistent_snapshot)
2090 if (found_consistent_snapshot)
2091 *found_consistent_snapshot =
false;
2135 elog(
ERROR,
"could not find record while advancing replication slot: %s",
2160 *found_consistent_snapshot =
true;
#define pg_attribute_unused()
#define PG_USED_FOR_ASSERTS_ONLY
void LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *record)
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
Assert(PointerIsAligned(start, uint64))
#define INJECTION_POINT(name, arg)
void InvalidateSystemCaches(void)
static void change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
static void commit_prepared_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
static void update_progress_txn_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr lsn)
XLogRecPtr LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto, bool *found_consistent_snapshot)
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
void FreeDecodingContext(LogicalDecodingContext *ctx)
bool LogicalReplicationSlotHasPendingWal(XLogRecPtr end_of_wal)
static void stream_start_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
static void commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
static void output_plugin_error_callback(void *arg)
static void begin_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn)
static void stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
LogicalDecodingContext * CreateDecodingContext(XLogRecPtr start_lsn, List *output_plugin_options, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
static void prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
static void stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
static void truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
void DecodingContextFindStartpoint(LogicalDecodingContext *ctx)
static void begin_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn)
static void rollback_prepared_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
bool DecodingContextReady(LogicalDecodingContext *ctx)
void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool skipped_xact)
static void startup_cb_wrapper(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
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)
void UpdateDecodingStats(LogicalDecodingContext *ctx)
void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart_lsn)
static void stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
static void stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
void ResetLogicalStreamingState(void)
void LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin)
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, bool in_create, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
struct LogicalErrorCallbackState LogicalErrorCallbackState
static void stream_message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
static void stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
static void shutdown_cb_wrapper(LogicalDecodingContext *ctx)
void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
void CheckLogicalDecodingRequirements(void)
bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id)
static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin)
static void stream_stop_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
static void message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
void(* LogicalOutputPluginWriterUpdateProgress)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool skipped_xact)
void(* LogicalOutputPluginWriterWrite)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool last_write)
LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
void namestrcpy(Name name, const char *str)
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static const char * plugin
void pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
#define PROC_IN_LOGICAL_DECODING
TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly)
ReorderBuffer * ReorderBufferAllocate(void)
void ReorderBufferFree(ReorderBuffer *rb)
ResourceOwner CurrentResourceOwner
void ReplicationSlotMarkDirty(void)
void ReplicationSlotReserveWal(void)
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
ReplicationSlot * MyReplicationSlot
void ReplicationSlotSave(void)
void WaitForStandbyConfirmation(XLogRecPtr wait_for_lsn)
void ReplicationSlotsComputeRequiredLSN(void)
void CheckSlotRequirements(void)
#define SlotIsPhysical(slot)
bool IsSyncingReplicationSlots(void)
void SnapBuildSetTwoPhaseAt(SnapBuild *builder, XLogRecPtr ptr)
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
SnapBuild * AllocateSnapshotBuilder(ReorderBuffer *reorder, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot, bool in_slot_creation, XLogRecPtr two_phase_at)
void FreeSnapshotBuilder(SnapBuild *builder)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
StringInfo makeStringInfo(void)
struct ErrorContextCallback * previous
void(* callback)(void *arg)
OutputPluginOptions options
struct SnapBuild * snapshot_builder
XLogRecPtr write_location
LogicalOutputPluginWriterPrepareWrite prepare_write
OutputPluginCallbacks callbacks
List * output_plugin_options
LogicalOutputPluginWriterWrite write
struct ReorderBuffer * reorder
LogicalOutputPluginWriterUpdateProgress update_progress
XLogRecPtr report_location
LogicalDecodingContext * ctx
const char * callback_name
LogicalDecodeStreamChangeCB stream_change_cb
LogicalDecodeMessageCB message_cb
LogicalDecodeStreamTruncateCB stream_truncate_cb
LogicalDecodeStreamMessageCB stream_message_cb
LogicalDecodeFilterPrepareCB filter_prepare_cb
LogicalDecodeFilterByOriginCB filter_by_origin_cb
LogicalDecodeTruncateCB truncate_cb
LogicalDecodeStreamStopCB stream_stop_cb
LogicalDecodeStreamCommitCB stream_commit_cb
LogicalDecodeRollbackPreparedCB rollback_prepared_cb
LogicalDecodeStreamPrepareCB stream_prepare_cb
LogicalDecodeCommitPreparedCB commit_prepared_cb
LogicalDecodeStreamStartCB stream_start_cb
LogicalDecodePrepareCB prepare_cb
LogicalDecodeStartupCB startup_cb
LogicalDecodeCommitCB commit_cb
LogicalDecodeBeginCB begin_cb
LogicalDecodeStreamAbortCB stream_abort_cb
LogicalDecodeBeginPrepareCB begin_prepare_cb
LogicalDecodeChangeCB change_cb
LogicalDecodeShutdownCB shutdown_cb
PgStat_Counter stream_count
PgStat_Counter total_txns
PgStat_Counter total_bytes
PgStat_Counter spill_txns
PgStat_Counter stream_txns
PgStat_Counter spill_count
PgStat_Counter stream_bytes
PgStat_Counter spill_bytes
ReorderBufferStreamMessageCB stream_message
ReorderBufferStreamChangeCB stream_change
ReorderBufferBeginCB begin_prepare
ReorderBufferStreamTruncateCB stream_truncate
ReorderBufferCommitPreparedCB commit_prepared
ReorderBufferUpdateProgressTxnCB update_progress_txn
ReorderBufferMessageCB message
ReorderBufferRollbackPreparedCB rollback_prepared
ReorderBufferPrepareCB prepare
ReorderBufferStreamStopCB stream_stop
ReorderBufferApplyChangeCB apply_change
ReorderBufferStreamPrepareCB stream_prepare
ReorderBufferStreamAbortCB stream_abort
ReorderBufferCommitCB commit
ReorderBufferStreamStartCB stream_start
ReorderBufferStreamCommitCB stream_commit
ReorderBufferApplyTruncateCB apply_truncate
ReorderBufferBeginCB begin
TransactionId catalog_xmin
XLogRecPtr confirmed_flush
ReplicationSlotInvalidationCause invalidated
XLogRecPtr candidate_xmin_lsn
TransactionId effective_catalog_xmin
XLogRecPtr candidate_restart_valid
TransactionId effective_xmin
XLogRecPtr candidate_restart_lsn
TransactionId candidate_catalog_xmin
ReplicationSlotPersistentData data
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
#define InvalidTransactionId
#define TransactionIdIsValid(xid)
bool IsTransactionOrTransactionBlock(void)
TransactionId CheckXidAlive
bool IsTransactionState(void)
TransactionId GetTopTransactionIdIfAny(void)
bool RecoveryInProgress(void)
WalLevel GetActiveWalLevelOnStandby(void)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
#define LSN_FORMAT_ARGS(lsn)
#define XLogRecPtrIsInvalid(r)
#define InvalidXLogRecPtr
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, XLogReaderRoutine *routine, void *private_data)
XLogRecord * XLogReadRecord(XLogReaderState *state, char **errormsg)
void XLogReaderFree(XLogReaderState *state)
void XLogBeginRead(XLogReaderState *state, XLogRecPtr RecPtr)
void wal_segment_close(XLogReaderState *state)
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)