75 const char *prefix,
Size message_size,
const char *message);
92 const char *prefix,
Size message_size,
const char *message);
114 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
115 errmsg(
"logical decoding requires wal_level >= logical")));
119 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
120 errmsg(
"logical decoding requires a database connection")));
137 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
138 errmsg(
"logical decoding cannot be used while in recovery")));
149 bool need_full_snapshot,
165 "Logical decoding context",
204 (
errcode(ERRCODE_OUT_OF_MEMORY),
206 errdetail(
"Failed while allocating a WAL reading processor.")));
283 ctx->
write = do_write;
320 List *output_plugin_options,
321 bool need_full_snapshot,
339 elog(
ERROR,
"cannot perform logical decoding without an acquired slot");
342 elog(
ERROR,
"cannot initialize logical decoding without a specified plugin");
347 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
348 errmsg(
"cannot use physical replication slot for logical decoding")));
352 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
353 errmsg(
"replication slot \"%s\" was not created in this database",
359 (
errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
360 errmsg(
"cannot create logical replication slot in transaction that has performed writes")));
413 if (need_full_snapshot)
425 need_full_snapshot,
false,
426 xl_routine, prepare_write, do_write,
480 List *output_plugin_options,
496 elog(
ERROR,
"cannot perform logical decoding without an acquired slot");
501 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
502 errmsg(
"cannot use physical replication slot for logical decoding")));
506 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
507 errmsg(
"replication slot \"%s\" was not created in this database",
515 else if (start_lsn < slot->
data.confirmed_flush)
529 elog(
LOG,
"%X/%X has been already streamed, forwarding to %X/%X",
538 fast_forward, xl_routine, prepare_write,
539 do_write, update_progress);
568 (
errmsg(
"starting logical decoding for slot \"%s\"",
570 errdetail(
"Streaming transactions committing after %X/%X, reading WAL from %X/%X.",
597 elog(
DEBUG1,
"searching for logical decoding starting point, starting at %X/%X",
609 elog(
ERROR,
"could not find logical decoding starting point: %s", err);
611 elog(
ERROR,
"could not find logical decoding starting point");
652 elog(
ERROR,
"writes are only accepted in commit, begin and change callbacks");
665 elog(
ERROR,
"OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
697 if (plugin_init == NULL)
698 elog(
ERROR,
"output plugins have to declare the _PG_output_plugin_init symbol");
701 plugin_init(callbacks);
704 elog(
ERROR,
"output plugins have to register a begin callback");
706 elog(
ERROR,
"output plugins have to register a change callback");
708 elog(
ERROR,
"output plugins have to register a commit callback");
718 errcontext(
"slot \"%s\", output plugin \"%s\", in the %s callback, associated LSN %X/%X",
721 state->callback_name,
724 errcontext(
"slot \"%s\", output plugin \"%s\", in the %s callback",
727 state->callback_name);
740 state.callback_name =
"startup";
768 state.callback_name =
"shutdown";
802 state.callback_name =
"begin";
834 state.callback_name =
"commit";
875 state.callback_name =
"begin_prepare";
894 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
895 errmsg(
"logical replication at prepare time requires a %s callback",
896 "begin_prepare_cb")));
920 state.callback_name =
"prepare";
939 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
940 errmsg(
"logical replication at prepare time requires a %s callback",
965 state.callback_name =
"commit_prepared";
984 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
985 errmsg(
"logical replication at prepare time requires a %s callback",
986 "commit_prepared_cb")));
1011 state.callback_name =
"rollback_prepared";
1030 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1031 errmsg(
"logical replication at prepare time requires a %s callback",
1032 "rollback_prepared_cb")));
1054 state.callback_name =
"change";
1055 state.report_location = change->
lsn;
1096 state.callback_name =
"truncate";
1097 state.report_location = change->
lsn;
1135 state.callback_name =
"filter_prepare";
1166 state.callback_name =
"filter_by_origin";
1189 const char *prefix,
Size message_size,
const char *message)
1202 state.callback_name =
"message";
1203 state.report_location = message_lsn;
1217 message_size, message);
1238 state.callback_name =
"stream_start";
1239 state.report_location = first_lsn;
1262 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1263 errmsg(
"logical streaming requires a %s callback",
1264 "stream_start_cb")));
1287 state.callback_name =
"stream_stop";
1288 state.report_location = last_lsn;
1311 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1312 errmsg(
"logical streaming requires a %s callback",
1313 "stream_stop_cb")));
1336 state.callback_name =
"stream_abort";
1337 state.report_location = abort_lsn;
1352 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1353 errmsg(
"logical streaming requires a %s callback",
1354 "stream_abort_cb")));
1381 state.callback_name =
"stream_prepare";
1397 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1398 errmsg(
"logical streaming at prepare time requires a %s callback",
1399 "stream_prepare_cb")));
1422 state.callback_name =
"stream_commit";
1438 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1439 errmsg(
"logical streaming requires a %s callback",
1440 "stream_commit_cb")));
1463 state.callback_name =
"stream_change";
1464 state.report_location = change->
lsn;
1487 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1488 errmsg(
"logical streaming requires a %s callback",
1489 "stream_change_cb")));
1500 const char *prefix,
Size message_size,
const char *message)
1517 state.callback_name =
"stream_message";
1518 state.report_location = message_lsn;
1532 message_size, message);
1540 int nrelations,
Relation relations[],
1558 state.callback_name =
"stream_truncate";
1559 state.report_location = change->
lsn;
1596 bool updated_xmin =
false;
1598 bool got_new_xmin =
false;
1619 else if (current_lsn <= slot->
data.confirmed_flush)
1625 updated_xmin =
true;
1641 got_new_xmin =
true;
1646 elog(
DEBUG1,
"got new catalog xmin %u at %X/%X", xmin,
1664 bool updated_lsn =
false;
1676 if (restart_lsn <= slot->
data.restart_lsn)
1684 else if (current_lsn <= slot->
data.confirmed_flush)
1704 elog(
DEBUG1,
"got new restart lsn %X/%X at %X/%X",
1719 elog(
DEBUG1,
"failed to increase restart lsn: proposed %X/%X, after %X/%X, current candidate %X/%X, current after %X/%X, flushed up to %X/%X",
1744 bool updated_xmin =
false;
1745 bool updated_restart =
false;
1770 updated_xmin =
true;
1782 updated_restart =
true;
1788 if (updated_xmin || updated_restart)
1792 elog(
DEBUG1,
"updated xmin: %u restart: %u", updated_xmin, updated_restart);
1842 elog(
DEBUG2,
"UpdateDecodingStats: updating stats %p %lld %lld %lld %lld %lld %lld %lld %lld",
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 errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
void FreeDecodingContext(LogicalDecodingContext *ctx)
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)
static void prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
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)
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)
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)
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)
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)
LogicalDecodingContext * CreateDecodingContext(XLogRecPtr start_lsn, List *output_plugin_options, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
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)
void ReplicationSlotMarkDirty(void)
void ReplicationSlotReserveWal(void)
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
ReplicationSlot * MyReplicationSlot
void ReplicationSlotSave(void)
void ReplicationSlotsComputeRequiredLSN(void)
void CheckSlotRequirements(void)
#define SlotIsPhysical(slot)
void SnapBuildSetTwoPhaseAt(SnapBuild *builder, XLogRecPtr ptr)
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
void FreeSnapshotBuilder(SnapBuild *builder)
SnapBuild * AllocateSnapshotBuilder(ReorderBuffer *reorder, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot, XLogRecPtr two_phase_at)
#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
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
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)
#define LSN_FORMAT_ARGS(lsn)
#define XLogRecPtrIsInvalid(r)
#define InvalidXLogRecPtr
XLogRecord * XLogReadRecord(XLogReaderState *state, char **errormsg)
void XLogReaderFree(XLogReaderState *state)
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, XLogReaderRoutine *routine, void *private_data)
void XLogBeginRead(XLogReaderState *state, XLogRecPtr RecPtr)