From: Thomas Munro Date: Fri, 11 Jan 2019 13:17:02 +0000 (+1300) Subject: Allow WAL record data on first modification after a checkpoint. X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=3d3565b64e2c2fd3a47c6fbdfa42d542923d44d4;p=users%2Frhaas%2Fpostgres.git Allow WAL record data on first modification after a checkpoint. Provide a way to attach data to WAL record conditionally, so that it is included only if this turns out to the be first modification to a given block after a checkpoint. This will be used to record undo log meta-data, to avoid a data synchronization problem with online checkpoints. Author: Thomas Munro Reviewed-by: Discussion: --- diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 3ec67d468b..001d7cb05b 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -565,6 +565,21 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, needs_data = false; else if ((regbuf->flags & REGBUF_KEEP_DATA) != 0) needs_data = true; + else if ((regbuf->flags & REGBUF_KEEP_DATA_AFTER_CP) != 0) + { + XLogRecPtr page_lsn = PageGetLSN(regbuf->page); + + needs_data = (page_lsn <= RedoRecPtr); + if (!needs_data) + { + /* + * XLogInsertRecord() will detect if our view of the latest + * checkpoint's RedoRecPtr is out of date. + */ + if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn) + *fpw_lsn = page_lsn; + } + } else needs_data = !needs_backup; diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index df24089ea4..22b388cb33 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -37,6 +37,8 @@ * will be skipped) */ #define REGBUF_KEEP_DATA 0x10 /* include data even if a full-page image * is taken */ +#define REGBUF_KEEP_DATA_AFTER_CP 0x20 /* include data on the first + * modification after a checkpoint */ /* prototypes for public functions in xloginsert.c: */ extern void XLogBeginInsert(void);