Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97c61f7

Browse files
committed
Document WAL rules related to PD_ALL_VISIBLE in README.
Also improve comments.Discussion:https://postgr.es/m/a50005c1c537f89bb359057fd70e66bb83bce969.camel@j-davis.comReviewed-by: Peter Geoghegan
1 parentd6a3dbe commit97c61f7

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8193,8 +8193,10 @@ log_heap_freeze(Relation reln, Buffer buffer, TransactionId cutoff_xid,
81938193
* corresponding visibility map block. Both should have already been modified
81948194
* and dirtied.
81958195
*
8196-
* If checksums are enabled, we also generate a full-page image of
8197-
* heap_buffer, if necessary.
8196+
* If checksums or wal_log_hints are enabled, we may also generate a full-page
8197+
* image of heap_buffer. Otherwise, we optimize away the FPI (by specifying
8198+
* REGBUF_NO_IMAGE for the heap buffer), in which case the caller should *not*
8199+
* update the heap page's LSN.
81988200
*/
81998201
XLogRecPtr
82008202
log_heap_visible(RelFileLocatorrlocator,Bufferheap_buffer,Buffervm_buffer,

‎src/backend/access/heap/visibilitymap.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf)
223223
*visibilitymap_set - set bit(s) on a previously pinned page
224224
*
225225
* recptr is the LSN of the XLOG record we're replaying, if we're in recovery,
226-
* or InvalidXLogRecPtr in normal running. The page LSN is advanced to the
226+
* or InvalidXLogRecPtr in normal running. TheVMpage LSN is advanced to the
227227
* one provided; in normal running, we generate a new XLOG record and set the
228-
* page LSN to that value. cutoff_xid isthelargest xmin on the page being
229-
*marked all-visible; itisneeded for Hot Standby, and can be
230-
*InvalidTransactionId if the page contains no tuples. Itcanalsobeset
231-
*to InvalidTransactionId when a page that is already all-visible is being
232-
* marked all-frozen.
228+
* page LSN to that value (thoughtheheap page's LSN may *not* be updated;
229+
*see below). cutoff_xidisthe largest xmin on the page being marked
230+
*all-visible; it is needed for Hot Standby, andcan beInvalidTransactionId
231+
*if the page contains no tuples. It can also be set to InvalidTransactionId
232+
*when a page that is already all-visible is beingmarked all-frozen.
233233
*
234234
* Caller is expected to set the heap page's PD_ALL_VISIBLE bit before calling
235235
* this function. Except in recovery, caller should also pass the heap
@@ -289,6 +289,11 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
289289
/*
290290
* If data checksums are enabled (or wal_log_hints=on), we
291291
* need to protect the heap page from being torn.
292+
*
293+
* If not, then we must *not* update the heap page's LSN. In
294+
* this case, the FPI for the heap page was omitted from the
295+
* WAL record inserted above, so it would be incorrect to
296+
* update the heap page's LSN.
292297
*/
293298
if (XLogHintBitIsNeeded())
294299
{

‎src/backend/access/transam/README

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,23 @@ If you do decide to optimise away a WAL record, then any calls to
645645
MarkBufferDirty() must be replaced by MarkBufferDirtyHint(),
646646
otherwise you will expose the risk of partial page writes.
647647

648+
The all-visible hint in a heap page (PD_ALL_VISIBLE) is a special
649+
case, because it is treated like a durable change in some respects and
650+
a hint in other respects. It must satisfy the invariant that, if a
651+
heap page's associated visibilitymap (VM) bit is set, then
652+
PD_ALL_VISIBLE is set on the heap page itself. Clearing of
653+
PD_ALL_VISIBLE is always treated like a fully-durable change to
654+
maintain this invariant. Additionally, if checksums or wal_log_hints
655+
are enabled, setting PD_ALL_VISIBLE is also treated like a
656+
fully-durable change to protect against torn pages.
657+
658+
But, if neither checksums nor wal_log_hints are enabled, torn pages
659+
are of no consequence if the only change is to PD_ALL_VISIBLE; so no
660+
full heap page image is taken, and the heap page's LSN is not
661+
updated. NB: it would be incorrect to update the heap page's LSN when
662+
applying this optimization, even though there is an associated WAL
663+
record, because subsequent modifiers (e.g. an unrelated UPDATE) of the
664+
page may falsely believe that a full page image is not required.
648665

649666
Write-Ahead Logging for Filesystem Actions
650667
------------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp