Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1d577f5

Browse files
committed
Add a startup check that pg_xlog and pg_xlog/archive_status exist.
If the latter doesn't exist, automatically recreate it. (We don't do this for pg_xlog, though, per discussion.) Jonah Harris
1 parent dbf57d3 commit 1d577f5

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

doc/src/sgml/backup.sgml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.120 2008/07/18 17:33:17 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.121 2008/11/09 17:51:15 tgl Exp $ -->
22

33
<chapter id="backup">
44
<title>Backup and Restore</title>
@@ -945,8 +945,6 @@ SELECT pg_stop_backup();
945945
If you didn't archive <filename>pg_xlog/</> at all, then recreate it,
946946
being careful to ensure that you re-establish it as a symbolic link
947947
if you had it set up that way before.
948-
Be sure to recreate the subdirectory
949-
<filename>pg_xlog/archive_status/</> as well.
950948
</para>
951949
</listitem>
952950
<listitem>

src/backend/access/transam/xlog.c

+56-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, 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.321 2008/10/31 15:04:59 heikki Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.322 2008/11/09 17:51:15 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -416,6 +416,7 @@ static bool RestoreArchivedFile(char *path, const char *xlogfname,
416416
const char *recovername, off_t expectedSize);
417417
static void PreallocXlogFiles(XLogRecPtr endptr);
418418
static void RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr);
419+
static void ValidateXLOGDirectoryStructure(void);
419420
static void CleanupBackupHistory(void);
420421
static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode);
421422
static bool ValidXLOGHeader(XLogPageHeader hdr, int emode);
@@ -2824,6 +2825,53 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
28242825
FreeDir(xldir);
28252826
}
28262827

2828+
/*
2829+
* Verify whether pg_xlog and pg_xlog/archive_status exist.
2830+
* If the latter does not exist, recreate it.
2831+
*
2832+
* It is not the goal of this function to verify the contents of these
2833+
* directories, but to help in cases where someone has performed a cluster
2834+
* copy for PITR purposes but omitted pg_xlog from the copy.
2835+
*
2836+
* We could also recreate pg_xlog if it doesn't exist, but a deliberate
2837+
* policy decision was made not to. It is fairly common for pg_xlog to be
2838+
* a symlink, and if that was the DBA's intent then automatically making a
2839+
* plain directory would result in degraded performance with no notice.
2840+
*/
2841+
static void
2842+
ValidateXLOGDirectoryStructure(void)
2843+
{
2844+
char path[MAXPGPATH];
2845+
struct stat stat_buf;
2846+
2847+
/* Check for pg_xlog; if it doesn't exist, error out */
2848+
if (stat(XLOGDIR, &stat_buf) != 0 ||
2849+
!S_ISDIR(stat_buf.st_mode))
2850+
ereport(FATAL,
2851+
(errmsg("required WAL directory \"%s\" does not exist",
2852+
XLOGDIR)));
2853+
2854+
/* Check for archive_status */
2855+
snprintf(path, MAXPGPATH, XLOGDIR "/archive_status");
2856+
if (stat(path, &stat_buf) == 0)
2857+
{
2858+
/* Check for weird cases where it exists but isn't a directory */
2859+
if (!S_ISDIR(stat_buf.st_mode))
2860+
ereport(FATAL,
2861+
(errmsg("required WAL directory \"%s\" does not exist",
2862+
path)));
2863+
}
2864+
else
2865+
{
2866+
ereport(LOG,
2867+
(errmsg("creating missing WAL directory \"%s\"", path)));
2868+
if (mkdir(path, 0700) < 0)
2869+
ereport(FATAL,
2870+
(errmsg("could not create missing directory \"%s\": %m",
2871+
path)));
2872+
}
2873+
}
2874+
28272875
/*
28282876
* Remove previous backup history files. This also retries creation of
28292877
* .ready files for any backup history files for which XLogArchiveNotify
@@ -4878,6 +4926,13 @@ StartupXLOG(void)
48784926
pg_usleep(60000000L);
48794927
#endif
48804928

4929+
/*
4930+
* Verify that pg_xlog and pg_xlog/archive_status exist. In cases where
4931+
* someone has performed a copy for PITR, these directories may have
4932+
* been excluded and need to be re-created.
4933+
*/
4934+
ValidateXLOGDirectoryStructure();
4935+
48814936
/*
48824937
* Initialize on the assumption we want to recover to the same timeline
48834938
* that's active according to pg_control.

0 commit comments

Comments
 (0)