From 1a8a2b34a8f3584dadd1384fde9fc511fe1a82a4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 22 Mar 2007 19:51:44 +0000 Subject: [PATCH] Allow DROP TABLESPACE to succeed (with a warning) if the pg_tblspc symlink doesn't exist. This allows DROP to be used to clean out the pg_tablespace catalog entry in a situation where a previous DROP attempt failed before committing but after having removed the directories and symlink. Per report from William Garrison. Even though his test case depends on an unrelated bug in PreventTransactionChain, it's certainly possible for this situation to arise due to other problems, eg a system crash at just the right time. --- src/backend/commands/tablespace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index eb13f48b0f..55b11b3486 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -523,12 +523,25 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo) * fresh subdirectories in parallel. It is possible that new files are * being created within subdirectories, though, so the rmdir call could * fail. Worst consequence is a less friendly error message. + * + * If redo is true then ENOENT is a likely outcome here, and we allow it + * to pass without comment. In normal operation we still allow it, but + * with a warning. This is because even though ProcessUtility disallows + * DROP TABLESPACE in a transaction block, it's possible that a previous + * DROP failed and rolled back after removing the tablespace directories + * and symlink. We want to allow a new DROP attempt to succeed at + * removing the catalog entries, so we should not give a hard error here. */ dirdesc = AllocateDir(location); if (dirdesc == NULL) { - if (redo && errno == ENOENT) + if (errno == ENOENT) { + if (!redo) + ereport(WARNING, + (errcode_for_file_access(), + errmsg("could not open directory \"%s\": %m", + location))); pfree(location); return true; } -- 2.39.5