diff -cr pgsql/src/backend/access/transam/xlog.c pgsql-arcstatdir/src/backend/access/transam/xlog.c *** pgsql/src/backend/access/transam/xlog.c Fri Oct 31 11:04:59 2008 --- pgsql-arcstatdir/src/backend/access/transam/xlog.c Sat Nov 8 15:13:20 2008 *************** *** 438,444 **** XLogRecPtr *minRecoveryLoc); static void rm_redo_error_callback(void *arg); static int get_sync_bit(int method); ! /* * Insert an XLOG record having the specified RMID and info bytes, --- 438,444 ---- XLogRecPtr *minRecoveryLoc); static void rm_redo_error_callback(void *arg); static int get_sync_bit(int method); ! static void ValidateXLOGDirectoryStructure(void); /* * Insert an XLOG record having the specified RMID and info bytes, *************** *** 2825,2830 **** --- 2825,2874 ---- } /* + * The purpose of this procedure is to verify whether pg_xlog and + * pg_xlog/archive_status exist and if not, attempt to recreate them. It + * is not the goal of this procedure to verify the contents of these + * directories, instead the directories themsleves are created for the + * case where someone has performed a cluster copy for PITR purposes and has + * omitted pg_xlog. + */ + static void + ValidateXLOGDirectoryStructure(void) + { + int i; + char path[MAXPGPATH]; + struct stat stat_buf; + static const char *xlogdirs[] = {XLOGDIR, XLOGDIR "/archive_status"}; + + for (i = 0; i < (sizeof(xlogdirs) / sizeof(char *)); i++) + { + /* Check for a pre-existing directory */ + snprintf(path, MAXPGPATH, "%s", xlogdirs[i]); + if (stat(path, &stat_buf) == 0) + { + if (!S_ISDIR(stat_buf.st_mode)) + { + ereport(ERROR, + (errmsg("an invalid filesystem object was found where directory \"%s\" was expected", + path))); + } + } + else + { + ereport(LOG, + (errmsg("recreating missing WAL directory \"%s\"", path))); + + if (mkdir(path, 0700) < 0) + { + ereport(ERROR, + (errmsg("could not create missing directory \"%s\"", + path))); + } + } + } + } + + /* * Remove previous backup history files. This also retries creation of * .ready files for any backup history files for which XLogArchiveNotify * failed earlier. *************** *** 4879,4884 **** --- 4923,4935 ---- #endif /* + * Verify that pg_xlog and pg_xlog/archive_status exist. In cases where + * someone has performed a copy for PITR, these directories may have + * been excluded and need to be re-created. + */ + ValidateXLOGDirectoryStructure(); + + /* * Initialize on the assumption we want to recover to the same timeline * that's active according to pg_control. */