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 and the greatest version
23  * we can support. LOGICALREP_PROTO_MIN_VERSION_NUM is the oldest version we
24  * have backwards compatibility for. The client requests protocol version at
25  * connect time.
26  */
27 #define LOGICALREP_PROTO_MIN_VERSION_NUM 1
28 #define LOGICALREP_PROTO_VERSION_NUM 1
29 
30 /* Tuple coming via logical replication. */
31 typedef struct LogicalRepTupleData
32 {
33  /* column values in text format, or NULL for a null value: */
35  /* markers for changed/unchanged column values: */
38 
40 
41 /* Relation information */
42 typedef struct LogicalRepRelation
43 {
44  /* Info coming from the remote side. */
45  LogicalRepRelId remoteid; /* unique id of the relation */
46  char *nspname; /* schema name */
47  char *relname; /* relation name */
48  int natts; /* number of columns */
49  char **attnames; /* column names */
50  Oid *atttyps; /* column types */
51  char replident; /* replica identity */
52  char relkind; /* remote relation kind */
53  Bitmapset *attkeys; /* Bitmap of key columns */
55 
56 /* Type mapping info */
57 typedef struct LogicalRepTyp
58 {
59  Oid remoteid; /* unique id of the remote type */
60  char *nspname; /* schema name of remote type */
61  char *typname; /* name of the remote type */
63 
64 /* Transaction info */
65 typedef struct LogicalRepBeginData
66 {
71 
72 typedef struct LogicalRepCommitData
73 {
78 
80 extern void logicalrep_read_begin(StringInfo in,
81  LogicalRepBeginData *begin_data);
83  XLogRecPtr commit_lsn);
84 extern void logicalrep_read_commit(StringInfo in,
85  LogicalRepCommitData *commit_data);
86 extern void logicalrep_write_origin(StringInfo out, const char *origin,
87  XLogRecPtr origin_lsn);
88 extern char *logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn);
89 extern void logicalrep_write_insert(StringInfo out, Relation rel,
90  HeapTuple newtuple);
92 extern void logicalrep_write_update(StringInfo out, Relation rel, HeapTuple oldtuple,
93  HeapTuple newtuple);
95  bool *has_oldtuple, LogicalRepTupleData *oldtup,
96  LogicalRepTupleData *newtup);
97 extern void logicalrep_write_delete(StringInfo out, Relation rel,
98  HeapTuple oldtuple);
100  LogicalRepTupleData *oldtup);
101 extern void logicalrep_write_truncate(StringInfo out, int nrelids, Oid relids[],
102  bool cascade, bool restart_seqs);
104  bool *cascade, bool *restart_seqs);
105 extern void logicalrep_write_rel(StringInfo out, Relation rel);
107 extern void logicalrep_write_typ(StringInfo out, Oid typoid);
108 extern void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp);
109 
110 #endif /* LOGICAL_PROTO_H */
TransactionId xid
Definition: logicalproto.h:69
char * typname
Definition: logicalproto.h:61
void logicalrep_write_update(StringInfo out, Relation rel, HeapTuple oldtuple, HeapTuple newtuple)
Definition: proto.c:181
uint32 TransactionId
Definition: c.h:513
#define MaxTupleAttributeNumber
Definition: htup_details.h:33
void logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: proto.c:75
int64 TimestampTz
Definition: timestamp.h:39
void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp)
Definition: proto.c:427
unsigned int Oid
Definition: postgres_ext.h:31
void logicalrep_write_rel(StringInfo out, Relation rel)
Definition: proto.c:350
void logicalrep_write_typ(StringInfo out, Oid typoid)
Definition: proto.c:400
Bitmapset * attkeys
Definition: logicalproto.h:53
LogicalRepRelId remoteid
Definition: logicalproto.h:45
struct LogicalRepCommitData LogicalRepCommitData
List * logicalrep_read_truncate(StringInfo in, bool *cascade, bool *restart_seqs)
Definition: proto.c:325
void logicalrep_write_origin(StringInfo out, const char *origin, XLogRecPtr origin_lsn)
Definition: proto.c:113
char * logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn)
Definition: proto.c:129
bool changed[MaxTupleAttributeNumber]
Definition: logicalproto.h:36
unsigned int uint32
Definition: c.h:367
LogicalRepRelation * logicalrep_read_rel(StringInfo in)
Definition: proto.c:375
struct LogicalRepTyp LogicalRepTyp
struct LogicalRepRelation LogicalRepRelation
XLogRecPtr final_lsn
Definition: logicalproto.h:67
void logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn)
Definition: proto.c:46
LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup)
Definition: proto.c:159
struct LogicalRepTupleData LogicalRepTupleData
void logicalrep_write_truncate(StringInfo out, int nrelids, Oid relids[], bool cascade, bool restart_seqs)
Definition: proto.c:298
struct LogicalRepBeginData LogicalRepBeginData
void logicalrep_write_delete(StringInfo out, Relation rel, HeapTuple oldtuple)
Definition: proto.c:251
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void logicalrep_read_commit(StringInfo in, LogicalRepCommitData *commit_data)
Definition: proto.c:95
LogicalRepRelId logicalrep_read_update(StringInfo in, bool *has_oldtuple, LogicalRepTupleData *oldtup, LogicalRepTupleData *newtup)
Definition: proto.c:210
char * values[MaxTupleAttributeNumber]
Definition: logicalproto.h:34
void logicalrep_read_begin(StringInfo in, LogicalRepBeginData *begin_data)
Definition: proto.c:60
LogicalRepRelId logicalrep_read_delete(StringInfo in, LogicalRepTupleData *oldtup)
Definition: proto.c:276
TimestampTz committime
Definition: logicalproto.h:68
XLogRecPtr commit_lsn
Definition: logicalproto.h:74
Definition: pg_list.h:50
TimestampTz committime
Definition: logicalproto.h:76
char * nspname
Definition: logicalproto.h:60
uint32 LogicalRepRelId
Definition: logicalproto.h:39
void logicalrep_write_insert(StringInfo out, Relation rel, HeapTuple newtuple)
Definition: proto.c:142