Skip to content

Commit 9f1cf97

Browse files
committed
Print WAL logical message contents in pg_waldump
This helps debuggability when looking at WAL streams containing logical messages. Author: Ashutosh Bapat <ashutosh.bapat@2ndquadrant.com> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/CAExHW5sWx49rKmXbg5H1Xc1t+nRv9PaYKQmgw82HPt6vWDVmDg@mail.gmail.com
1 parent 58c6fec commit 9f1cf97

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/backend/access/rmgrdesc/logicalmsgdesc.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record)
2424
if (info == XLOG_LOGICAL_MESSAGE)
2525
{
2626
xl_logical_message *xlrec = (xl_logical_message *) rec;
27+
char *prefix = xlrec->message;
28+
char *message = xlrec->message + xlrec->prefix_size;
29+
char *sep = "";
2730

28-
appendStringInfo(buf, "%s message size %zu bytes",
29-
xlrec->transactional ? "transactional" : "nontransactional",
30-
xlrec->message_size);
31+
Assert(prefix[xlrec->prefix_size] != '\0');
32+
33+
appendStringInfo(buf, "%s, prefix \"%s\"; payload (%zu bytes): ",
34+
xlrec->transactional ? "transactional" : "non-transactional",
35+
prefix, xlrec->message_size);
36+
/* Write message payload as a series of hex bytes */
37+
for (int cnt = 0; cnt < xlrec->message_size; cnt++)
38+
{
39+
appendStringInfo(buf, "%s%02X", sep, (unsigned char) message[cnt]);
40+
sep = " ";
41+
}
3142
}
3243
}
3344

src/backend/replication/logical/message.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
5959

6060
xlrec.dbId = MyDatabaseId;
6161
xlrec.transactional = transactional;
62+
/* trailing zero is critical; see logicalmsg_desc */
6263
xlrec.prefix_size = strlen(prefix) + 1;
6364
xlrec.message_size = size;
6465

src/include/replication/message.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ typedef struct xl_logical_message
2323
bool transactional; /* is message transactional? */
2424
Size prefix_size; /* length of prefix */
2525
Size message_size; /* size of the message */
26-
char message[FLEXIBLE_ARRAY_MEMBER]; /* message including the null
27-
* terminated prefix of length
28-
* prefix_size */
26+
/* payload, including null-terminated prefix of length prefix_size */
27+
char message[FLEXIBLE_ARRAY_MEMBER];
2928
} xl_logical_message;
3029

3130
#define SizeOfLogicalMessage (offsetof(xl_logical_message, message))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy