* that have already been truncated from the commit log. Easiest way
* to deal with that is to accept references to nonexistent files here
* and in CLOGPhysicalReadPage.)
+ *
+ * Note: it is possible for more than one backend to be executing
+ * this code simultaneously for different pages of the same file.
+ * Hence, don't use O_EXCL or O_TRUNC or anything like that.
*/
- fd = BasicOpenFile(path, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
+ fd = BasicOpenFile(path, O_RDWR | O_CREAT | PG_BINARY,
+ S_IRUSR | S_IWUSR);
if (fd < 0)
- {
- if (errno != ENOENT)
- elog(PANIC, "open of %s failed: %m", path);
- fd = BasicOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
- S_IRUSR | S_IWUSR);
- if (fd < 0)
- elog(PANIC, "creation of file %s failed: %m", path);
- }
+ elog(PANIC, "open of %s failed: %m", path);
if (lseek(fd, (off_t) offset, SEEK_SET) < 0)
elog(PANIC, "lseek of clog file %u, offset %u failed: %m",