Request XLOG switch before writing checkpoint in pg_start_backup(). Otherwise
commit9c8f673a5df02dfc74b335dc8bc3f4f23cb30661
authorheikki <heikki>
Thu, 7 May 2009 11:25:25 +0000 (7 11:25 +0000)
committerheikki <heikki>
Thu, 7 May 2009 11:25:25 +0000 (7 11:25 +0000)
tree0237009ef8e518aa3b3d2704dbff6ef71e8995be
parent643660edefb12c97615c927ad69624a26590647f
Request XLOG switch before writing checkpoint in pg_start_backup(). Otherwise
you can end up with an unrecoverable backup if you start a new base backup
right after finishing archive recovery. In that scenario, the redo pointer of
the checkpoint that pg_start_backup() writes points to the XLOG segment where
the timeline-changing end-of-archive-recovery checkpoint is. The beginning
of that segment contains pages with the old timeline ID, and we don't accept
that in recovery unless we find a history file covering the old timeline ID.
If you omit pg_xlog from the base backup and clear the archive directory
before starting the backup, there will be no such history file available.

The bug is present in all versions since PITR was introduced in 8.0, but I'm
back-patching only back to 8.2. Earlier versions didn't have XLOG switch
records, making this fix unfeasible. Given the lack of reports until now,
it doesn't seem worthwhile to spend more effort to fix 8.0 and 8.1.

Per report and suggestion by Mikael Krantz
src/backend/access/transam/xlog.c