summaryrefslogtreecommitdiff
path: root/src/include/replication
diff options
context:
space:
mode:
authorTom Lane2020-07-18 16:44:51 +0000
committerTom Lane2020-07-18 16:44:51 +0000
commit9de77b5453130242654ff0b30a551c9c862ed661 (patch)
tree9c48ed25ee4711934006078939a834186c8e9727 /src/include/replication
parent9add405014f8e47e038af7124528b7601249a2ac (diff)
Allow logical replication to transfer data in binary format.
This patch adds a "binary" option to CREATE/ALTER SUBSCRIPTION. When that's set, the publisher will send data using the data type's typsend function if any, rather than typoutput. This is generally faster, if slightly less robust. As committed, we won't try to transfer user-defined array or composite types in binary, for fear that type OIDs won't match at the subscriber. This might be changed later, but it seems like fit material for a follow-on patch. Dave Cramer, reviewed by Daniel Gustafsson, Petr Jelinek, and others; adjusted some by me Discussion: https://postgr.es/m/CADK3HH+R3xMn=8t3Ct+uD+qJ1KD=Hbif5NFMJ+d5DkoCzp6Vgw@mail.gmail.com
Diffstat (limited to 'src/include/replication')
-rw-r--r--src/include/replication/logicalproto.h21
-rw-r--r--src/include/replication/pgoutput.h4
-rw-r--r--src/include/replication/walreceiver.h1
3 files changed, 17 insertions, 9 deletions
diff --git a/src/include/replication/logicalproto.h b/src/include/replication/logicalproto.h
index 4860561be9f..287288ab415 100644
--- a/src/include/replication/logicalproto.h
+++ b/src/include/replication/logicalproto.h
@@ -30,12 +30,19 @@
/* Tuple coming via logical replication. */
typedef struct LogicalRepTupleData
{
- /* column values in text format, or NULL for a null value: */
- char *values[MaxTupleAttributeNumber];
- /* markers for changed/unchanged column values: */
- bool changed[MaxTupleAttributeNumber];
+ /* Array of StringInfos, one per column; some may be unused */
+ StringInfoData *colvalues;
+ /* Array of markers for null/unchanged/text/binary, one per column */
+ char *colstatus;
} LogicalRepTupleData;
+/* Possible values for LogicalRepTupleData.colstatus[colnum] */
+/* These values are also used in the on-the-wire protocol */
+#define LOGICALREP_COLUMN_NULL 'n'
+#define LOGICALREP_COLUMN_UNCHANGED 'u'
+#define LOGICALREP_COLUMN_TEXT 't'
+#define LOGICALREP_COLUMN_BINARY 'b' /* added in PG14 */
+
typedef uint32 LogicalRepRelId;
/* Relation information */
@@ -87,15 +94,15 @@ extern void logicalrep_write_origin(StringInfo out, const char *origin,
XLogRecPtr origin_lsn);
extern char *logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn);
extern void logicalrep_write_insert(StringInfo out, Relation rel,
- HeapTuple newtuple);
+ HeapTuple newtuple, bool binary);
extern LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup);
extern void logicalrep_write_update(StringInfo out, Relation rel, HeapTuple oldtuple,
- HeapTuple newtuple);
+ HeapTuple newtuple, bool binary);
extern LogicalRepRelId logicalrep_read_update(StringInfo in,
bool *has_oldtuple, LogicalRepTupleData *oldtup,
LogicalRepTupleData *newtup);
extern void logicalrep_write_delete(StringInfo out, Relation rel,
- HeapTuple oldtuple);
+ HeapTuple oldtuple, bool binary);
extern LogicalRepRelId logicalrep_read_delete(StringInfo in,
LogicalRepTupleData *oldtup);
extern void logicalrep_write_truncate(StringInfo out, int nrelids, Oid relids[],
diff --git a/src/include/replication/pgoutput.h b/src/include/replication/pgoutput.h
index 2e8e9daf445..a8c676ed23b 100644
--- a/src/include/replication/pgoutput.h
+++ b/src/include/replication/pgoutput.h
@@ -20,11 +20,11 @@ typedef struct PGOutputData
MemoryContext context; /* private memory context for transient
* allocations */
- /* client info */
+ /* client-supplied info: */
uint32 protocol_version;
-
List *publication_names;
List *publications;
+ bool binary;
} PGOutputData;
#endif /* PGOUTPUT_H */
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index c75dcebea0c..c2d5dbee549 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -177,6 +177,7 @@ typedef struct
{
uint32 proto_version; /* Logical protocol version */
List *publication_names; /* String list of publications */
+ bool binary; /* Ask publisher to use binary */
} logical;
} proto;
} WalRcvStreamOptions;