aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/bufmgr.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-03-24 14:38:51 -0400
committerRobert Haas <rhaas@postgresql.org>2022-03-24 14:38:51 -0400
commit3821d66a7b3e913d750a3314fd8a560d374af575 (patch)
tree73c4e5f0a61cb77821d82a4c7feb9bb5cb88991e /src/backend/storage/buffer/bufmgr.c
parent61a007feed526f2acde4822e27a599cb0a734dfe (diff)
downloadpostgresql-3821d66a7b3e913d750a3314fd8a560d374af575.tar.gz
postgresql-3821d66a7b3e913d750a3314fd8a560d374af575.zip
Fix possible recovery trouble if TRUNCATE overlaps a checkpoint.
If TRUNCATE causes some buffers to be invalidated and thus the checkpoint does not flush them, TRUNCATE must also ensure that the corresponding files are truncated on disk. Otherwise, a replay from the checkpoint might find that the buffers exist but have the wrong contents, which may cause replay to fail. Report by Teja Mupparti. Patch by Kyotaro Horiguchi, per a design suggestion from Heikki Linnakangas, with some changes to the comments by me. Review of this and a prior patch that approached the issue differently by Heikki Linnakangas, Andres Freund, Álvaro Herrera, Masahiko Sawada, and Tom Lane. Discussion: http://postgr.es/m/BYAPR06MB6373BF50B469CA393C614257ABF00@BYAPR06MB6373.namprd06.prod.outlook.com
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r--src/backend/storage/buffer/bufmgr.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 01c09fd532b..7d11b0963f3 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -3514,7 +3514,9 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
* essential that CreateCheckpoint waits for virtual transactions
* rather than full transactionids.
*/
- MyPgXact->delayChkpt = delayChkpt = true;
+ Assert((MyPgXact->delayChkpt & DELAY_CHKPT_START) == 0);
+ MyPgXact->delayChkpt |= DELAY_CHKPT_START;
+ delayChkpt = true;
lsn = XLogSaveBufferForHint(buffer, buffer_std);
}
@@ -3547,7 +3549,7 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
UnlockBufHdr(bufHdr, buf_state);
if (delayChkpt)
- MyPgXact->delayChkpt = false;
+ MyPgXact->delayChkpt &= ~DELAY_CHKPT_START;
if (dirtied)
{