1 /*------------------------------------------------------------------------- 2 * output_plugin.h 3 * PostgreSQL Logical Decode Plugin Interface 4 * 5 * Copyright (c) 2012-2016, 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) (struct LogicalDecodingContext *ctx, 45 OutputPluginOptions *options, 46 bool is_init); 47 48 /* 49 * Callback called for every (explicit or implicit) BEGIN of a successful 50 * transaction. 51 */ 52 typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx, 53 ReorderBufferTXN *txn); 54 55 /* 56 * Callback for every individual change in a successful transaction. 57 */ 58 typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx, 59 ReorderBufferTXN *txn, 60 Relation relation, 61 ReorderBufferChange *change); 62 63 /* 64 * Called for every (explicit or implicit) COMMIT of a successful transaction. 65 */ 66 typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx, 67 ReorderBufferTXN *txn, 68 XLogRecPtr commit_lsn); 69 70 /* 71 * Called for the generic logical decoding messages. 72 */ 73 typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx, 74 ReorderBufferTXN *txn, 75 XLogRecPtr message_lsn, 76 bool transactional, 77 const char *prefix, 78 Size message_size, 79 const char *message); 80 81 /* 82 * Filter changes by origin. 83 */ 84 typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx, 85 RepOriginId origin_id); 86 87 /* 88 * Called to shutdown an output plugin. 89 */ 90 typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx); 91 92 /* 93 * Output plugin callbacks 94 */ 95 typedef struct OutputPluginCallbacks 96 { 97 LogicalDecodeStartupCB startup_cb; 98 LogicalDecodeBeginCB begin_cb; 99 LogicalDecodeChangeCB change_cb; 100 LogicalDecodeCommitCB commit_cb; 101 LogicalDecodeMessageCB message_cb; 102 LogicalDecodeFilterByOriginCB filter_by_origin_cb; 103 LogicalDecodeShutdownCB shutdown_cb; 104 } OutputPluginCallbacks; 105 106 /* Functions in replication/logical/logical.c */ 107 extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write); 108 extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write); 109 110 #endif /* OUTPUT_PLUGIN_H */ 111