diff --git a/src/backend/access/appendonly/aomd.c b/src/backend/access/appendonly/aomd.c index 342e7771b7b..1c47339c514 100644 --- a/src/backend/access/appendonly/aomd.c +++ b/src/backend/access/appendonly/aomd.c @@ -256,6 +256,7 @@ struct truncate_ao_callback_ctx void mdunlink_ao(RelFileNodeBackend rnode, ForkNumber forkNumber, bool isRedo) { + int ret; const char *path = relpath(rnode, forkNumber); /* @@ -294,6 +295,19 @@ mdunlink_ao(RelFileNodeBackend rnode, ForkNumber forkNumber, bool isRedo) pfree(segPath); } + /* + * Delete or truncate the first segment. See mdunlinkfork also. + */ + if (RelFileNodeBackendIsTemp(rnode)) + { + /* Next unlink the file, unless it was already found to be missing */ + ret = unlink(path); + if (ret < 0 && errno != ENOENT) + ereport(WARNING, + (errcode_for_file_access(), + errmsg("could not remove file \"%s\": %m", path))); + } + pfree((void *) path); }