Skip to content

Commit 57cb806

Browse files
committed
Fix locking bugs that could corrupt pg_control.
The redo routines for XLOG_CHECKPOINT_{ONLINE,SHUTDOWN} must acquire ControlFileLock before modifying ControlFile->checkPointCopy, or the checkpointer could write out a control file with a bad checksum. Likewise, XLogReportParameters() must acquire ControlFileLock before modifying ControlFile and calling UpdateControlFile(). Back-patch to all supported releases. Author: Nathan Bossart <bossartn@amazon.com> Author: Fujii Masao <masao.fujii@oss.nttdata.com> Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/70BF24D6-DC51-443F-B55A-95735803842A%40amazon.com
1 parent d094bf9 commit 57cb806

File tree

1 file changed

+8
-0
lines changed
  • src/backend/access/transam

1 file changed

+8
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9743,6 +9743,8 @@ XLogReportParameters(void)
97439743
XLogFlush(recptr);
97449744
}
97459745

9746+
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
9747+
97469748
ControlFile->MaxConnections = MaxConnections;
97479749
ControlFile->max_worker_processes = max_worker_processes;
97489750
ControlFile->max_wal_senders = max_wal_senders;
@@ -9752,6 +9754,8 @@ XLogReportParameters(void)
97529754
ControlFile->wal_log_hints = wal_log_hints;
97539755
ControlFile->track_commit_timestamp = track_commit_timestamp;
97549756
UpdateControlFile();
9757+
9758+
LWLockRelease(ControlFileLock);
97559759
}
97569760
}
97579761

@@ -9976,7 +9980,9 @@ xlog_redo(XLogReaderState *record)
99769980
}
99779981

99789982
/* ControlFile->checkPointCopy always tracks the latest ckpt XID */
9983+
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
99799984
ControlFile->checkPointCopy.nextFullXid = checkPoint.nextFullXid;
9985+
LWLockRelease(ControlFileLock);
99809986

99819987
/* Update shared-memory copy of checkpoint XID/epoch */
99829988
SpinLockAcquire(&XLogCtl->info_lck);
@@ -10033,7 +10039,9 @@ xlog_redo(XLogReaderState *record)
1003310039
SetTransactionIdLimit(checkPoint.oldestXid,
1003410040
checkPoint.oldestXidDB);
1003510041
/* ControlFile->checkPointCopy always tracks the latest ckpt XID */
10042+
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
1003610043
ControlFile->checkPointCopy.nextFullXid = checkPoint.nextFullXid;
10044+
LWLockRelease(ControlFileLock);
1003710045

1003810046
/* Update shared-memory copy of checkpoint XID/epoch */
1003910047
SpinLockAcquire(&XLogCtl->info_lck);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy