oracle删除用户数据
★--仅仅是删除用户drop user user_name;
★--会删除此用户名下的所有表和视图。如果对象很多,那么会删除很慢,可能1个小时才能删除3000-4000张表,如果有几十万张表可能删除大半天可能都删除不完。
oracle对象有:1、表(Table);2、索引(Index);3、簇(Cluster);4、视图;5、Synonym;6、序列(Sequence);7、过程(Procedure)和函数(Function);8、触发器;9、约束等。 drop user user_name cascade ;
★我这次就遇到一次,由于对象有很多,表有24w+,删除就花了很长时间 ,大半天才删除1w+,下面提供一个更快删除用户对象的方法:
也就是先将用户所有的对象生成删除该对象的sql脚本,然后执行脚本,在删除用户,如创建脚本dropnc1205.sql,将删除用户对象的语句保持到脚本dropnc1205.sql,然后执行。 SQL>set pages 0 SQL>spool dropnc1205.sql --select 查询所有用户的对象,生成如 :drop table nc1205.tablename SQL>select "drop " || object_type || " " || owner || "." || object_name || ";" from dba_objects where owner = "NC1205"; SQL>spool off SQL>@dropnc1205.sql SQL>drop user NC1205 cascade
可以看到生成了43w+
执行删除的时候,可以关注表个数的变化
★--查看所有用户表个数select count(*) from all_tab_comments;
★--查看当前用户表个数select count(*) from user_tab_comments;
--查看用户下所有的数据对象的大小: select temp.owner, temp.table_name, temp.column_name, temp.segment_name, "truncate table "|| temp.segment_name ||" DROP STORAGE;" as execTxt, temp.segment_type,temp.g from ( select a.owner, b.table_name, b.column_name, a.segment_name, a.segment_type, round(sum(a.bytes / 1024 / 1024 / 1024), 2) g --以 G 为单位 from dba_segments a left join dba_lobs b on a.owner = b.owner and a.segment_name = b.segment_name --where b.segment_name = "SYS_LOB0000026212C00002$" where a.owner="NC1205" having round(sum(a.bytes / 1024 / 1024 / 1024), 2) >1 -- 条件:大于 1G group by a.owner,b.table_name, b.column_name, a.segment_name,a.segment_type ) temp order by temp.segment_type,temp.g desc;