git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6fcaeb0)
Improve truncation of pg_serial/, removing "apparent wraparound" LOGs
2023年10月17日 05:36:04 +0000 (14:36 +0900)
2023年10月17日 05:36:21 +0000 (14:36 +0900)
It is possible that the tail XID of pg_serial/ gets ahead of its head
XID, which would cause the truncation of pg_serial/ done during
checkpoints to show up as a "wraparound" LOG in SimpleLruTruncate(),
which is confusing. This also wastes a bit of disk space until the head
page is reclaimed again.

CheckPointPredicate() is changed so as the cutoff page for the
truncation is switched to the head page if the tail XID has advanced
beyond the head XID, rather than the tail page. This prevents the
confusing LOG message about a wraparound while allowing some truncation
to be done to cut in disk space.

This could be considered as a bug fix, but the original behavior is
harmless as well, resulting only in disk space temporarily wasted, so
no backpatch is done.

Author: Sami Imseih
Reviewed-by: Heikki Linnakangas, Michael Paquier
Discussion: https://postgr.es/m/755E19CA-D02C-4A4C-80D3-74F775410C48@amazon.com


diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index 1af41213b41be783ed5461c089756813d87c3062..a794546db3e6d1cec6cf20440e691530234c44e0 100644 (file)
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -1004,7 +1004,7 @@ SerialSetActiveSerXmin(TransactionId xid)
void
CheckPointPredicate(void)
{
- int tailPage;
+ int truncateCutoffPage;
LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
@@ -1017,8 +1017,24 @@ CheckPointPredicate(void)
if (TransactionIdIsValid(serialControl->tailXid))
{
- /* We can truncate the SLRU up to the page containing tailXid */
+ int tailPage;
+
tailPage = SerialPage(serialControl->tailXid);
+
+ /*
+ * It is possible for the tailXid to be ahead of the headXid. This
+ * occurs if we checkpoint while there are in-progress serializable
+ * transaction(s) advancing the tail but we are yet to summarize the
+ * transactions. In this case, we cutoff up to the headPage and the
+ * next summary will advance the headXid.
+ */
+ if (SerialPagePrecedesLogically(tailPage, serialControl->headPage))
+ {
+ /* We can truncate the SLRU up to the page containing tailXid */
+ truncateCutoffPage = tailPage;
+ }
+ else
+ truncateCutoffPage = serialControl->headPage;
}
else
{
@@ -1051,14 +1067,14 @@ CheckPointPredicate(void)
* transaction instigating the summarize fails in
* SimpleLruReadPage().
*/
- tailPage = serialControl->headPage;
+ truncateCutoffPage = serialControl->headPage;
serialControl->headPage = -1;
}
LWLockRelease(SerialSLRULock);
/* Truncate away pages that are no longer required */
- SimpleLruTruncate(SerialSlruCtl, tailPage);
+ SimpleLruTruncate(SerialSlruCtl, truncateCutoffPage);
/*
* Write dirty SLRU pages to disk
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /