PostgreSQL Source Code  git master
logicalproto.h File Reference
Include dependency graph for logicalproto.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LogicalRepTupleData
 
struct  LogicalRepRelation
 
struct  LogicalRepTyp
 
struct  LogicalRepBeginData
 
struct  LogicalRepCommitData
 

Macros

#define LOGICALREP_PROTO_MIN_VERSION_NUM   1
 
#define LOGICALREP_PROTO_VERSION_NUM   1
 

Typedefs

typedef struct LogicalRepTupleData LogicalRepTupleData
 
typedef uint32 LogicalRepRelId
 
typedef struct LogicalRepRelation LogicalRepRelation
 
typedef struct LogicalRepTyp LogicalRepTyp
 
typedef struct LogicalRepBeginData LogicalRepBeginData
 
typedef struct LogicalRepCommitData LogicalRepCommitData
 

Functions

void logicalrep_write_begin (StringInfo out, ReorderBufferTXN *txn)
 
void logicalrep_read_begin (StringInfo in, LogicalRepBeginData *begin_data)
 
void logicalrep_write_commit (StringInfo out, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
void logicalrep_read_commit (StringInfo in, LogicalRepCommitData *commit_data)
 
void logicalrep_write_origin (StringInfo out, const char *origin, XLogRecPtr origin_lsn)
 
char * logicalrep_read_origin (StringInfo in, XLogRecPtr *origin_lsn)
 
void logicalrep_write_insert (StringInfo out, Relation rel, HeapTuple newtuple)
 
LogicalRepRelId logicalrep_read_insert (StringInfo in, LogicalRepTupleData *newtup)
 
void logicalrep_write_update (StringInfo out, Relation rel, HeapTuple oldtuple, HeapTuple newtuple)
 
LogicalRepRelId logicalrep_read_update (StringInfo in, bool *has_oldtuple, LogicalRepTupleData *oldtup, LogicalRepTupleData *newtup)
 
void logicalrep_write_delete (StringInfo out, Relation rel, HeapTuple oldtuple)
 
LogicalRepRelId logicalrep_read_delete (StringInfo in, LogicalRepTupleData *oldtup)
 
void logicalrep_write_truncate (StringInfo out, int nrelids, Oid relids[], bool cascade, bool restart_seqs)
 
Listlogicalrep_read_truncate (StringInfo in, bool *cascade, bool *restart_seqs)
 
void logicalrep_write_rel (StringInfo out, Relation rel)
 
LogicalRepRelationlogicalrep_read_rel (StringInfo in)
 
void logicalrep_write_typ (StringInfo out, Oid typoid)
 
void logicalrep_read_typ (StringInfo out, LogicalRepTyp *ltyp)
 

Macro Definition Documentation

◆ LOGICALREP_PROTO_MIN_VERSION_NUM

#define LOGICALREP_PROTO_MIN_VERSION_NUM   1

Definition at line 27 of file logicalproto.h.

Referenced by pgoutput_startup().

◆ LOGICALREP_PROTO_VERSION_NUM

#define LOGICALREP_PROTO_VERSION_NUM   1

Definition at line 28 of file logicalproto.h.

Referenced by ApplyWorkerMain(), and pgoutput_startup().

Typedef Documentation

◆ LogicalRepBeginData

◆ LogicalRepCommitData

◆ LogicalRepRelation

◆ LogicalRepRelId

Definition at line 39 of file logicalproto.h.

◆ LogicalRepTupleData

◆ LogicalRepTyp

typedef struct LogicalRepTyp LogicalRepTyp

Function Documentation

◆ logicalrep_read_begin()

void logicalrep_read_begin ( StringInfo  in,
LogicalRepBeginData begin_data 
)

Definition at line 60 of file proto.c.

References LogicalRepBeginData::committime, elog, ERROR, LogicalRepBeginData::final_lsn, InvalidXLogRecPtr, pq_getmsgint(), pq_getmsgint64(), and LogicalRepBeginData::xid.

Referenced by apply_handle_begin().

61 {
62  /* read fields */
63  begin_data->final_lsn = pq_getmsgint64(in);
64  if (begin_data->final_lsn == InvalidXLogRecPtr)
65  elog(ERROR, "final_lsn not set in begin message");
66  begin_data->committime = pq_getmsgint64(in);
67  begin_data->xid = pq_getmsgint(in, 4);
68 }
TransactionId xid
Definition: logicalproto.h:69
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define ERROR
Definition: elog.h:43
XLogRecPtr final_lsn
Definition: logicalproto.h:67
#define elog(elevel,...)
Definition: elog.h:214
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
TimestampTz committime
Definition: logicalproto.h:68

◆ logicalrep_read_commit()

void logicalrep_read_commit ( StringInfo  in,
LogicalRepCommitData commit_data 
)

Definition at line 95 of file proto.c.

References LogicalRepCommitData::commit_lsn, LogicalRepCommitData::committime, elog, LogicalRepCommitData::end_lsn, ERROR, pq_getmsgbyte(), and pq_getmsgint64().

Referenced by apply_handle_commit().

96 {
97  /* read flags (unused for now) */
98  uint8 flags = pq_getmsgbyte(in);
99 
100  if (flags != 0)
101  elog(ERROR, "unrecognized flags %u in commit message", flags);
102 
103  /* read fields */
104  commit_data->commit_lsn = pq_getmsgint64(in);
105  commit_data->end_lsn = pq_getmsgint64(in);
106  commit_data->committime = pq_getmsgint64(in);
107 }
unsigned char uint8
Definition: c.h:365
#define ERROR
Definition: elog.h:43
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
#define elog(elevel,...)
Definition: elog.h:214
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
XLogRecPtr commit_lsn
Definition: logicalproto.h:74
TimestampTz committime
Definition: logicalproto.h:76

◆ logicalrep_read_delete()

LogicalRepRelId logicalrep_read_delete ( StringInfo  in,
LogicalRepTupleData oldtup 
)

Definition at line 276 of file proto.c.

References generate_unaccent_rules::action, elog, ERROR, logicalrep_read_tuple(), pq_getmsgbyte(), and pq_getmsgint().

Referenced by apply_handle_delete().

277 {
278  char action;
279  LogicalRepRelId relid;
280 
281  /* read the relation id */
282  relid = pq_getmsgint(in, 4);
283 
284  /* read and verify action */
285  action = pq_getmsgbyte(in);
286  if (action != 'K' && action != 'O')
287  elog(ERROR, "expected action 'O' or 'K', got %c", action);
288 
289  logicalrep_read_tuple(in, oldtup);
290 
291  return relid;
292 }
#define ERROR
Definition: elog.h:43
static void logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
Definition: proto.c:507
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
#define elog(elevel,...)
Definition: elog.h:214
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
uint32 LogicalRepRelId
Definition: logicalproto.h:39

◆ logicalrep_read_insert()

LogicalRepRelId logicalrep_read_insert ( StringInfo  in,
LogicalRepTupleData newtup 
)

Definition at line 159 of file proto.c.

References generate_unaccent_rules::action, elog, ERROR, logicalrep_read_tuple(), pq_getmsgbyte(), and pq_getmsgint().

Referenced by apply_handle_insert().

160 {
161  char action;
162  LogicalRepRelId relid;
163 
164  /* read the relation id */
165  relid = pq_getmsgint(in, 4);
166 
167  action = pq_getmsgbyte(in);
168  if (action != 'N')
169  elog(ERROR, "expected new tuple but got %d",
170  action);
171 
172  logicalrep_read_tuple(in, newtup);
173 
174  return relid;
175 }
#define ERROR
Definition: elog.h:43
static void logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
Definition: proto.c:507
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
#define elog(elevel,...)
Definition: elog.h:214
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
uint32 LogicalRepRelId
Definition: logicalproto.h:39

◆ logicalrep_read_origin()

char* logicalrep_read_origin ( StringInfo  in,
XLogRecPtr origin_lsn 
)

Definition at line 129 of file proto.c.

References pq_getmsgint64(), pq_getmsgstring(), and pstrdup().

130 {
131  /* fixed fields */
132  *origin_lsn = pq_getmsgint64(in);
133 
134  /* return origin */
135  return pstrdup(pq_getmsgstring(in));
136 }
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:581
char * pstrdup(const char *in)
Definition: mcxt.c:1186
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ logicalrep_read_rel()

LogicalRepRelation* logicalrep_read_rel ( StringInfo  in)

Definition at line 375 of file proto.c.

References logicalrep_read_attrs(), logicalrep_read_namespace(), LogicalRepRelation::nspname, palloc(), pq_getmsgbyte(), pq_getmsgint(), pq_getmsgstring(), pstrdup(), LogicalRepRelation::relname, LogicalRepRelation::remoteid, and LogicalRepRelation::replident.

Referenced by apply_handle_relation().

376 {
378 
379  rel->remoteid = pq_getmsgint(in, 4);
380 
381  /* Read relation name from stream */
383  rel->relname = pstrdup(pq_getmsgstring(in));
384 
385  /* Read the replica identity. */
386  rel->replident = pq_getmsgbyte(in);
387 
388  /* Get attribute description */
389  logicalrep_read_attrs(in, rel);
390 
391  return rel;
392 }
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:581
char * pstrdup(const char *in)
Definition: mcxt.c:1186
LogicalRepRelId remoteid
Definition: logicalproto.h:45
static void logicalrep_read_attrs(StringInfo in, LogicalRepRelation *rel)
Definition: proto.c:617
static const char * logicalrep_read_namespace(StringInfo in)
Definition: proto.c:679
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
void * palloc(Size size)
Definition: mcxt.c:949
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ logicalrep_read_truncate()

List* logicalrep_read_truncate ( StringInfo  in,
bool cascade,
bool restart_seqs 
)

Definition at line 325 of file proto.c.

References i, lappend_oid(), NIL, pq_getmsgint(), TRUNCATE_CASCADE, and TRUNCATE_RESTART_SEQS.

Referenced by apply_handle_truncate().

327 {
328  int i;
329  int nrelids;
330  List *relids = NIL;
331  uint8 flags;
332 
333  nrelids = pq_getmsgint(in, 4);
334 
335  /* read and decode truncate flags */
336  flags = pq_getmsgint(in, 1);
337  *cascade = (flags & TRUNCATE_CASCADE) > 0;
338  *restart_seqs = (flags & TRUNCATE_RESTART_SEQS) > 0;
339 
340  for (i = 0; i < nrelids; i++)
341  relids = lappend_oid(relids, pq_getmsgint(in, 4));
342 
343  return relids;
344 }
#define NIL
Definition: pg_list.h:65
unsigned char uint8
Definition: c.h:365
List * lappend_oid(List *list, Oid datum)
Definition: list.c:357
int i
#define TRUNCATE_CASCADE
Definition: proto.c:29
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
Definition: pg_list.h:50
#define TRUNCATE_RESTART_SEQS
Definition: proto.c:30

◆ logicalrep_read_typ()

void logicalrep_read_typ ( StringInfo  out,
LogicalRepTyp ltyp 
)

Definition at line 427 of file proto.c.

References logicalrep_read_namespace(), LogicalRepTyp::nspname, pq_getmsgint(), pq_getmsgstring(), pstrdup(), LogicalRepTyp::remoteid, and LogicalRepTyp::typname.

Referenced by apply_handle_type().

428 {
429  ltyp->remoteid = pq_getmsgint(in, 4);
430 
431  /* Read type name from stream */
433  ltyp->typname = pstrdup(pq_getmsgstring(in));
434 }
char * typname
Definition: logicalproto.h:61
const char * pq_getmsgstring(StringInfo msg)
Definition: pqformat.c:581
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static const char * logicalrep_read_namespace(StringInfo in)
Definition: proto.c:679
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
char * nspname
Definition: logicalproto.h:60

◆ logicalrep_read_update()

LogicalRepRelId logicalrep_read_update ( StringInfo  in,
bool has_oldtuple,
LogicalRepTupleData oldtup,
LogicalRepTupleData newtup 
)

Definition at line 210 of file proto.c.

References generate_unaccent_rules::action, elog, ERROR, logicalrep_read_tuple(), pq_getmsgbyte(), and pq_getmsgint().

Referenced by apply_handle_update().

213 {
214  char action;
215  LogicalRepRelId relid;
216 
217  /* read the relation id */
218  relid = pq_getmsgint(in, 4);
219 
220  /* read and verify action */
221  action = pq_getmsgbyte(in);
222  if (action != 'K' && action != 'O' && action != 'N')
223  elog(ERROR, "expected action 'N', 'O' or 'K', got %c",
224  action);
225 
226  /* check for old tuple */
227  if (action == 'K' || action == 'O')
228  {
229  logicalrep_read_tuple(in, oldtup);
230  *has_oldtuple = true;
231 
232  action = pq_getmsgbyte(in);
233  }
234  else
235  *has_oldtuple = false;
236 
237  /* check for new tuple */
238  if (action != 'N')
239  elog(ERROR, "expected action 'N', got %c",
240  action);
241 
242  logicalrep_read_tuple(in, newtup);
243 
244  return relid;
245 }
#define ERROR
Definition: elog.h:43
static void logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
Definition: proto.c:507
int pq_getmsgbyte(StringInfo msg)
Definition: pqformat.c:401
#define elog(elevel,...)
Definition: elog.h:214
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
uint32 LogicalRepRelId
Definition: logicalproto.h:39

◆ logicalrep_write_begin()

void logicalrep_write_begin ( StringInfo  out,
ReorderBufferTXN txn 
)

Definition at line 46 of file proto.c.

References ReorderBufferTXN::commit_time, ReorderBufferTXN::final_lsn, pq_sendbyte(), pq_sendint32(), pq_sendint64(), and ReorderBufferTXN::xid.

Referenced by pgoutput_begin_txn().

47 {
48  pq_sendbyte(out, 'B'); /* BEGIN */
49 
50  /* fixed fields */
51  pq_sendint64(out, txn->final_lsn);
52  pq_sendint64(out, txn->commit_time);
53  pq_sendint32(out, txn->xid);
54 }
TimestampTz commit_time
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
XLogRecPtr final_lsn
TransactionId xid

◆ logicalrep_write_commit()

void logicalrep_write_commit ( StringInfo  out,
ReorderBufferTXN txn,
XLogRecPtr  commit_lsn 
)

Definition at line 75 of file proto.c.

References ReorderBufferTXN::commit_time, ReorderBufferTXN::end_lsn, pq_sendbyte(), and pq_sendint64().

Referenced by pgoutput_commit_txn().

77 {
78  uint8 flags = 0;
79 
80  pq_sendbyte(out, 'C'); /* sending COMMIT */
81 
82  /* send the flags field (unused for now) */
83  pq_sendbyte(out, flags);
84 
85  /* send fields */
86  pq_sendint64(out, commit_lsn);
87  pq_sendint64(out, txn->end_lsn);
88  pq_sendint64(out, txn->commit_time);
89 }
TimestampTz commit_time
unsigned char uint8
Definition: c.h:365
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
XLogRecPtr end_lsn

◆ logicalrep_write_delete()

void logicalrep_write_delete ( StringInfo  out,
Relation  rel,
HeapTuple  oldtuple 
)

Definition at line 251 of file proto.c.

References Assert, logicalrep_write_tuple(), pq_sendbyte(), pq_sendint32(), RelationData::rd_rel, and RelationGetRelid.

Referenced by pgoutput_change().

252 {
253  Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
254  rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
255  rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
256 
257  pq_sendbyte(out, 'D'); /* action DELETE */
258 
259  /* use Oid as relation identifier */
260  pq_sendint32(out, RelationGetRelid(rel));
261 
262  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
263  pq_sendbyte(out, 'O'); /* old tuple follows */
264  else
265  pq_sendbyte(out, 'K'); /* old key follows */
266 
267  logicalrep_write_tuple(out, rel, oldtuple);
268 }
Form_pg_class rd_rel
Definition: rel.h:109
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define Assert(condition)
Definition: c.h:738
#define RelationGetRelid(relation)
Definition: rel.h:456
static void logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple)
Definition: proto.c:440

◆ logicalrep_write_insert()

void logicalrep_write_insert ( StringInfo  out,
Relation  rel,
HeapTuple  newtuple 
)

Definition at line 142 of file proto.c.

References logicalrep_write_tuple(), pq_sendbyte(), pq_sendint32(), and RelationGetRelid.

Referenced by pgoutput_change().

143 {
144  pq_sendbyte(out, 'I'); /* action INSERT */
145 
146  /* use Oid as relation identifier */
147  pq_sendint32(out, RelationGetRelid(rel));
148 
149  pq_sendbyte(out, 'N'); /* new tuple follows */
150  logicalrep_write_tuple(out, rel, newtuple);
151 }
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define RelationGetRelid(relation)
Definition: rel.h:456
static void logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple)
Definition: proto.c:440

◆ logicalrep_write_origin()

void logicalrep_write_origin ( StringInfo  out,
const char *  origin,
XLogRecPtr  origin_lsn 
)

Definition at line 113 of file proto.c.

References pq_sendbyte(), pq_sendint64(), and pq_sendstring().

Referenced by pgoutput_begin_txn().

115 {
116  pq_sendbyte(out, 'O'); /* ORIGIN */
117 
118  /* fixed fields */
119  pq_sendint64(out, origin_lsn);
120 
121  /* origin string */
122  pq_sendstring(out, origin);
123 }
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161

◆ logicalrep_write_rel()

void logicalrep_write_rel ( StringInfo  out,
Relation  rel 
)

Definition at line 350 of file proto.c.

References logicalrep_write_attrs(), logicalrep_write_namespace(), pq_sendbyte(), pq_sendint32(), pq_sendstring(), RelationData::rd_rel, RelationGetNamespace, RelationGetRelationName, RelationGetRelid, and relname.

Referenced by send_relation_and_attrs().

351 {
352  char *relname;
353 
354  pq_sendbyte(out, 'R'); /* sending RELATION */
355 
356  /* use Oid as relation identifier */
357  pq_sendint32(out, RelationGetRelid(rel));
358 
359  /* send qualified relation name */
361  relname = RelationGetRelationName(rel);
362  pq_sendstring(out, relname);
363 
364  /* send replica identity */
365  pq_sendbyte(out, rel->rd_rel->relreplident);
366 
367  /* send the attribute info */
368  logicalrep_write_attrs(out, rel);
369 }
static void logicalrep_write_namespace(StringInfo out, Oid nspid)
Definition: proto.c:659
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
Form_pg_class rd_rel
Definition: rel.h:109
NameData relname
Definition: pg_class.h:38
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static void logicalrep_write_attrs(StringInfo out, Relation rel)
Definition: proto.c:558
#define RelationGetRelationName(relation)
Definition: rel.h:490
#define RelationGetRelid(relation)
Definition: rel.h:456
#define RelationGetNamespace(relation)
Definition: rel.h:497

◆ logicalrep_write_truncate()

void logicalrep_write_truncate ( StringInfo  out,
int  nrelids,
Oid  relids[],
bool  cascade,
bool  restart_seqs 
)

Definition at line 298 of file proto.c.

References i, pq_sendbyte(), pq_sendint32(), pq_sendint8(), TRUNCATE_CASCADE, and TRUNCATE_RESTART_SEQS.

Referenced by pgoutput_truncate().

302 {
303  int i;
304  uint8 flags = 0;
305 
306  pq_sendbyte(out, 'T'); /* action TRUNCATE */
307 
308  pq_sendint32(out, nrelids);
309 
310  /* encode and send truncate flags */
311  if (cascade)
312  flags |= TRUNCATE_CASCADE;
313  if (restart_seqs)
314  flags |= TRUNCATE_RESTART_SEQS;
315  pq_sendint8(out, flags);
316 
317  for (i = 0; i < nrelids; i++)
318  pq_sendint32(out, relids[i]);
319 }
unsigned char uint8
Definition: c.h:365
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
int i
#define TRUNCATE_CASCADE
Definition: proto.c:29
static void pq_sendint8(StringInfo buf, uint8 i)
Definition: pqformat.h:129
#define TRUNCATE_RESTART_SEQS
Definition: proto.c:30

◆ logicalrep_write_typ()

void logicalrep_write_typ ( StringInfo  out,
Oid  typoid 
)

Definition at line 400 of file proto.c.

References elog, ERROR, getBaseType(), GETSTRUCT, HeapTupleIsValid, logicalrep_write_namespace(), NameStr, ObjectIdGetDatum, pq_sendbyte(), pq_sendint32(), pq_sendstring(), ReleaseSysCache(), SearchSysCache1(), and TYPEOID.

Referenced by send_relation_and_attrs().

401 {
402  Oid basetypoid = getBaseType(typoid);
403  HeapTuple tup;
404  Form_pg_type typtup;
405 
406  pq_sendbyte(out, 'Y'); /* sending TYPE */
407 
408  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(basetypoid));
409  if (!HeapTupleIsValid(tup))
410  elog(ERROR, "cache lookup failed for type %u", basetypoid);
411  typtup = (Form_pg_type) GETSTRUCT(tup);
412 
413  /* use Oid as relation identifier */
414  pq_sendint32(out, typoid);
415 
416  /* send qualified type name */
417  logicalrep_write_namespace(out, typtup->typnamespace);
418  pq_sendstring(out, NameStr(typtup->typname));
419 
420  ReleaseSysCache(tup);
421 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
static void logicalrep_write_namespace(StringInfo out, Oid nspid)
Definition: proto.c:659
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
unsigned int Oid
Definition: postgres_ext.h:31
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:615
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409

◆ logicalrep_write_update()

void logicalrep_write_update ( StringInfo  out,
Relation  rel,
HeapTuple  oldtuple,
HeapTuple  newtuple 
)

Definition at line 181 of file proto.c.

References Assert, logicalrep_write_tuple(), pq_sendbyte(), pq_sendint32(), RelationData::rd_rel, and RelationGetRelid.

Referenced by pgoutput_change().

183 {
184  pq_sendbyte(out, 'U'); /* action UPDATE */
185 
186  Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
187  rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
188  rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
189 
190  /* use Oid as relation identifier */
191  pq_sendint32(out, RelationGetRelid(rel));
192 
193  if (oldtuple != NULL)
194  {
195  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
196  pq_sendbyte(out, 'O'); /* old tuple follows */
197  else
198  pq_sendbyte(out, 'K'); /* old key follows */
199  logicalrep_write_tuple(out, rel, oldtuple);
200  }
201 
202  pq_sendbyte(out, 'N'); /* new tuple follows */
203  logicalrep_write_tuple(out, rel, newtuple);
204 }
Form_pg_class rd_rel
Definition: rel.h:109
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition: pqformat.h:161
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define Assert(condition)
Definition: c.h:738
#define RelationGetRelid(relation)
Definition: rel.h:456
static void logicalrep_write_tuple(StringInfo out, Relation rel, HeapTuple tuple)
Definition: proto.c:440