diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 77d254ccd4..d7f0ae43c0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.258.2.4 2008/05/13 20:54:00 mha Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.258.2.5 2009/05/07 11:25:32 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -6189,6 +6189,19 @@ pg_start_backup(PG_FUNCTION_ARGS) XLogCtl->Insert.forcePageWrites = true; LWLockRelease(WALInsertLock); + /* + * Force an XLOG file switch before the checkpoint, to ensure that the WAL + * segment the checkpoint is written to doesn't contain pages with old + * timeline IDs. That would otherwise happen if you called + * pg_start_backup() right after restoring from a PITR archive: the first + * WAL segment containing the startup checkpoint has pages in the + * beginning with the old timeline ID. That can cause trouble at recovery: + * we won't have a history file covering the old timeline if pg_xlog + * directory was not included in the base backup and the WAL archive was + * cleared too before starting the backup. + */ + RequestXLogSwitch(); + /* Ensure we release forcePageWrites if fail below */ PG_ENSURE_ERROR_CLEANUP(pg_start_backup_callback, (Datum) 0); {