Commit 9f1cf97b authored by Alvaro Herrera's avatar Alvaro Herrera

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: default avatarÁlvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/CAExHW5sWx49rKmXbg5H1Xc1t+nRv9PaYKQmgw82HPt6vWDVmDg@mail.gmail.com
parent 58c6fecc
...@@ -24,10 +24,21 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record) ...@@ -24,10 +24,21 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record)
if (info == XLOG_LOGICAL_MESSAGE) if (info == XLOG_LOGICAL_MESSAGE)
{ {
xl_logical_message *xlrec = (xl_logical_message *) rec; xl_logical_message *xlrec = (xl_logical_message *) rec;
char *prefix = xlrec->message;
char *message = xlrec->message + xlrec->prefix_size;
char *sep = "";
appendStringInfo(buf, "%s message size %zu bytes", Assert(prefix[xlrec->prefix_size] != '\0');
xlrec->transactional ? "transactional" : "nontransactional",
xlrec->message_size); appendStringInfo(buf, "%s, prefix \"%s\"; payload (%zu bytes): ",
xlrec->transactional ? "transactional" : "non-transactional",
prefix, xlrec->message_size);
/* Write message payload as a series of hex bytes */
for (int cnt = 0; cnt < xlrec->message_size; cnt++)
{
appendStringInfo(buf, "%s%02X", sep, (unsigned char) message[cnt]);
sep = " ";
}
} }
} }
......
...@@ -59,6 +59,7 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size, ...@@ -59,6 +59,7 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
xlrec.dbId = MyDatabaseId; xlrec.dbId = MyDatabaseId;
xlrec.transactional = transactional; xlrec.transactional = transactional;
/* trailing zero is critical; see logicalmsg_desc */
xlrec.prefix_size = strlen(prefix) + 1; xlrec.prefix_size = strlen(prefix) + 1;
xlrec.message_size = size; xlrec.message_size = size;
......
...@@ -23,9 +23,8 @@ typedef struct xl_logical_message ...@@ -23,9 +23,8 @@ typedef struct xl_logical_message
bool transactional; /* is message transactional? */ bool transactional; /* is message transactional? */
Size prefix_size; /* length of prefix */ Size prefix_size; /* length of prefix */
Size message_size; /* size of the message */ Size message_size; /* size of the message */
char message[FLEXIBLE_ARRAY_MEMBER]; /* message including the null /* payload, including null-terminated prefix of length prefix_size */
* terminated prefix of length char message[FLEXIBLE_ARRAY_MEMBER];
* prefix_size */
} xl_logical_message; } xl_logical_message;
#define SizeOfLogicalMessage (offsetof(xl_logical_message, message)) #define SizeOfLogicalMessage (offsetof(xl_logical_message, message))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment