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
This commit is contained in:
Alvaro Herrera 2020-09-10 19:37:02 -03:00
parent 58c6feccfa
commit 9f1cf97bb5
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
3 changed files with 17 additions and 6 deletions

View File

@ -24,10 +24,21 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record)
if (info == XLOG_LOGICAL_MESSAGE)
{
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",
xlrec->transactional ? "transactional" : "nontransactional",
xlrec->message_size);
Assert(prefix[xlrec->prefix_size] != '\0');
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 = " ";
}
}
}

View File

@ -59,6 +59,7 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
xlrec.dbId = MyDatabaseId;
xlrec.transactional = transactional;
/* trailing zero is critical; see logicalmsg_desc */
xlrec.prefix_size = strlen(prefix) + 1;
xlrec.message_size = size;

View File

@ -23,9 +23,8 @@ typedef struct xl_logical_message
bool transactional; /* is message transactional? */
Size prefix_size; /* length of prefix */
Size message_size; /* size of the message */
char message[FLEXIBLE_ARRAY_MEMBER]; /* message including the null
* terminated prefix of length
* prefix_size */
/* payload, including null-terminated prefix of length prefix_size */
char message[FLEXIBLE_ARRAY_MEMBER];
} xl_logical_message;
#define SizeOfLogicalMessage (offsetof(xl_logical_message, message))