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;

展开阅读全文

页面更新:2024-04-15

标签:用户   触发器   大半天   名下   视图   序列   语句   脚本   个数   对象   数据

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top