From: Tom Lane Date: Thu, 22 Mar 2007 19:51:44 +0000 (+0000) Subject: Allow DROP TABLESPACE to succeed (with a warning) if the pg_tblspc symlink X-Git-Tag: REL8_3_BETA1~996 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4127b713de3a655a0136bf53adceebf7b83d319;p=postgresql 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. --- diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c index 8e3bfbda86..16a9f52bd5 100644 --- a/src/backend/commands/tablespace.c +++ b/src/backend/commands/tablespace.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.44 2007/03/13 00:33:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.45 2007/03/22 19:51:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -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; }