1/*-------------------------------------------------------------------------
2 * output_plugin.h
3 * PostgreSQL Logical Decode Plugin Interface
4 *
5 * Copyright (c) 2012-2019, PostgreSQL Global Development Group
6 *
7 *-------------------------------------------------------------------------
8 */
9#ifndef OUTPUT_PLUGIN_H
10#define OUTPUT_PLUGIN_H
11
12#include "replication/reorderbuffer.h"
13
14struct LogicalDecodingContext;
15struct OutputPluginCallbacks;
16
17typedef enum OutputPluginOutputType
18{
19 OUTPUT_PLUGIN_BINARY_OUTPUT,
20 OUTPUT_PLUGIN_TEXTUAL_OUTPUT
21} OutputPluginOutputType;
22
23/*
24 * Options set by the output plugin, in the startup callback.
25 */
26typedef struct OutputPluginOptions
27{
28 OutputPluginOutputType output_type;
29 bool receive_rewrites;
30} OutputPluginOptions;
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 */
36typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
37
38/*
39 * Callback that gets called in a user-defined plugin. ctx->private_data can
40 * be set to some private data.
41 *
42 * "is_init" will be set to "true" if the decoding slot just got defined. When
43 * the same slot is used from there one, it will be "false".
44 */
45typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,
46 OutputPluginOptions *options,
47 bool is_init);
48
49/*
50 * Callback called for every (explicit or implicit) BEGIN of a successful
51 * transaction.
52 */
53typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
54 ReorderBufferTXN *txn);
55
56/*
57 * Callback for every individual change in a successful transaction.
58 */
59typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
60 ReorderBufferTXN *txn,
61 Relation relation,
62 ReorderBufferChange *change);
63
64/*
65 * Callback for every TRUNCATE in a successful transaction.
66 */
67typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
68 ReorderBufferTXN *txn,
69 int nrelations,
70 Relation relations[],
71 ReorderBufferChange *change);
72
73/*
74 * Called for every (explicit or implicit) COMMIT of a successful transaction.
75 */
76typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
77 ReorderBufferTXN *txn,
78 XLogRecPtr commit_lsn);
79
80/*
81 * Called for the generic logical decoding messages.
82 */
83typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,
84 ReorderBufferTXN *txn,
85 XLogRecPtr message_lsn,
86 bool transactional,
87 const char *prefix,
88 Size message_size,
89 const char *message);
90
91/*
92 * Filter changes by origin.
93 */
94typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx,
95 RepOriginId origin_id);
96
97/*
98 * Called to shutdown an output plugin.
99 */
100typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);
101
102/*
103 * Output plugin callbacks
104 */
105typedef struct OutputPluginCallbacks
106{
107 LogicalDecodeStartupCB startup_cb;
108 LogicalDecodeBeginCB begin_cb;
109 LogicalDecodeChangeCB change_cb;
110 LogicalDecodeTruncateCB truncate_cb;
111 LogicalDecodeCommitCB commit_cb;
112 LogicalDecodeMessageCB message_cb;
113 LogicalDecodeFilterByOriginCB filter_by_origin_cb;
114 LogicalDecodeShutdownCB shutdown_cb;
115} OutputPluginCallbacks;
116
117/* Functions in replication/logical/logical.c */
118extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
119extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
120extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx);
121
122#endif /* OUTPUT_PLUGIN_H */
123