OSDN Git Service

Allow DROP TABLESPACE to succeed (with a warning) if the pg_tblspc symlink
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Mar 2007 19:51:44 +0000 (19:51 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 Mar 2007 19:51:44 +0000 (19:51 +0000)
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

index 8e3bfbd..16a9f52 100644 (file)
@@ -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;
                }