Skip to content

Commit ffe8c7c

Browse files
committed
Need to hold ControlFileLock while updating control file. Update
minRecoveryPoint in control file when replaying a parameter change record, to ensure that we don't allow hot standby on WAL generated without wal_level='hot_standby' after a standby restart.
1 parent c0de88c commit ffe8c7c

File tree

1 file changed

+18
-1
lines changed
  • src/backend/access/transam

1 file changed

+18
-1
lines changed

src/backend/access/transam/xlog.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.408 2010/05/02 02:10:33 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.409 2010/05/03 11:17:52 heikki Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -7920,11 +7920,28 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
79207920
/* Update our copy of the parameters in pg_control */
79217921
memcpy(&xlrec, XLogRecGetData(record), sizeof(xl_parameter_change));
79227922

7923+
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
79237924
ControlFile->MaxConnections = xlrec.MaxConnections;
79247925
ControlFile->max_prepared_xacts = xlrec.max_prepared_xacts;
79257926
ControlFile->max_locks_per_xact = xlrec.max_locks_per_xact;
79267927
ControlFile->wal_level = xlrec.wal_level;
7928+
/*
7929+
* Update minRecoveryPoint to ensure that if recovery is aborted,
7930+
* we recover back up to this point before allowing hot standby
7931+
* again. This is particularly important if wal_level was set to
7932+
* 'archive' before, and is now 'hot_standby', to ensure you don't
7933+
* run queries against the WAL preceding the wal_level change.
7934+
* Same applies to decreasing max_* settings.
7935+
*/
7936+
minRecoveryPoint = ControlFile->minRecoveryPoint;
7937+
if ((minRecoveryPoint.xlogid != 0 || minRecoveryPoint.xrecoff != 0)
7938+
&& XLByteLT(minRecoveryPoint, lsn))
7939+
{
7940+
ControlFile->minRecoveryPoint = lsn;
7941+
}
7942+
79277943
UpdateControlFile();
7944+
LWLockRelease(ControlFileLock);
79287945

79297946
/* Check to see if any changes to max_connections give problems */
79307947
CheckRequiredParameterValues();

0 commit comments

Comments
 (0)