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

Commitb834713

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 parent966970e commitb834713

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
@@ -678,8 +678,9 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
678678
* with a warning.This is because even though ProcessUtility disallows
679679
* DROP TABLESPACE in a transaction block, it's possible that a previous
680680
* DROP failed and rolled back after removing the tablespace directories
681-
* and symlink. We want to allow a new DROP attempt to succeed at
682-
* removing the catalog entries, so we should not give a hard error here.
681+
* and/or symlink. We want to allow a new DROP attempt to succeed at
682+
* removing the catalog entries (and symlink if still present), so we
683+
* should not give a hard error here.
683684
*/
684685
dirdesc=AllocateDir(linkloc_with_version_dir);
685686
if (dirdesc==NULL)
@@ -691,8 +692,8 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
691692
(errcode_for_file_access(),
692693
errmsg("could not open directory \"%s\": %m",
693694
linkloc_with_version_dir)));
694-
pfree(linkloc_with_version_dir);
695-
return true;
695+
/* The symlink might still exist, so go try to remove it */
696+
gotoremove_symlink;
696697
}
697698
elseif (redo)
698699
{
@@ -755,8 +756,10 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
755756
* Windows where junction points lstat() as directories.
756757
*
757758
* Note: in the redo case, we'll return true if this final step fails;
758-
* there's no point in retrying it.
759+
* there's no point in retrying it. Also, ENOENT should provoke no more
760+
* than a warning.
759761
*/
762+
remove_symlink:
760763
linkloc=pstrdup(linkloc_with_version_dir);
761764
get_parent_directory(linkloc);
762765
if (lstat(linkloc,&st)==0&&S_ISDIR(st.st_mode))
@@ -770,7 +773,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
770773
else
771774
{
772775
if (unlink(linkloc)<0)
773-
ereport(redo ?LOG :ERROR,
776+
ereport(redo ?LOG :(errno==ENOENT ?WARNING :ERROR),
774777
(errcode_for_file_access(),
775778
errmsg("could not remove symbolic link \"%s\": %m",
776779
linkloc)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp