PostgreSQL Source Code  git master
output_plugin.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * output_plugin.h
3  * PostgreSQL Logical Decode Plugin Interface
4  *
5  * Copyright (c) 2012-2024, PostgreSQL Global Development Group
6  *
7  *-------------------------------------------------------------------------
8  */
9 #ifndef OUTPUT_PLUGIN_H
10 #define OUTPUT_PLUGIN_H
11 
13 
16 
18 {
22 
23 /*
24  * Options set by the output plugin, in the startup callback.
25  */
26 typedef struct OutputPluginOptions
27 {
31 
32 /*
33  * Type of the shared library symbol _PG_output_plugin_init that is looked up
34  * when loading an output plugin shared library.
35  */
36 typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
37 
39 
40 /*
41  * Callback that gets called in a user-defined plugin. ctx->private_data can
42  * be set to some private data.
43  *
44  * "is_init" will be set to "true" if the decoding slot just got defined. When
45  * the same slot is used from there one, it will be "false".
46  */
47 typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,
49  bool is_init);
50 
51 /*
52  * Callback called for every (explicit or implicit) BEGIN of a successful
53  * transaction.
54  */
55 typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
56  ReorderBufferTXN *txn);
57 
58 /*
59  * Callback for every individual change in a successful transaction.
60  */
61 typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
62  ReorderBufferTXN *txn,
63  Relation relation,
64  ReorderBufferChange *change);
65 
66 /*
67  * Callback for every TRUNCATE in a successful transaction.
68  */
69 typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
70  ReorderBufferTXN *txn,
71  int nrelations,
72  Relation relations[],
73  ReorderBufferChange *change);
74 
75 /*
76  * Called for every (explicit or implicit) COMMIT of a successful transaction.
77  */
78 typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
79  ReorderBufferTXN *txn,
80  XLogRecPtr commit_lsn);
81 
82 /*
83  * Called for the generic logical decoding messages.
84  */
85 typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,
86  ReorderBufferTXN *txn,
87  XLogRecPtr message_lsn,
88  bool transactional,
89  const char *prefix,
90  Size message_size,
91  const char *message);
92 
93 /*
94  * Filter changes by origin.
95  */
97  RepOriginId origin_id);
98 
99 /*
100  * Called to shutdown an output plugin.
101  */
102 typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);
103 
104 /*
105  * Called before decoding of PREPARE record to decide whether this
106  * transaction should be decoded with separate calls to prepare and
107  * commit_prepared/rollback_prepared callbacks or wait till COMMIT PREPARED
108  * and sent as usual transaction.
109  */
111  TransactionId xid,
112  const char *gid);
113 
114 /*
115  * Callback called for every BEGIN of a prepared transaction.
116  */
118  ReorderBufferTXN *txn);
119 
120 /*
121  * Called for PREPARE record unless it was filtered by filter_prepare()
122  * callback.
123  */
124 typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
125  ReorderBufferTXN *txn,
126  XLogRecPtr prepare_lsn);
127 
128 /*
129  * Called for COMMIT PREPARED.
130  */
132  ReorderBufferTXN *txn,
133  XLogRecPtr commit_lsn);
134 
135 /*
136  * Called for ROLLBACK PREPARED.
137  */
139  ReorderBufferTXN *txn,
140  XLogRecPtr prepare_end_lsn,
141  TimestampTz prepare_time);
142 
143 
144 /*
145  * Called when starting to stream a block of changes from in-progress
146  * transaction (may be called repeatedly, if it's streamed in multiple
147  * chunks).
148  */
150  ReorderBufferTXN *txn);
151 
152 /*
153  * Called when stopping to stream a block of changes from in-progress
154  * transaction to a remote node (may be called repeatedly, if it's streamed
155  * in multiple chunks).
156  */
158  ReorderBufferTXN *txn);
159 
160 /*
161  * Called to discard changes streamed to remote node from in-progress
162  * transaction.
163  */
165  ReorderBufferTXN *txn,
166  XLogRecPtr abort_lsn);
167 
168 /*
169  * Called to prepare changes streamed to remote node from in-progress
170  * transaction. This is called as part of a two-phase commit.
171  */
173  ReorderBufferTXN *txn,
174  XLogRecPtr prepare_lsn);
175 
176 /*
177  * Called to apply changes streamed to remote node from in-progress
178  * transaction.
179  */
181  ReorderBufferTXN *txn,
182  XLogRecPtr commit_lsn);
183 
184 /*
185  * Callback for streaming individual changes from in-progress transactions.
186  */
188  ReorderBufferTXN *txn,
189  Relation relation,
190  ReorderBufferChange *change);
191 
192 /*
193  * Callback for streaming generic logical decoding messages from in-progress
194  * transactions.
195  */
197  ReorderBufferTXN *txn,
198  XLogRecPtr message_lsn,
199  bool transactional,
200  const char *prefix,
201  Size message_size,
202  const char *message);
203 
204 /*
205  * Callback for streaming truncates from in-progress transactions.
206  */
208  ReorderBufferTXN *txn,
209  int nrelations,
210  Relation relations[],
211  ReorderBufferChange *change);
212 
213 /*
214  * Output plugin callbacks
215  */
216 typedef struct OutputPluginCallbacks
217 {
226 
227  /* streaming of changes at prepare time */
233 
234  /* streaming of changes */
244 
245 /* Functions in replication/logical/logical.c */
246 extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
247 extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
248 extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool skipped_xact);
249 
250 #endif /* OUTPUT_PLUGIN_H */
#define PGDLLEXPORT
Definition: c.h:1289
uint32 TransactionId
Definition: c.h:606
size_t Size
Definition: c.h:559
int64 TimestampTz
Definition: timestamp.h:39
void(* LogicalDecodeStreamCommitCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
struct OutputPluginOptions OutputPluginOptions
bool(* LogicalDecodeFilterByOriginCB)(struct LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: output_plugin.h:96
void(* LogicalDecodeBeginCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
Definition: output_plugin.h:55
void(* LogicalDecodeBeginPrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
void(* LogicalDecodeStreamAbortCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
void(* LogicalDecodeCommitPreparedCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
bool(* LogicalDecodeFilterPrepareCB)(struct LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
void(* LogicalDecodePrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
OutputPluginOutputType
Definition: output_plugin.h:18
@ OUTPUT_PLUGIN_BINARY_OUTPUT
Definition: output_plugin.h:19
@ OUTPUT_PLUGIN_TEXTUAL_OUTPUT
Definition: output_plugin.h:20
void(* LogicalDecodeStreamPrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
void(* LogicalDecodeChangeCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: output_plugin.h:61
void(* LogicalDecodeStreamStartCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:722
void(* LogicalDecodeStreamTruncateCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
Definition: output_plugin.h:36
void(* LogicalDecodeCommitCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: output_plugin.h:78
void(* LogicalDecodeStreamChangeCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
void(* LogicalDecodeMessageCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
Definition: output_plugin.h:85
void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool skipped_xact)
Definition: logical.c:735
PGDLLEXPORT void _PG_output_plugin_init(struct OutputPluginCallbacks *cb)
struct OutputPluginCallbacks OutputPluginCallbacks
void(* LogicalDecodeStreamMessageCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
void(* LogicalDecodeRollbackPreparedCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
void(* LogicalDecodeTruncateCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: output_plugin.h:69
void(* LogicalDecodeStartupCB)(struct LogicalDecodingContext *ctx, OutputPluginOptions *options, bool is_init)
Definition: output_plugin.h:47
void(* LogicalDecodeShutdownCB)(struct LogicalDecodingContext *ctx)
void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:709
void(* LogicalDecodeStreamStopCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
static char ** options
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
OutputPluginOutputType output_type
Definition: output_plugin.h:28
uint16 RepOriginId
Definition: xlogdefs.h:65
uint64 XLogRecPtr
Definition: xlogdefs.h:21