Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d577f5

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 dothis for pg_xlog, though, per discussion.)Jonah Harris
1 parentdbf57d3 commit1d577f5

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

‎doc/src/sgml/backup.sgml

Lines changed: 1 addition & 3 deletions
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

Lines changed: 56 additions & 1 deletion
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
constchar*recovername,off_texpectedSize);
417417
staticvoidPreallocXlogFiles(XLogRecPtrendptr);
418418
staticvoidRemoveOldXlogFiles(uint32log,uint32seg,XLogRecPtrendptr);
419+
staticvoidValidateXLOGDirectoryStructure(void);
419420
staticvoidCleanupBackupHistory(void);
420421
staticXLogRecord*ReadRecord(XLogRecPtr*RecPtr,intemode);
421422
staticboolValidXLOGHeader(XLogPageHeaderhdr,intemode);
@@ -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+
staticvoid
2842+
ValidateXLOGDirectoryStructure(void)
2843+
{
2844+
charpath[MAXPGPATH];
2845+
structstatstat_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)

[8]ページ先頭

©2009-2025 Movatter.jp