diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-12-30 14:26:47 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-12-30 14:29:45 +0200 |
commit | 60df192aea0e6458f20301546e11f7673c102101 (patch) | |
tree | 07d5bacf98d8223ab79363b859ac60b13fd84ab7 /src/backend/access/transam/xlog.c | |
parent | 103cc89362accb04cf37a9063e51eac04d489e89 (diff) | |
download | postgresql-60df192aea0e6458f20301546e11f7673c102101.tar.gz postgresql-60df192aea0e6458f20301546e11f7673c102101.zip |
Keep timeline history files restored from archive in pg_xlog.
The cascading standby patch in 9.2 changed the way WAL files are treated
when restored from the archive. Before, they were restored under a temporary
filename, and not kept in pg_xlog, but after the patch, they were copied
under pg_xlog. This is necessary for a cascading standby to find them, but
it also means that if the archive goes offline and a standby is restarted,
it can recover back to where it was using the files in pg_xlog. It also
means that if you take an offline backup from a standby server, it includes
all the required WAL files in pg_xlog.
However, the same change was not made to timeline history files, so if the
WAL segment containing the checkpoint record contains a timeline switch, you
will still get an error if you try to restart recovery without the archive,
or recover from an offline backup taken from the standby.
With this patch, timeline history files restored from archive are copied
into pg_xlog like WAL files are, so that pg_xlog contains all the files
required to recover. This is a corner-case pre-existing issue in 9.2, but
even more important in master where it's possible for a standby to follow a
timeline switch through streaming replication. To make that possible, the
timeline history files must be present in pg_xlog.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 2998f60c5f9..aebdf0b85ab 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2626,68 +2626,12 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, */ if (source == XLOG_FROM_ARCHIVE) { - char xlogfpath[MAXPGPATH]; - bool reload = false; - struct stat statbuf; - - XLogFilePath(xlogfpath, tli, segno); - if (stat(xlogfpath, &statbuf) == 0) - { - char oldpath[MAXPGPATH]; -#ifdef WIN32 - static unsigned int deletedcounter = 1; - /* - * On Windows, if another process (e.g a walsender process) holds - * the file open in FILE_SHARE_DELETE mode, unlink will succeed, - * but the file will still show up in directory listing until the - * last handle is closed, and we cannot rename the new file in its - * place until that. To avoid that problem, rename the old file to - * a temporary name first. Use a counter to create a unique - * filename, because the same file might be restored from the - * archive multiple times, and a walsender could still be holding - * onto an old deleted version of it. - */ - snprintf(oldpath, MAXPGPATH, "%s.deleted%u", - xlogfpath, deletedcounter++); - if (rename(xlogfpath, oldpath) != 0) - { - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not rename file \"%s\" to \"%s\": %m", - xlogfpath, oldpath))); - } -#else - strncpy(oldpath, xlogfpath, MAXPGPATH); -#endif - if (unlink(oldpath) != 0) - ereport(FATAL, - (errcode_for_file_access(), - errmsg("could not remove file \"%s\": %m", - xlogfpath))); - reload = true; - } - - if (rename(path, xlogfpath) < 0) - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not rename file \"%s\" to \"%s\": %m", - path, xlogfpath))); + KeepFileRestoredFromArchive(path, xlogfname); /* * Set path to point at the new file in pg_xlog. */ - strncpy(path, xlogfpath, MAXPGPATH); - - /* - * If the existing segment was replaced, since walsenders might have - * it open, request them to reload a currently-open segment. - */ - if (reload) - WalSndRqstFileReload(); - - /* Signal walsender that new WAL has arrived */ - if (AllowCascadeReplication()) - WalSndWakeup(); + snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname); } fd = BasicOpenFile(path, O_RDONLY | PG_BINARY, 0); |