diff options
Diffstat (limited to 'src/backend/storage/smgr/md.c')
-rw-r--r-- | src/backend/storage/smgr/md.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index a761369d39c..7150a00407e 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -323,7 +323,13 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo) * number until it's safe, because relfilenode assignment skips over any * existing file. * - * If isRedo is true, it's okay for the relation to be already gone. + * All the above applies only to the relation's main fork; other forks can + * just be removed immediately, since they are not needed to prevent the + * relfilenode number from being recycled. Also, we do not carefully + * track whether other forks have been created or not, but just attempt to + * unlink them unconditionally; so we should never complain about ENOENT. + * + * If isRedo is true, it's unsurprising for the relation to be already gone. * Also, we should remove the file immediately instead of queuing a request * for later, since during redo there's no possibility of creating a * conflicting relation. @@ -351,13 +357,10 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo) if (isRedo || forkNum != MAIN_FORKNUM) { ret = unlink(path); - if (ret < 0) - { - if (!isRedo || errno != ENOENT) - ereport(WARNING, - (errcode_for_file_access(), - errmsg("could not remove file \"%s\": %m", path))); - } + if (ret < 0 && errno != ENOENT) + ereport(WARNING, + (errcode_for_file_access(), + errmsg("could not remove file \"%s\": %m", path))); } else { @@ -380,6 +383,9 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo) ereport(WARNING, (errcode_for_file_access(), errmsg("could not truncate file \"%s\": %m", path))); + + /* Register request to unlink first segment later */ + register_unlink(rnode); } /* @@ -411,10 +417,6 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo) } pfree(path); - - /* Register request to unlink first segment later */ - if (!isRedo && forkNum == MAIN_FORKNUM) - register_unlink(rnode); } /* |