为什么 Oracle DROP USER CASCADE 不从磁盘中删除用户的所有剩余部分?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35664354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't Oracle DROP USER CASCADE removing all remants of a user from disk?
提问by HereAndThere
I need to eliminate all remnants of specific users from an Oracle 11g R2 database. This means not only deleting the users one by one, but also deleting all objects associaated with that user, in addition to all physical remnants on the disk, such as .dbf
files.
我需要从 Oracle 11g R2 数据库中消除特定用户的所有残余。这意味着不仅要逐个删除用户,还要删除与该用户关联的所有对象,以及磁盘上的所有物理残留物,例如.dbf
文件。
I read several articles suggesting syntax for this, and settled on the following series of two lines for each user:
我阅读了几篇建议语法的文章,并为每个用户确定了以下两行系列:
DROP USER <username> CASCADE;
DROP TABLESPACE <username> INCLUDING CONTENTS AND DATAFILES;
I then typed SELECT USERNAME, DEFAULT_TABLESPACE FROM DBA_USERS;
and confirmed that the USER with the specific username was not included in the results.
然后我输入SELECT USERNAME, DEFAULT_TABLESPACE FROM DBA_USERS;
并确认具有特定用户名的 USER 未包含在结果中。
But I also have the folder containing the .DBF
files open, and I notice that the .DBF
files are not deleted even though the Oracle SQL Developer interface tells me that both of the two above commands succeeded.
但是我也.DBF
打开了包含文件的文件夹,我注意到即使 Oracle SQL Developer 界面告诉我上述两个命令都成功了,.DBF
文件也没有被删除。
What specific syntax or other actions do I need to take in order to delete EVERY remnant of the user and its associated schema, etc. from an Oracle 11g R2 database?
为了从 Oracle 11g R2 数据库中删除用户的所有残余及其关联的模式等,我需要采取哪些特定的语法或其他操作?
ONGOING RESEARCH:
正在进行的研究:
After reading @EliasGarcia's approach, I tried his first command select tablespace_name from dba_data_files where file_name = 'file_including_path'
for the same username that was used in the preceding commands in the OP. But this query did not produce any results because the table space was deleted by the two commands shown above in my OP.
阅读@EliasGarcia 的方法后,我尝试了他的第一个命令select tablespace_name from dba_data_files where file_name = 'file_including_path'
,该命令与 OP 中前面命令中使用的用户名相同。但是这个查询没有产生任何结果,因为我的 OP 中上面显示的两个命令删除了表空间。
Given that I have to delete the user and all objects related to the user also, can someone please show how to combine the OP approach with @EliasGarcia's approach? For example, the OP is asking for something like DROP USER username CASCADE INCLUDING CONTENTS AND DATAFILES;
鉴于我还必须删除用户以及与用户相关的所有对象,有人可以展示如何将 OP 方法与 @EliasGarcia 的方法结合起来吗?例如,OP 要求类似DROP USER username CASCADE INCLUDING CONTENTS AND DATAFILES;
I hesitate to simply delete the .dbf
files after running the above commands.
.dbf
运行上述命令后,我犹豫是否要删除文件。
回答by Elias Garcia
Datafiles are allocated to tablespaces, not users. Dropping the users will remove the tables etc. from the tablespace, but the underlying storage is not affected.
数据文件分配给表空间,而不是用户。删除用户将从表空间中删除表等,但不影响底层存储。
Don't delete the dbf files from the filesystem directly, you'll get your database into a mess. To remove them, find which tablespace the files belong to using the following statement:
不要直接从文件系统中删除 dbf 文件,你会让你的数据库变得一团糟。要删除它们,请使用以下语句查找文件属于哪个表空间:
select tablespace_name
from dba_data_files
where file_name = <file name with full path>;
You can then remove the file(s) by dropping the tablespace:
然后,您可以通过删除表空间来删除文件:
drop tablespace <tablespace_name> including contents and datafiles;
Before doing this you should verify that there aren't any objects still allocated to the tablespace for other users however. You can find this by running:
在执行此操作之前,您应该确认没有任何对象仍然分配给其他用户的表空间。您可以通过运行找到它:
select * from dba_segments
where tablespace_name = <tablespace to drop>;
If this returns anything, move the objects to another tablespace if you want to keep them before dropping the tablespace.
如果这返回任何内容,如果您想在删除表空间之前保留它们,请将对象移动到另一个表空间。