1/*-------------------------------------------------------------------------
2 *
3 * logicalproto.h
4 * logical replication protocol
5 *
6 * Copyright (c) 2015-2019, 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
16#include "replication/reorderbuffer.h"
17#include "utils/rel.h"
18
19/*
20 * Protocol capabilities
21 *
22 * LOGICAL_PROTO_VERSION_NUM is our native protocol and the greatest version
23 * we can support. PGLOGICAL_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. */
31typedef struct LogicalRepTupleData
32{
33 /* column values in text format, or NULL for a null value: */
34 char *values[MaxTupleAttributeNumber];
35 /* markers for changed/unchanged column values: */
36 bool changed[MaxTupleAttributeNumber];
37} LogicalRepTupleData;
38
39typedef uint32 LogicalRepRelId;
40
41/* Relation information */
42typedef 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 Bitmapset *attkeys; /* Bitmap of key columns */
53} LogicalRepRelation;
54
55/* Type mapping info */
56typedef struct LogicalRepTyp
57{
58 Oid remoteid; /* unique id of the remote type */
59 char *nspname; /* schema name of remote type */
60 char *typname; /* name of the remote type */
61} LogicalRepTyp;
62
63/* Transaction info */
64typedef struct LogicalRepBeginData
65{
66 XLogRecPtr final_lsn;
67 TimestampTz committime;
68 TransactionId xid;
69} LogicalRepBeginData;
70
71typedef struct LogicalRepCommitData
72{
73 XLogRecPtr commit_lsn;
74 XLogRecPtr end_lsn;
75 TimestampTz committime;
76} LogicalRepCommitData;
77
78extern void logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn);
79extern void logicalrep_read_begin(StringInfo in,
80 LogicalRepBeginData *begin_data);
81extern void logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn,
82 XLogRecPtr commit_lsn);
83extern void logicalrep_read_commit(StringInfo in,
84 LogicalRepCommitData *commit_data);
85extern void logicalrep_write_origin(StringInfo out, const char *origin,
86 XLogRecPtr origin_lsn);
87extern char *logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn);
88extern void logicalrep_write_insert(StringInfo out, Relation rel,
89 HeapTuple newtuple);
90extern LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup);
91extern void logicalrep_write_update(StringInfo out, Relation rel, HeapTuple oldtuple,
92 HeapTuple newtuple);
93extern LogicalRepRelId logicalrep_read_update(StringInfo in,
94 bool *has_oldtuple, LogicalRepTupleData *oldtup,
95 LogicalRepTupleData *newtup);
96extern void logicalrep_write_delete(StringInfo out, Relation rel,
97 HeapTuple oldtuple);
98extern LogicalRepRelId logicalrep_read_delete(StringInfo in,
99 LogicalRepTupleData *oldtup);
100extern void logicalrep_write_truncate(StringInfo out, int nrelids, Oid relids[],
101 bool cascade, bool restart_seqs);
102extern List *logicalrep_read_truncate(StringInfo in,
103 bool *cascade, bool *restart_seqs);
104extern void logicalrep_write_rel(StringInfo out, Relation rel);
105extern LogicalRepRelation *logicalrep_read_rel(StringInfo in);
106extern void logicalrep_write_typ(StringInfo out, Oid typoid);
107extern void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp);
108
109#endif /* LOGICALREP_PROTO_H */
110