Formalize WAL record for XLOG_CHECKPOINT_REDO

XLOG_CHECKPOINT_REDO only contains the wal_level copied straight in
without an encapsulating record structure. While it works, it makes
future uses of XLOG_CHECKPOINT_REDO hard as there is nowhere to put
new data items.  This fix this was inspired by the online checksums
patch which adds data to this record,  but this change has value on
its own.

Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/c92b5d8b-bc03-47bc-b209-2e4a719eee32@iki.fi
This commit is contained in:
Daniel Gustafsson 2026-03-31 09:38:01 +02:00
parent 82a7cbea74
commit 097ab69d17
5 changed files with 21 additions and 5 deletions

View file

@ -163,10 +163,10 @@ xlog_desc(StringInfo buf, XLogReaderState *record)
}
else if (info == XLOG_CHECKPOINT_REDO)
{
int wal_level;
xl_checkpoint_redo xlrec;
memcpy(&wal_level, rec, sizeof(int));
appendStringInfo(buf, "wal_level %s", get_wal_level_string(wal_level));
memcpy(&xlrec, rec, sizeof(xl_checkpoint_redo));
appendStringInfo(buf, "wal_level %s", get_wal_level_string(xlrec.wal_level));
}
else if (info == XLOG_LOGICAL_DECODING_STATUS_CHANGE)
{

View file

@ -7179,9 +7179,15 @@ CreateCheckPoint(int flags)
*/
if (!shutdown)
{
xl_checkpoint_redo redo_rec;
WALInsertLockAcquire();
redo_rec.wal_level = wal_level;
WALInsertLockRelease();
/* Include WAL level in record for WAL summarizer's benefit. */
XLogBeginInsert();
XLogRegisterData(&wal_level, sizeof(wal_level));
XLogRegisterData(&redo_rec, sizeof(xl_checkpoint_redo));
(void) XLogInsert(RM_XLOG_ID, XLOG_CHECKPOINT_REDO);
/*

View file

@ -1435,8 +1435,11 @@ SummarizeXlogRecord(XLogReaderState *xlogreader, bool *new_fast_forward)
if (info == XLOG_CHECKPOINT_REDO)
{
xl_checkpoint_redo xlrec;
/* Payload is wal_level at the time record was written. */
memcpy(&record_wal_level, XLogRecGetData(xlogreader), sizeof(int));
memcpy(&xlrec, XLogRecGetData(xlogreader), sizeof(xl_checkpoint_redo));
record_wal_level = xlrec.wal_level;
}
else if (info == XLOG_CHECKPOINT_SHUTDOWN)
{

View file

@ -303,6 +303,12 @@ typedef struct xl_end_of_recovery
int wal_level;
} xl_end_of_recovery;
/* checkpoint redo */
typedef struct xl_checkpoint_redo
{
int wal_level;
} xl_checkpoint_redo;
/*
* The functions in xloginsert.c construct a chain of XLogRecData structs
* to represent the final WAL record.

View file

@ -4397,6 +4397,7 @@ xl_btree_split
xl_btree_unlink_page
xl_btree_update
xl_btree_vacuum
xl_checkpoint_redo
xl_clog_truncate
xl_commit_ts_truncate
xl_dbase_create_file_copy_rec