PostgreSQL Source Code  git master
logicalproto.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * logicalproto.h
4  * logical replication protocol
5  *
6  * Copyright (c) 2015-2020, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/include/replication/logicalproto.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef LOGICAL_PROTO_H
14 #define LOGICAL_PROTO_H
15 
17 #include "utils/rel.h"
18 
19 /*
20  * Protocol capabilities
21  *
22  * LOGICALREP_PROTO_VERSION_NUM is our native protocol.
23  * LOGICALREP_PROTO_MAX_VERSION_NUM is the greatest version we can support.
24  * LOGICALREP_PROTO_MIN_VERSION_NUM is the oldest version we
25  * have backwards compatibility for. The client requests protocol version at
26  * connect time.
27  *
28  * LOGICALREP_PROTO_STREAM_VERSION_NUM is the minimum protocol version with
29  * support for streaming large transactions.
30  */
31 #define LOGICALREP_PROTO_MIN_VERSION_NUM 1
32 #define LOGICALREP_PROTO_VERSION_NUM 1
33 #define LOGICALREP_PROTO_STREAM_VERSION_NUM 2
34 #define LOGICALREP_PROTO_MAX_VERSION_NUM LOGICALREP_PROTO_STREAM_VERSION_NUM
35 
36 /*
37  * This struct stores a tuple received via logical replication.
38  * Keep in mind that the columns correspond to the *remote* table.
39  */
40 typedef struct LogicalRepTupleData
41 {
42  /* Array of StringInfos, one per column; some may be unused */
44  /* Array of markers for null/unchanged/text/binary, one per column */
45  char *colstatus;
46  /* Length of above arrays */
47  int ncols;
49 
50 /* Possible values for LogicalRepTupleData.colstatus[colnum] */
51 /* These values are also used in the on-the-wire protocol */
52 #define LOGICALREP_COLUMN_NULL 'n'
53 #define LOGICALREP_COLUMN_UNCHANGED 'u'
54 #define LOGICALREP_COLUMN_TEXT 't'
55 #define LOGICALREP_COLUMN_BINARY 'b' /* added in PG14 */
56 
58 
59 /* Relation information */
60 typedef struct LogicalRepRelation
61 {
62  /* Info coming from the remote side. */
63  LogicalRepRelId remoteid; /* unique id of the relation */
64  char *nspname; /* schema name */
65  char *relname; /* relation name */
66  int natts; /* number of columns */
67  char **attnames; /* column names */
68  Oid *atttyps; /* column types */
69  char replident; /* replica identity */
70  char relkind; /* remote relation kind */
71  Bitmapset *attkeys; /* Bitmap of key columns */
73 
74 /* Type mapping info */
75 typedef struct LogicalRepTyp
76 {
77  Oid remoteid; /* unique id of the remote type */
78  char *nspname; /* schema name of remote type */
79  char *typname; /* name of the remote type */
81 
82 /* Transaction info */
83 typedef struct LogicalRepBeginData
84 {
89 
90 typedef struct LogicalRepCommitData
91 {
96 
98 extern void logicalrep_read_begin(StringInfo in,
99  LogicalRepBeginData *begin_data);
101  XLogRecPtr commit_lsn);
102 extern void logicalrep_read_commit(StringInfo in,
103  LogicalRepCommitData *commit_data);
104 extern void logicalrep_write_origin(StringInfo out, const char *origin,
105  XLogRecPtr origin_lsn);
106 extern char *logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn);
108  Relation rel, HeapTuple newtuple,
109  bool binary);
112  Relation rel, HeapTuple oldtuple,
113  HeapTuple newtuple, bool binary);
115  bool *has_oldtuple, LogicalRepTupleData *oldtup,
116  LogicalRepTupleData *newtup);
118  Relation rel, HeapTuple oldtuple,
119  bool binary);
121  LogicalRepTupleData *oldtup);
123  int nrelids, Oid relids[],
124  bool cascade, bool restart_seqs);
126  bool *cascade, bool *restart_seqs);
127 extern void logicalrep_write_rel(StringInfo out, TransactionId xid,
128  Relation rel);
130 extern void logicalrep_write_typ(StringInfo out, TransactionId xid,
131  Oid typoid);
132 extern void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp);
134  bool first_segment);
136  bool *first_segment);
139  XLogRecPtr commit_lsn);
141  LogicalRepCommitData *commit_data);
143  TransactionId subxid);
145  TransactionId *subxid);
146 
147 #endif /* LOGICAL_PROTO_H */
TransactionId xid
Definition: logicalproto.h:87
void logicalrep_write_update(StringInfo out, TransactionId xid, Relation rel, HeapTuple oldtuple, HeapTuple newtuple, bool binary)
Definition: proto.c:185
char * typname
Definition: logicalproto.h:79
uint32 TransactionId
Definition: c.h:521
void logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: proto.c:74
int64 TimestampTz
Definition: timestamp.h:39
TransactionId logicalrep_read_stream_commit(StringInfo out, LogicalRepCommitData *commit_data)
Definition: proto.c:823
void logicalrep_write_stream_stop(StringInfo out)
Definition: proto.c:789
void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp)
Definition: proto.c:453
StringInfoData * colvalues
Definition: logicalproto.h:43
void logicalrep_write_stream_commit(StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: proto.c:798
unsigned int Oid
Definition: postgres_ext.h:31
Bitmapset * attkeys
Definition: logicalproto.h:71
void logicalrep_write_rel(StringInfo out, TransactionId xid, Relation rel)
Definition: proto.c:368
LogicalRepRelId remoteid
Definition: logicalproto.h:63
struct LogicalRepCommitData LogicalRepCommitData
List * logicalrep_read_truncate(StringInfo in, bool *cascade, bool *restart_seqs)
Definition: proto.c:343
void logicalrep_write_origin(StringInfo out, const char *origin, XLogRecPtr origin_lsn)
Definition: proto.c:112
char * logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn)
Definition: proto.c:128
void logicalrep_write_stream_start(StringInfo out, TransactionId xid, bool first_segment)
Definition: proto.c:755
void logicalrep_write_typ(StringInfo out, TransactionId xid, Oid typoid)
Definition: proto.c:422
unsigned int uint32
Definition: c.h:375
LogicalRepRelation * logicalrep_read_rel(StringInfo in)
Definition: proto.c:397
struct LogicalRepTyp LogicalRepTyp
struct LogicalRepRelation LogicalRepRelation
XLogRecPtr final_lsn
Definition: logicalproto.h:85
void logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn)
Definition: proto.c:45
LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup)
Definition: proto.c:163
struct LogicalRepTupleData LogicalRepTupleData
struct LogicalRepBeginData LogicalRepBeginData
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void logicalrep_write_truncate(StringInfo out, TransactionId xid, int nrelids, Oid relids[], bool cascade, bool restart_seqs)
Definition: proto.c:311
void logicalrep_write_delete(StringInfo out, TransactionId xid, Relation rel, HeapTuple oldtuple, bool binary)
Definition: proto.c:259
void logicalrep_read_commit(StringInfo in, LogicalRepCommitData *commit_data)
Definition: proto.c:94
TransactionId logicalrep_read_stream_start(StringInfo in, bool *first_segment)
Definition: proto.c:773
LogicalRepRelId logicalrep_read_update(StringInfo in, bool *has_oldtuple, LogicalRepTupleData *oldtup, LogicalRepTupleData *newtup)
Definition: proto.c:218
void logicalrep_write_stream_abort(StringInfo out, TransactionId xid, TransactionId subxid)
Definition: proto.c:849
void logicalrep_read_begin(StringInfo in, LogicalRepBeginData *begin_data)
Definition: proto.c:59
LogicalRepRelId logicalrep_read_delete(StringInfo in, LogicalRepTupleData *oldtup)
Definition: proto.c:289
void logicalrep_write_insert(StringInfo out, TransactionId xid, Relation rel, HeapTuple newtuple, bool binary)
Definition: proto.c:141
TimestampTz committime
Definition: logicalproto.h:86
XLogRecPtr commit_lsn
Definition: logicalproto.h:92
Definition: pg_list.h:50
TimestampTz committime
Definition: logicalproto.h:94
char * nspname
Definition: logicalproto.h:78
uint32 LogicalRepRelId
Definition: logicalproto.h:57
void logicalrep_read_stream_abort(StringInfo in, TransactionId *xid, TransactionId *subxid)
Definition: proto.c:865