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

Commit69c058f

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 parent436af24 commit69c058f

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
@@ -674,8 +674,9 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
674674
* with a warning.This is because even though ProcessUtility disallows
675675
* DROP TABLESPACE in a transaction block, it's possible that a previous
676676
* DROP failed and rolled back after removing the tablespace directories
677-
* and symlink. We want to allow a new DROP attempt to succeed at
678-
* removing the catalog entries, so we should not give a hard error here.
677+
* and/or symlink. We want to allow a new DROP attempt to succeed at
678+
* removing the catalog entries (and symlink if still present), so we
679+
* should not give a hard error here.
679680
*/
680681
dirdesc=AllocateDir(linkloc_with_version_dir);
681682
if (dirdesc==NULL)
@@ -687,8 +688,8 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
687688
(errcode_for_file_access(),
688689
errmsg("could not open directory \"%s\": %m",
689690
linkloc_with_version_dir)));
690-
pfree(linkloc_with_version_dir);
691-
return true;
691+
/* The symlink might still exist, so go try to remove it */
692+
gotoremove_symlink;
692693
}
693694
elseif (redo)
694695
{
@@ -751,8 +752,10 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
751752
* Windows where junction points lstat() as directories.
752753
*
753754
* Note: in the redo case, we'll return true if this final step fails;
754-
* there's no point in retrying it.
755+
* there's no point in retrying it. Also, ENOENT should provoke no more
756+
* than a warning.
755757
*/
758+
remove_symlink:
756759
linkloc=pstrdup(linkloc_with_version_dir);
757760
get_parent_directory(linkloc);
758761
if (lstat(linkloc,&st)==0&&S_ISDIR(st.st_mode))
@@ -766,7 +769,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
766769
else
767770
{
768771
if (unlink(linkloc)<0)
769-
ereport(redo ?LOG :ERROR,
772+
ereport(redo ?LOG :(errno==ENOENT ?WARNING :ERROR),
770773
(errcode_for_file_access(),
771774
errmsg("could not remove symbolic link \"%s\": %m",
772775
linkloc)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp