Commit 9d0bd95f authored by Michael Paquier's avatar Michael Paquier

Add block information in error context of WAL REDO apply loop

Providing this information can be useful for example when diagnosing
problems related to recovery conflicts or for recovery issues without
having to go through the output generated by pg_waldump to get some
information about the blocks a WAL record works on.

The block information is printed in the same format as pg_waldump.  This
already existed in xlog.c for debugging purposes with -DWAL_DEBUG, so
adding the block information in the callback has required just a small
refactoring.

Author: Bertrand Drouvot
Reviewed-by: Michael Paquier, Masahiko Sawada
Discussion: https://postgr.es/m/c31e2cba-efda-762c-f4ad-5c25e5dac3d0@amazon.com
parent 49642530
...@@ -940,6 +940,7 @@ static bool CheckForStandbyTrigger(void); ...@@ -940,6 +940,7 @@ static bool CheckForStandbyTrigger(void);
#ifdef WAL_DEBUG #ifdef WAL_DEBUG
static void xlog_outrec(StringInfo buf, XLogReaderState *record); static void xlog_outrec(StringInfo buf, XLogReaderState *record);
#endif #endif
static void xlog_block_info(StringInfo buf, XLogReaderState *record);
static void xlog_outdesc(StringInfo buf, XLogReaderState *record); static void xlog_outdesc(StringInfo buf, XLogReaderState *record);
static void pg_start_backup_callback(int code, Datum arg); static void pg_start_backup_callback(int code, Datum arg);
static void pg_stop_backup_callback(int code, Datum arg); static void pg_stop_backup_callback(int code, Datum arg);
...@@ -10258,6 +10259,19 @@ xlog_outrec(StringInfo buf, XLogReaderState *record) ...@@ -10258,6 +10259,19 @@ xlog_outrec(StringInfo buf, XLogReaderState *record)
appendStringInfo(buf, "; len %u", appendStringInfo(buf, "; len %u",
XLogRecGetDataLen(record)); XLogRecGetDataLen(record));
xlog_block_info(buf, record);
}
#endif /* WAL_DEBUG */
/*
* Returns a string giving information about all the blocks in an
* XLogRecord.
*/
static void
xlog_block_info(StringInfo buf, XLogReaderState *record)
{
int block_id;
/* decode block references */ /* decode block references */
for (block_id = 0; block_id <= record->max_block_id; block_id++) for (block_id = 0; block_id <= record->max_block_id; block_id++)
{ {
...@@ -10284,7 +10298,6 @@ xlog_outrec(StringInfo buf, XLogReaderState *record) ...@@ -10284,7 +10298,6 @@ xlog_outrec(StringInfo buf, XLogReaderState *record)
appendStringInfoString(buf, " FPW"); appendStringInfoString(buf, " FPW");
} }
} }
#endif /* WAL_DEBUG */
/* /*
* Returns a string describing an XLogRecord, consisting of its identity * Returns a string describing an XLogRecord, consisting of its identity
...@@ -11765,6 +11778,7 @@ rm_redo_error_callback(void *arg) ...@@ -11765,6 +11778,7 @@ rm_redo_error_callback(void *arg)
initStringInfo(&buf); initStringInfo(&buf);
xlog_outdesc(&buf, record); xlog_outdesc(&buf, record);
xlog_block_info(&buf, record);
/* translator: %s is a WAL record description */ /* translator: %s is a WAL record description */
errcontext("WAL redo at %X/%X for %s", errcontext("WAL redo at %X/%X for %s",
......
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