Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82992a4

Browse files
committed
Fix DROP TABLESPACE to unlink symlink when directory is not there.
If the tablespace directory is missing entirely, we allow DROP TABLESPACEto go through, on the grounds that it should be possible to clean up thecatalog entry in such a situation. However, we forgot that the pg_tblspcsymlink might still be there. We should try to remove the symlink too(but not fail if it's no longer there), since not doing so can lead toweird behavior subsequently, as per report from Michael Nolan.There was some discussion of adding dependency links to prevent DROPTABLESPACE when the catalogs still contain references to the tablespace.That might be worth doing too, but it's an orthogonal question, and inany case wouldn't be back-patchable.Back-patch to 9.0, which is as far back as the logic looks like this.We could possibly do something similar in 8.x, but given the lack ofreports I'm not sure it's worth the trouble, and anyway the case couldnot arise in the form the logic is meant to cover (namely, a post-DROPtransaction rollback having resurrected the pg_tablespace entry aftersome or all of the filesystem infrastructure is gone).
1 parent37edecf commit82992a4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎src/backend/commands/tablespace.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
669669
* with a warning.This is because even though ProcessUtility disallows
670670
* DROP TABLESPACE in a transaction block, it's possible that a previous
671671
* DROP failed and rolled back after removing the tablespace directories
672-
* and symlink. We want to allow a new DROP attempt to succeed at
673-
* removing the catalog entries, so we should not give a hard error here.
672+
* and/or symlink. We want to allow a new DROP attempt to succeed at
673+
* removing the catalog entries (and symlink if still present), so we
674+
* should not give a hard error here.
674675
*/
675676
dirdesc=AllocateDir(linkloc_with_version_dir);
676677
if (dirdesc==NULL)
@@ -682,8 +683,8 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
682683
(errcode_for_file_access(),
683684
errmsg("could not open directory \"%s\": %m",
684685
linkloc_with_version_dir)));
685-
pfree(linkloc_with_version_dir);
686-
return true;
686+
/* The symlink might still exist, so go try to remove it */
687+
gotoremove_symlink;
687688
}
688689
elseif (redo)
689690
{
@@ -746,8 +747,10 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
746747
* Windows where junction points lstat() as directories.
747748
*
748749
* Note: in the redo case, we'll return true if this final step fails;
749-
* there's no point in retrying it.
750+
* there's no point in retrying it. Also, ENOENT should provoke no more
751+
* than a warning.
750752
*/
753+
remove_symlink:
751754
linkloc=pstrdup(linkloc_with_version_dir);
752755
get_parent_directory(linkloc);
753756
if (lstat(linkloc,&st)==0&&S_ISDIR(st.st_mode))
@@ -761,7 +764,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
761764
else
762765
{
763766
if (unlink(linkloc)<0)
764-
ereport(redo ?LOG :ERROR,
767+
ereport(redo ?LOG :(errno==ENOENT ?WARNING :ERROR),
765768
(errcode_for_file_access(),
766769
errmsg("could not remove symbolic link \"%s\": %m",
767770
linkloc)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp