]> granicus.if.org Git - postgresql/blob - src/include/replication/output_plugin.h
Centralize definition of integer limits.
[postgresql] / src / include / replication / output_plugin.h
1 /*-------------------------------------------------------------------------
2  * output_plugin.h
3  *         PostgreSQL Logical Decode Plugin Interface
4  *
5  * Copyright (c) 2012-2015, PostgreSQL Global Development Group
6  *
7  *-------------------------------------------------------------------------
8  */
9 #ifndef OUTPUT_PLUGIN_H
10 #define OUTPUT_PLUGIN_H
11
12 #include "replication/reorderbuffer.h"
13
14 struct LogicalDecodingContext;
15 struct OutputPluginCallbacks;
16
17 typedef 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  */
26 typedef struct OutputPluginOptions
27 {
28         OutputPluginOutputType output_type;
29 } OutputPluginOptions;
30
31 /*
32  * Type of the shared library symbol _PG_output_plugin_init that is looked up
33  * when loading an output plugin shared library.
34  */
35 typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
36
37 /*
38  * Callback that gets called in a user-defined plugin. ctx->private_data can
39  * be set to some private data.
40  *
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".
43  */
44 typedef void (*LogicalDecodeStartupCB) (
45                                                                                   struct LogicalDecodingContext *ctx,
46                                                                                                 OutputPluginOptions *options,
47                                                                                                         bool is_init
48 );
49
50 /*
51  * Callback called for every (explicit or implicit) BEGIN of a successful
52  * transaction.
53  */
54 typedef void (*LogicalDecodeBeginCB) (
55                                                                                          struct LogicalDecodingContext *,
56                                                                                                   ReorderBufferTXN *txn);
57
58 /*
59  * Callback for every individual change in a successful transaction.
60  */
61 typedef void (*LogicalDecodeChangeCB) (
62                                                                                          struct LogicalDecodingContext *,
63                                                                                                    ReorderBufferTXN *txn,
64                                                                                                    Relation relation,
65                                                                                                    ReorderBufferChange *change
66 );
67
68 /*
69  * Called for every (explicit or implicit) COMMIT of a successful transaction.
70  */
71 typedef void (*LogicalDecodeCommitCB) (
72                                                                                          struct LogicalDecodingContext *,
73                                                                                                    ReorderBufferTXN *txn,
74                                                                                                    XLogRecPtr commit_lsn);
75
76 /*
77  * Called to shutdown an output plugin.
78  */
79 typedef void (*LogicalDecodeShutdownCB) (
80                                                                                           struct LogicalDecodingContext *
81 );
82
83 /*
84  * Output plugin callbacks
85  */
86 typedef struct OutputPluginCallbacks
87 {
88         LogicalDecodeStartupCB startup_cb;
89         LogicalDecodeBeginCB begin_cb;
90         LogicalDecodeChangeCB change_cb;
91         LogicalDecodeCommitCB commit_cb;
92         LogicalDecodeShutdownCB shutdown_cb;
93 } OutputPluginCallbacks;
94
95 void            OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
96 void            OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
97
98 #endif   /* OUTPUT_PLUGIN_H */