Skip to content

Commit a4127b7

Browse files
committed
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.
1 parent 832b6d0 commit a4127b7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/backend/commands/tablespace.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.44 2007/03/13 00:33:40 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.45 2007/03/22 19:51:44 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -523,12 +523,25 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
523523
* fresh subdirectories in parallel. It is possible that new files are
524524
* being created within subdirectories, though, so the rmdir call could
525525
* fail. Worst consequence is a less friendly error message.
526+
*
527+
* If redo is true then ENOENT is a likely outcome here, and we allow it
528+
* to pass without comment. In normal operation we still allow it, but
529+
* with a warning. This is because even though ProcessUtility disallows
530+
* DROP TABLESPACE in a transaction block, it's possible that a previous
531+
* DROP failed and rolled back after removing the tablespace directories
532+
* and symlink. We want to allow a new DROP attempt to succeed at
533+
* removing the catalog entries, so we should not give a hard error here.
526534
*/
527535
dirdesc = AllocateDir(location);
528536
if (dirdesc == NULL)
529537
{
530-
if (redo && errno == ENOENT)
538+
if (errno == ENOENT)
531539
{
540+
if (!redo)
541+
ereport(WARNING,
542+
(errcode_for_file_access(),
543+
errmsg("could not open directory \"%s\": %m",
544+
location)));
532545
pfree(location);
533546
return true;
534547
}

0 commit comments

Comments
 (0)