1 /*-------------------------------------------------------------------------
3 * PostgreSQL Logical Decode Plugin Interface
5 * Copyright (c) 2012-2015, PostgreSQL Global Development Group
7 *-------------------------------------------------------------------------
9 #ifndef OUTPUT_PLUGIN_H
10 #define OUTPUT_PLUGIN_H
12 #include "replication/reorderbuffer.h"
14 struct LogicalDecodingContext;
15 struct OutputPluginCallbacks;
17 typedef enum OutputPluginOutputType
19 OUTPUT_PLUGIN_BINARY_OUTPUT,
20 OUTPUT_PLUGIN_TEXTUAL_OUTPUT
21 } OutputPluginOutputType;
24 * Options set by the output plugin, in the startup callback.
26 typedef struct OutputPluginOptions
28 OutputPluginOutputType output_type;
29 } OutputPluginOptions;
32 * Type of the shared library symbol _PG_output_plugin_init that is looked up
33 * when loading an output plugin shared library.
35 typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
38 * Callback that gets called in a user-defined plugin. ctx->private_data can
39 * be set to some private data.
41 * "is_init" will be set to "true" if the decoding slot just got defined. When
42 * the same slot is used from there one, it will be "false".
44 typedef void (*LogicalDecodeStartupCB) (
45 struct LogicalDecodingContext *ctx,
46 OutputPluginOptions *options,
51 * Callback called for every (explicit or implicit) BEGIN of a successful
54 typedef void (*LogicalDecodeBeginCB) (
55 struct LogicalDecodingContext *,
56 ReorderBufferTXN *txn);
59 * Callback for every individual change in a successful transaction.
61 typedef void (*LogicalDecodeChangeCB) (
62 struct LogicalDecodingContext *,
63 ReorderBufferTXN *txn,
65 ReorderBufferChange *change
69 * Called for every (explicit or implicit) COMMIT of a successful transaction.
71 typedef void (*LogicalDecodeCommitCB) (
72 struct LogicalDecodingContext *,
73 ReorderBufferTXN *txn,
74 XLogRecPtr commit_lsn);
77 * Called to shutdown an output plugin.
79 typedef void (*LogicalDecodeShutdownCB) (
80 struct LogicalDecodingContext *
84 * Output plugin callbacks
86 typedef struct OutputPluginCallbacks
88 LogicalDecodeStartupCB startup_cb;
89 LogicalDecodeBeginCB begin_cb;
90 LogicalDecodeChangeCB change_cb;
91 LogicalDecodeCommitCB commit_cb;
92 LogicalDecodeShutdownCB shutdown_cb;
93 } OutputPluginCallbacks;
95 void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
96 void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
98 #endif /* OUTPUT_PLUGIN_H */