PostgreSQL Source Code  git master
proto.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * proto.c
4  * logical replication protocol functions
5  *
6  * Copyright (c) 2015-2020, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/backend/replication/logical/proto.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "postgres.h"
14 
15 #include "access/sysattr.h"
16 #include "catalog/pg_namespace.h"
17 #include "catalog/pg_type.h"
18 #include "libpq/pqformat.h"
20 #include "utils/lsyscache.h"
21 #include "utils/syscache.h"
22 
23 /*
24  * Protocol message flags.
25  */
26 #define LOGICALREP_IS_REPLICA_IDENTITY 1
27 
28 #define TRUNCATE_CASCADE (1<<0)
29 #define TRUNCATE_RESTART_SEQS (1<<1)
30 
31 static void logicalrep_write_attrs(StringInfo out, Relation rel);
32 static void logicalrep_write_tuple(StringInfo out, Relation rel,
33  HeapTuple tuple, bool binary);
34 
37 
38 static void logicalrep_write_namespace(StringInfo out, Oid nspid);
39 static const char *logicalrep_read_namespace(StringInfo in);
40 
41 /*
42  * Write BEGIN to the output stream.
43  */
44 void
46 {
47  pq_sendbyte(out, 'B'); /* BEGIN */
48 
49  /* fixed fields */
50  pq_sendint64(out, txn->final_lsn);
51  pq_sendint64(out, txn->commit_time);
52  pq_sendint32(out, txn->xid);
53 }
54 
55 /*
56  * Read transaction BEGIN from the stream.
57  */
58 void
60 {
61  /* read fields */
62  begin_data->final_lsn = pq_getmsgint64(in);
63  if (begin_data->final_lsn == InvalidXLogRecPtr)
64  elog(ERROR, "final_lsn not set in begin message");
65  begin_data->committime = pq_getmsgint64(in);
66  begin_data->xid = pq_getmsgint(in, 4);
67 }
68 
69 
70 /*
71  * Write COMMIT to the output stream.
72  */
73 void
75  XLogRecPtr commit_lsn)
76 {
77  uint8 flags = 0;
78 
79  pq_sendbyte(out, 'C'); /* sending COMMIT */
80 
81  /* send the flags field (unused for now) */
82  pq_sendbyte(out, flags);
83 
84  /* send fields */
85  pq_sendint64(out, commit_lsn);
86  pq_sendint64(out, txn->end_lsn);
87  pq_sendint64(out, txn->commit_time);
88 }
89 
90 /*
91  * Read transaction COMMIT from the stream.
92  */
93 void
95 {
96  /* read flags (unused for now) */
97  uint8 flags = pq_getmsgbyte(in);
98 
99  if (flags != 0)
100  elog(ERROR, "unrecognized flags %u in commit message", flags);
101 
102  /* read fields */
103  commit_data->commit_lsn = pq_getmsgint64(in);
104  commit_data->end_lsn = pq_getmsgint64(in);
105  commit_data->committime = pq_getmsgint64(in);
106 }
107 
108 /*
109  * Write ORIGIN to the output stream.
110  */
111 void
112 logicalrep_write_origin(StringInfo out, const char *origin,
113  XLogRecPtr origin_lsn)
114 {
115  pq_sendbyte(out, 'O'); /* ORIGIN */
116 
117  /* fixed fields */
118  pq_sendint64(out, origin_lsn);
119 
120  /* origin string */
121  pq_sendstring(out, origin);
122 }
123 
124 /*
125  * Read ORIGIN from the output stream.
126  */
127 char *
129 {
130  /* fixed fields */
131  *origin_lsn = pq_getmsgint64(in);
132 
133  /* return origin */
134  return pstrdup(pq_getmsgstring(in));
135 }
136 
137 /*
138  * Write INSERT to the output stream.
139  */
140 void
142  HeapTuple newtuple, bool binary)
143 {
144  pq_sendbyte(out, 'I'); /* action INSERT */
145 
146  /* transaction ID (if not valid, we're not streaming) */
147  if (TransactionIdIsValid(xid))
148  pq_sendint32(out, xid);
149 
150  /* use Oid as relation identifier */
151  pq_sendint32(out, RelationGetRelid(rel));
152 
153  pq_sendbyte(out, 'N'); /* new tuple follows */
154  logicalrep_write_tuple(out, rel, newtuple, binary);
155 }
156 
157 /*
158  * Read INSERT from stream.
159  *
160  * Fills the new tuple.
161  */
164 {
165  char action;
166  LogicalRepRelId relid;
167 
168  /* read the relation id */
169  relid = pq_getmsgint(in, 4);
170 
171  action = pq_getmsgbyte(in);
172  if (action != 'N')
173  elog(ERROR, "expected new tuple but got %d",
174  action);
175 
176  logicalrep_read_tuple(in, newtup);
177 
178  return relid;
179 }
180 
181 /*
182  * Write UPDATE to the output stream.
183  */
184 void
186  HeapTuple oldtuple, HeapTuple newtuple, bool binary)
187 {
188  pq_sendbyte(out, 'U'); /* action UPDATE */
189 
190  Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
191  rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
192  rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
193 
194  /* transaction ID (if not valid, we're not streaming) */
195  if (TransactionIdIsValid(xid))
196  pq_sendint32(out, xid);
197 
198  /* use Oid as relation identifier */
199  pq_sendint32(out, RelationGetRelid(rel));
200 
201  if (oldtuple != NULL)
202  {
203  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
204  pq_sendbyte(out, 'O'); /* old tuple follows */
205  else
206  pq_sendbyte(out, 'K'); /* old key follows */
207  logicalrep_write_tuple(out, rel, oldtuple, binary);
208  }
209 
210  pq_sendbyte(out, 'N'); /* new tuple follows */
211  logicalrep_write_tuple(out, rel, newtuple, binary);
212 }
213 
214 /*
215  * Read UPDATE from stream.
216  */
218 logicalrep_read_update(StringInfo in, bool *has_oldtuple,
219  LogicalRepTupleData *oldtup,
220  LogicalRepTupleData *newtup)
221 {
222  char action;
223  LogicalRepRelId relid;
224 
225  /* read the relation id */
226  relid = pq_getmsgint(in, 4);
227 
228  /* read and verify action */
229  action = pq_getmsgbyte(in);
230  if (action != 'K' && action != 'O' && action != 'N')
231  elog(ERROR, "expected action 'N', 'O' or 'K', got %c",
232  action);
233 
234  /* check for old tuple */
235  if (action == 'K' || action == 'O')
236  {
237  logicalrep_read_tuple(in, oldtup);
238  *has_oldtuple = true;
239 
240  action = pq_getmsgbyte(in);
241  }
242  else
243  *has_oldtuple = false;
244 
245  /* check for new tuple */
246  if (action != 'N')
247  elog(ERROR, "expected action 'N', got %c",
248  action);
249 
250  logicalrep_read_tuple(in, newtup);
251 
252  return relid;
253 }
254 
255 /*
256  * Write DELETE to the output stream.
257  */
258 void
260  HeapTuple oldtuple, bool binary)
261 {
262  Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
263  rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
264  rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
265 
266  pq_sendbyte(out, 'D'); /* action DELETE */
267 
268  /* transaction ID (if not valid, we're not streaming) */
269  if (TransactionIdIsValid(xid))
270  pq_sendint32(out, xid);
271 
272  /* use Oid as relation identifier */
273  pq_sendint32(out, RelationGetRelid(rel));
274 
275  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
276  pq_sendbyte(out, 'O'); /* old tuple follows */
277  else
278  pq_sendbyte(out, 'K'); /* old key follows */
279 
280  logicalrep_write_tuple(out, rel, oldtuple, binary);
281 }
282 
283 /*
284  * Read DELETE from stream.
285  *
286  * Fills the old tuple.
287  */
290 {
291  char action;
292  LogicalRepRelId relid;
293 
294  /* read the relation id */
295  relid = pq_getmsgint(in, 4);
296 
297  /* read and verify action */
298  action = pq_getmsgbyte(in);
299  if (action != 'K' && action != 'O')
300  elog(ERROR, "expected action 'O' or 'K', got %c", action);
301 
302  logicalrep_read_tuple(in, oldtup);
303 
304  return relid;
305 }
306 
307 /*
308  * Write TRUNCATE to the output stream.
309  */
310 void
312  TransactionId xid,
313  int nrelids,
314  Oid relids[],
315  bool cascade, bool restart_seqs)
316 {
317  int i;
318  uint8 flags = 0;
319 
320  pq_sendbyte(out, 'T'); /* action TRUNCATE */
321 
322  /* transaction ID (if not valid, we're not streaming) */
323  if (TransactionIdIsValid(xid))
324  pq_sendint32(out, xid);
325 
326  pq_sendint32(out, nrelids);
327 
328  /* encode and send truncate flags */
329  if (cascade)
330  flags |= TRUNCATE_CASCADE;
331  if (restart_seqs)
332  flags |= TRUNCATE_RESTART_SEQS;
333  pq_sendint8(out, flags);
334 
335  for (i = 0; i < nrelids; i++)
336  pq_sendint32(out, relids[i]);
337 }
338 
339 /*
340  * Read TRUNCATE from stream.
341  */
342 List *
344  bool *cascade, bool *restart_seqs)
345 {
346  int i;
347  int nrelids;
348  List *relids = NIL;
349  uint8 flags;
350 
351  nrelids = pq_getmsgint(in, 4);
352 
353  /* read and decode truncate flags */
354  flags = pq_getmsgint(in, 1);
355  *cascade = (flags & TRUNCATE_CASCADE) > 0;
356  *restart_seqs = (flags & TRUNCATE_RESTART_SEQS) > 0;
357 
358  for (i = 0; i < nrelids; i++)
359  relids = lappend_oid(relids, pq_getmsgint(in, 4));
360 
361  return relids;
362 }
363 
364 /*
365  * Write relation description to the output stream.
366  */
367 void
369 {
370  char *relname;
371 
372  pq_sendbyte(out, 'R'); /* sending RELATION */
373 
374  /* transaction ID (if not valid, we're not streaming) */
375  if (TransactionIdIsValid(xid))
376  pq_sendint32(out, xid);
377 
378  /* use Oid as relation identifier */
379  pq_sendint32(out, RelationGetRelid(rel));
380 
381  /* send qualified relation name */
383  relname = RelationGetRelationName(rel);
384  pq_sendstring(out, relname);
385 
386  /* send replica identity */
387  pq_sendbyte(out, rel->rd_rel->relreplident);
388 
389  /* send the attribute info */
390  logicalrep_write_attrs(out, rel);
391 }
392 
393 /*
394  * Read the relation info from stream and return as LogicalRepRelation.
395  */
398 {
400 
401  rel->remoteid = pq_getmsgint(in, 4);
402 
403  /* Read relation name from stream */
405  rel->relname = pstrdup(pq_getmsgstring(in));
406 
407  /* Read the replica identity. */
408  rel->replident = pq_getmsgbyte(in);
409 
410  /* Get attribute description */
411  logicalrep_read_attrs(in, rel);
412 
413  return rel;
414 }
415 
416 /*
417  * Write type info to the output stream.
418  *
419  * This function will always write base type info.
420  */
421 void
423 {
424  Oid basetypoid = getBaseType(typoid);
425  HeapTuple tup;
426  Form_pg_type typtup;
427 
428  pq_sendbyte(out, 'Y'); /* sending TYPE */
429 
430  /* transaction ID (if not valid, we're not streaming) */
431  if (TransactionIdIsValid(xid))
432  pq_sendint32(out, xid);
433 
434  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(basetypoid));
435  if (!HeapTupleIsValid(tup))
436  elog(ERROR, "cache lookup failed for type %u", basetypoid);
437  typtup = (Form_pg_type) GETSTRUCT(tup);
438 
439  /* use Oid as relation identifier */
440  pq_sendint32(out, typoid);
441 
442  /* send qualified type name */
443  logicalrep_write_namespace(out, typtup->typnamespace);
444  pq_sendstring(out, NameStr(typtup->typname));
445 
446  ReleaseSysCache(tup);
447 }
448 
449 /*
450  * Read type info from the output stream.
451  */
452 void
454 {
455  ltyp->remoteid = pq_getmsgint(in, 4);
456 
457  /* Read type name from stream */
459  ltyp->typname = pstrdup(pq_getmsgstring(in));
460 }
461 
462 /*
463  * Write a tuple to the outputstream, in the most efficient format possible.
464  */
465 static void
467 {
468  TupleDesc desc;
470  bool isnull[MaxTupleAttributeNumber];
471  int i;
472  uint16 nliveatts = 0;
473 
474  desc = RelationGetDescr(rel);
475 
476  for (i = 0; i < desc->natts; i++)
477  {
478  if (TupleDescAttr(desc, i)->attisdropped || TupleDescAttr(desc, i)->attgenerated)
479  continue;
480  nliveatts++;
481  }
482  pq_sendint16(out, nliveatts);
483 
484  /* try to allocate enough memory from the get-go */
485  enlargeStringInfo(out, tuple->t_len +
486  nliveatts * (1 + 4));
487 
488  heap_deform_tuple(tuple, desc, values, isnull);
489 
490  /* Write the values */
491  for (i = 0; i < desc->natts; i++)
492  {
493  HeapTuple typtup;
494  Form_pg_type typclass;
495  Form_pg_attribute att = TupleDescAttr(desc, i);
496  char *outputstr;
497 
498  if (att->attisdropped || att->attgenerated)
499  continue;
500 
501  if (isnull[i])
502  {
504  continue;
505  }
506 
507  if (att->attlen == -1 && VARATT_IS_EXTERNAL_ONDISK(values[i]))
508  {
509  /*
510  * Unchanged toasted datum. (Note that we don't promise to detect
511  * unchanged data in general; this is just a cheap check to avoid
512  * sending large values unnecessarily.)
513  */
515  continue;
516  }
517 
518  typtup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(att->atttypid));
519  if (!HeapTupleIsValid(typtup))
520  elog(ERROR, "cache lookup failed for type %u", att->atttypid);
521  typclass = (Form_pg_type) GETSTRUCT(typtup);
522 
523  /*
524  * Send in binary if requested and type has suitable send function.
525  */
526  if (binary && OidIsValid(typclass->typsend))
527  {
528  bytea *outputbytes;
529  int len;
530 
532  outputbytes = OidSendFunctionCall(typclass->typsend, values[i]);
533  len = VARSIZE(outputbytes) - VARHDRSZ;
534  pq_sendint(out, len, 4); /* length */
535  pq_sendbytes(out, VARDATA(outputbytes), len); /* data */
536  pfree(outputbytes);
537  }
538  else
539  {
541  outputstr = OidOutputFunctionCall(typclass->typoutput, values[i]);
542  pq_sendcountedtext(out, outputstr, strlen(outputstr), false);
543  pfree(outputstr);
544  }
545 
546  ReleaseSysCache(typtup);
547  }
548 }
549 
550 /*
551  * Read tuple in logical replication format from stream.
552  */
553 static void
555 {
556  int i;
557  int natts;
558 
559  /* Get number of attributes */
560  natts = pq_getmsgint(in, 2);
561 
562  /* Allocate space for per-column values; zero out unused StringInfoDatas */
563  tuple->colvalues = (StringInfoData *) palloc0(natts * sizeof(StringInfoData));
564  tuple->colstatus = (char *) palloc(natts * sizeof(char));
565  tuple->ncols = natts;
566 
567  /* Read the data */
568  for (i = 0; i < natts; i++)
569  {
570  char kind;
571  int len;
572  StringInfo value = &tuple->colvalues[i];
573 
574  kind = pq_getmsgbyte(in);
575  tuple->colstatus[i] = kind;
576 
577  switch (kind)
578  {
580  /* nothing more to do */
581  break;
583  /* we don't receive the value of an unchanged column */
584  break;
586  len = pq_getmsgint(in, 4); /* read length */
587 
588  /* and data */
589  value->data = palloc(len + 1);
590  pq_copymsgbytes(in, value->data, len);
591  value->data[len] = '\0';
592  /* make StringInfo fully valid */
593  value->len = len;
594  value->cursor = 0;
595  value->maxlen = len;
596  break;
598  len = pq_getmsgint(in, 4); /* read length */
599 
600  /* and data */
601  value->data = palloc(len + 1);
602  pq_copymsgbytes(in, value->data, len);
603  /* not strictly necessary but per StringInfo practice */
604  value->data[len] = '\0';
605  /* make StringInfo fully valid */
606  value->len = len;
607  value->cursor = 0;
608  value->maxlen = len;
609  break;
610  default:
611  elog(ERROR, "unrecognized data representation type '%c'", kind);
612  }
613  }
614 }
615 
616 /*
617  * Write relation attribute metadata to the stream.
618  */
619 static void
621 {
622  TupleDesc desc;
623  int i;
624  uint16 nliveatts = 0;
625  Bitmapset *idattrs = NULL;
626  bool replidentfull;
627 
628  desc = RelationGetDescr(rel);
629 
630  /* send number of live attributes */
631  for (i = 0; i < desc->natts; i++)
632  {
633  if (TupleDescAttr(desc, i)->attisdropped || TupleDescAttr(desc, i)->attgenerated)
634  continue;
635  nliveatts++;
636  }
637  pq_sendint16(out, nliveatts);
638 
639  /* fetch bitmap of REPLICATION IDENTITY attributes */
640  replidentfull = (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL);
641  if (!replidentfull)
642  idattrs = RelationGetIndexAttrBitmap(rel,
644 
645  /* send the attributes */
646  for (i = 0; i < desc->natts; i++)
647  {
648  Form_pg_attribute att = TupleDescAttr(desc, i);
649  uint8 flags = 0;
650 
651  if (att->attisdropped || att->attgenerated)
652  continue;
653 
654  /* REPLICA IDENTITY FULL means all columns are sent as part of key. */
655  if (replidentfull ||
657  idattrs))
659 
660  pq_sendbyte(out, flags);
661 
662  /* attribute name */
663  pq_sendstring(out, NameStr(att->attname));
664 
665  /* attribute type id */
666  pq_sendint32(out, (int) att->atttypid);
667 
668  /* attribute mode */
669  pq_sendint32(out, att->atttypmod);
670  }
671 
672  bms_free(idattrs);
673 }
674 
675 /*
676  * Read relation attribute metadata from the stream.
677  */
678 static void
680 {
681  int i;
682  int natts;
683  char **attnames;
684  Oid *atttyps;
685  Bitmapset *attkeys = NULL;
686 
687  natts = pq_getmsgint(in, 2);
688  attnames = palloc(natts * sizeof(char *));
689  atttyps = palloc(natts * sizeof(Oid));
690 
691  /* read the attributes */
692  for (i = 0; i < natts; i++)
693  {
694  uint8 flags;
695 
696  /* Check for replica identity column */
697  flags = pq_getmsgbyte(in);
698  if (flags & LOGICALREP_IS_REPLICA_IDENTITY)
699  attkeys = bms_add_member(attkeys, i);
700 
701  /* attribute name */
702  attnames[i] = pstrdup(pq_getmsgstring(in));
703 
704  /* attribute type id */
705  atttyps[i] = (Oid) pq_getmsgint(in, 4);
706 
707  /* we ignore attribute mode for now */
708  (void) pq_getmsgint(in, 4);
709  }
710 
711  rel->attnames = attnames;
712  rel->atttyps = atttyps;
713  rel->attkeys = attkeys;
714  rel->natts = natts;
715 }
716 
717 /*
718  * Write the namespace name or empty string for pg_catalog (to save space).
719  */
720 static void
722 {
723  if (nspid == PG_CATALOG_NAMESPACE)
724  pq_sendbyte(out, '\0');
725  else
726  {
727  char *nspname = get_namespace_name(nspid);
728 
729  if (nspname == NULL)
730  elog(ERROR, "cache lookup failed for namespace %u",
731  nspid);
732 
733  pq_sendstring(out, nspname);
734  }
735 }
736 
737 /*
738  * Read the namespace name while treating empty string as pg_catalog.
739  */
740 static const char *
742 {
743  const char *nspname = pq_getmsgstring(in);
744 
745  if (nspname[0] == '\0')
746  nspname = "pg_catalog";
747 
748  return nspname;
749 }
750 
751 /*
752  * Write the information for the start stream message to the output stream.
753  */
754 void
756  TransactionId xid, bool first_segment)
757 {
758  pq_sendbyte(out, 'S'); /* action STREAM START */
759 
761 
762  /* transaction ID (we're starting to stream, so must be valid) */
763  pq_sendint32(out, xid);
764 
765  /* 1 if this is the first streaming segment for this xid */
766  pq_sendbyte(out, first_segment ? 1 : 0);
767 }
768 
769 /*
770  * Read the information about the start stream message from output stream.
771  */
773 logicalrep_read_stream_start(StringInfo in, bool *first_segment)
774 {
775  TransactionId xid;
776 
777  Assert(first_segment);
778 
779  xid = pq_getmsgint(in, 4);
780  *first_segment = (pq_getmsgbyte(in) == 1);
781 
782  return xid;
783 }
784 
785 /*
786  * Write the stop stream message to the output stream.
787  */
788 void
790 {
791  pq_sendbyte(out, 'E'); /* action STREAM END */
792 }
793 
794 /*
795  * Write STREAM COMMIT to the output stream.
796  */
797 void
799  XLogRecPtr commit_lsn)
800 {
801  uint8 flags = 0;
802 
803  pq_sendbyte(out, 'c'); /* action STREAM COMMIT */
804 
806 
807  /* transaction ID */
808  pq_sendint32(out, txn->xid);
809 
810  /* send the flags field (unused for now) */
811  pq_sendbyte(out, flags);
812 
813  /* send fields */
814  pq_sendint64(out, commit_lsn);
815  pq_sendint64(out, txn->end_lsn);
816  pq_sendint64(out, txn->commit_time);
817 }
818 
819 /*
820  * Read STREAM COMMIT from the output stream.
821  */
824 {
825  TransactionId xid;
826  uint8 flags;
827 
828  xid = pq_getmsgint(in, 4);
829 
830  /* read flags (unused for now) */
831  flags = pq_getmsgbyte(in);
832 
833  if (flags != 0)
834  elog(ERROR, "unrecognized flags %u in commit message", flags);
835 
836  /* read fields */
837  commit_data->commit_lsn = pq_getmsgint64(in);
838  commit_data->end_lsn = pq_getmsgint64(in);
839  commit_data->committime = pq_getmsgint64(in);
840 
841  return xid;
842 }
843 
844 /*
845  * Write STREAM ABORT to the output stream. Note that xid and subxid will be
846  * same for the top-level transaction abort.
847  */
848 void
850  TransactionId subxid)
851 {
852  pq_sendbyte(out, 'A'); /* action STREAM ABORT */
853 
855 
856  /* transaction ID */
857  pq_sendint32(out, xid);
858  pq_sendint32(out, subxid);
859 }
860 
861 /*
862  * Read STREAM ABORT from the output stream.
863  */
864 void
866  TransactionId *subxid)
867 {
868  Assert(xid && subxid);
869 
870  *xid = pq_getmsgint(in, 4);
871  *subxid = pq_getmsgint(in, 4);
872 }
static void logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple, bool binary)
Definition: proto.c:466
#define NIL
Definition: pg_list.h:65
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
TimestampTz commit_time
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:314
TransactionId xid
Definition: logicalproto.h:87
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define VARDATA(PTR)
Definition: postgres.h:302
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
LogicalRepRelId logicalrep_read_delete(StringInfo in, LogicalRepTupleData *oldtup)
Definition: proto.c:289
void logicalrep_write_truncate(StringInfo out, TransactionId xid, int nrelids, Oid relids[], bool cascade, bool restart_seqs)
Definition: proto.c:311
static void pq_sendint(StringInfo buf, uint32 i, int b)
Definition: pqformat.h:172
char * typname
Definition: logicalproto.h:79
uint32 TransactionId
Definition: c.h:521
#define MaxTupleAttributeNumber
Definition: htup_details.h:33
TransactionId logicalrep_read_stream_commit(StringInfo in, LogicalRepCommitData *commit_data)
Definition: proto.c:823
#define RelationGetDescr(relation)
Definition: rel.h:482
void logicalrep_write_stream_stop(StringInfo out)
Definition: proto.c:789
#define VARSIZE(PTR)
Definition: postgres.h:303
void logicalrep_read_begin(StringInfo in, LogicalRepBeginData *begin_data)
Definition: proto.c:59
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:581
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define VARHDRSZ
Definition: c.h:569
List * logicalrep_read_truncate(StringInfo in, bool *cascade, bool *restart_seqs)
Definition: proto.c:343
char * pstrdup(const char *in)
Definition: mcxt.c:1187
static void logicalrep_write_namespace(StringInfo out, Oid nspid)
Definition: proto.c:721
#define LOGICALREP_COLUMN_NULL
Definition: logicalproto.h:52
LogicalRepRelation * logicalrep_read_rel(StringInfo in)
Definition: proto.c:397
unsigned char uint8
Definition: c.h:373
void logicalrep_write_stream_abort(StringInfo out, TransactionId xid, TransactionId subxid)
Definition: proto.c:849
#define LOGICALREP_COLUMN_TEXT
Definition: logicalproto.h:54
void logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: proto.c:74
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void logicalrep_write_delete(StringInfo out, TransactionId xid, Relation rel, HeapTuple oldtuple, bool binary)
Definition: proto.c:259
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
void logicalrep_write_origin(StringInfo out, const char *origin, XLogRecPtr origin_lsn)
Definition: proto.c:112
StringInfoData * colvalues
Definition: logicalproto.h:43
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
Form_pg_class rd_rel
Definition: rel.h:109
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:357
#define OidIsValid(objectId)
Definition: c.h:652
#define LOGICALREP_COLUMN_BINARY
Definition: logicalproto.h:55
void logicalrep_write_insert(StringInfo out, TransactionId xid, Relation rel, HeapTuple newtuple, bool binary)
Definition: proto.c:141
Bitmapset * attkeys
Definition: logicalproto.h:71
LogicalRepRelId remoteid
Definition: logicalproto.h:63
#define LOGICALREP_IS_REPLICA_IDENTITY
Definition: proto.c:26
LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup)
Definition: proto.c:163
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
void logicalrep_write_stream_start(StringInfo out, TransactionId xid, bool first_segment)
Definition: proto.c:755
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define LOGICALREP_COLUMN_UNCHANGED
Definition: logicalproto.h:53
unsigned short uint16
Definition: c.h:374
void pfree(void *pointer)
Definition: mcxt.c:1057
void logicalrep_write_rel(StringInfo out, TransactionId xid, Relation rel)
Definition: proto.c:368
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
void logicalrep_read_typ(StringInfo in, LogicalRepTyp *ltyp)
Definition: proto.c:453
bytea * OidSendFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1676
uint32 t_len
Definition: htup.h:64
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
static void logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
Definition: proto.c:554
static void logicalrep_write_attrs(StringInfo out, Relation rel)
Definition: proto.c:620
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:283
#define RelationGetRelationName(relation)
Definition: rel.h:490
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
XLogRecPtr final_lsn
void pq_sendcountedtext(StringInfo buf, const char *str, int slen, bool countincludesself)
Definition: pqformat.c:142
static void logicalrep_read_attrs(StringInfo in, LogicalRepRelation *rel)
Definition: proto.c:679
void logicalrep_write_stream_commit(StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: proto.c:798
void logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn)
Definition: proto.c:45
XLogRecPtr final_lsn
Definition: logicalproto.h:85
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void * palloc0(Size size)
Definition: mcxt.c:981
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
TransactionId xid
static struct @143 value
static const char * logicalrep_read_namespace(StringInfo in)
Definition: proto.c:741
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:746
void pq_copymsgbytes(StringInfo msg, char *buf, int datalen)
Definition: pqformat.c:530
XLogRecPtr end_lsn
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
LogicalRepRelId logicalrep_read_update(StringInfo in, bool *has_oldtuple, LogicalRepTupleData *oldtup, LogicalRepTupleData *newtup)
Definition: proto.c:218
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
void logicalrep_read_commit(StringInfo in, LogicalRepCommitData *commit_data)
Definition: proto.c:94
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
static Datum values[MAXATTR]
Definition: bootstrap.c:165
void pq_sendbytes(StringInfo buf, const char *data, int datalen)
Definition: pqformat.c:125
TransactionId logicalrep_read_stream_start(StringInfo in, bool *first_segment)
Definition: proto.c:773
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1657
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:214
int i
void logicalrep_write_typ(StringInfo out, TransactionId xid, Oid typoid)
Definition: proto.c:422
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:4944
#define TRUNCATE_CASCADE
Definition: proto.c:28
#define NameStr(name)
Definition: c.h:623
Definition: c.h:563
char * logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn)
Definition: proto.c:128
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
void logicalrep_write_update(StringInfo out, TransactionId xid, Relation rel, HeapTuple oldtuple, HeapTuple newtuple, bool binary)
Definition: proto.c:185
TimestampTz committime
Definition: logicalproto.h:86
#define TransactionIdIsValid(xid)
Definition: transam.h:41
XLogRecPtr commit_lsn
Definition: logicalproto.h:92
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409
static void pq_sendint8(StringInfo buf, uint8 i)
Definition: pqformat.h:129
Definition: pg_list.h:50
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
#define TRUNCATE_RESTART_SEQS
Definition: proto.c:29
#define RelationGetRelid(relation)
Definition: rel.h:456
TimestampTz committime
Definition: logicalproto.h:94
char * nspname
Definition: logicalproto.h:78
void logicalrep_read_stream_abort(StringInfo in, TransactionId *xid, TransactionId *subxid)
Definition: proto.c:865
uint32 LogicalRepRelId
Definition: logicalproto.h:57
#define RelationGetNamespace(relation)
Definition: rel.h:497