Skip to content

Commit cb822ff

Browse files
committed
Rework activation of commit timestamps during recovery
The activation and deactivation of commit timestamp tracking has not been handled consistently for a primary or standbys at recovery. The facility can be activated at three different moments of recovery: - The beginning, where a primary would use the GUC value for the decision-making, and where a standby relies on the contents of the control file. - When replaying a XLOG_PARAMETER_CHANGE record at redo. - The end, where both primary and standby rely on the GUC value. Using the GUC value for a primary at the beginning of recovery causes problems with commit timestamp access when doing crash recovery. Particularly, when replaying transaction commits, it could be possible that an attempt to read commit timestamps is done for a transaction which committed at a moment when track_commit_timestamp was disabled. A test case is added to reproduce the failure. The test works down to v11 as it takes advantage of transaction commits within procedures. Reported-by: Hailong Li Author: Masahiko Sawasa, Michael Paquier Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/11224478-a782-203b-1f17-e4797b39bdf0@qunar.com Backpatch-through: 9.5, where commit timestamps have been introduced.
1 parent 21c8f9c commit cb822ff

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/backend/access/transam/commit_ts.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,9 @@ CompleteCommitTsInitialization(void)
573573
* any leftover data.
574574
*
575575
* Conversely, we activate the module if the feature is enabled. This is
576-
* not necessary in a master system because we already did it earlier, but
577-
* if we're in a standby server that got promoted which had the feature
578-
* enabled and was following a master that had the feature disabled, this
579-
* is where we turn it on locally.
576+
* necessary for primary and standby as the activation depends on the
577+
* control file contents at the beginning of recovery or when a
578+
* XLOG_PARAMETER_CHANGE is replayed.
580579
*/
581580
if (!track_commit_timestamp)
582581
DeactivateCommitTs();
@@ -586,7 +585,7 @@ CompleteCommitTsInitialization(void)
586585

587586
/*
588587
* Activate or deactivate CommitTs' upon reception of a XLOG_PARAMETER_CHANGE
589-
* XLog record in a standby.
588+
* XLog record during recovery.
590589
*/
591590
void
592591
CommitTsParameterChange(bool newvalue, bool oldvalue)

src/backend/access/transam/xlog.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6719,11 +6719,12 @@ StartupXLOG(void)
67196719
StartupMultiXact();
67206720

67216721
/*
6722-
* Ditto commit timestamps. In a standby, we do it if setting is enabled
6723-
* in ControlFile; in a master we base the decision on the GUC itself.
6722+
* Ditto for commit timestamps. Activate the facility if the setting is
6723+
* enabled in the control file, as there should be no tracking of commit
6724+
* timestamps done when the setting was disabled. This facility can be
6725+
* started or stopped when replaying a XLOG_PARAMETER_CHANGE record.
67246726
*/
6725-
if (ArchiveRecoveryRequested ?
6726-
ControlFile->track_commit_timestamp : track_commit_timestamp)
6727+
if (ControlFile->track_commit_timestamp)
67276728
StartupCommitTs();
67286729

67296730
/*

0 commit comments

Comments
 (0)