diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c index fa9940da9b..c6b210d137 100644 --- a/src/backend/storage/file/buffile.c +++ b/src/backend/storage/file/buffile.c @@ -211,6 +211,16 @@ MakeNewSharedSegment(BufFile *buffile, int segment) char name[MAXPGPATH]; File file; + /* + * It is possible that there are files left over from before a crash + * restart with the same name. In order for BufFileOpenShared() + * not to get confused about how many segments there are, we'll unlink + * the next segment number if it already exists. + */ + SharedSegmentName(name, buffile->name, segment + 1); + SharedFileSetDelete(buffile->fileset, name, true); + + /* Create the new segment. */ SharedSegmentName(name, buffile->name, segment); file = SharedFileSetCreate(buffile->fileset, name); @@ -303,7 +313,9 @@ BufFileOpenShared(SharedFileSet *fileset, const char *name) * name. */ if (nfiles == 0) - return NULL; + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not open BufFile \"%s\"", name))); file->numFiles = nfiles; file->files = files;