设为首页 收藏本站
查看: 603|回复: 0

[经验分享] Oracle truncate 和drop 的区别测试

[复制链接]

尚未签到

发表于 2016-8-10 07:18:22 | 显示全部楼层 |阅读模式
设置autotrace功能
1.创建plan_table表
sqlplus /nolog
conn sys /as sysdba
@?/rdbms/admin/utlxplan.sql;
create public synonym plan_table for plan_table;
grant all on plan_table to public;
2.创建plustrace角色和权限
@?/sqlplus/admin/plustrce.sql;
DBA用户首先被授予了plustrace角色,然后我们可以把plustrace授予public,这样所有用户都将拥有plustrace角色的权限.
grant plustrace to public ;
已可用autotrace功能
3.测试:
SQL> connect center/Dongyun123
SQL> set autotrace on;
设置时间提示
SQL> set time on;
设置统计执行时间
SQL 18:23:53> set timing on;
4.帮助:
关于autotrace几个常用选项的说明:
SET AUTOTRACE OFF ------------ 不生成AUTOTRACE 报告,这是缺省模式
SET AUTOTRACE ON EXPLAIN ----- AUTOTRACE只显示优化器执行路径报告
SET AUTOTRACE ON STATISTICS -- 只显示执行统计信息
SET AUTOTRACE ON ------------- 包含执行计划和统计信息
SET AUTOTRACE TRACEONLY ------- 同set autotrace on,但是不显示查询输出
 
sys@TICKET> set auo
SP2-0158: 未知的 SET 选项 "auo"
sys@TICKET> set autot
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
sys@TICKET> set autotrace on stat;
sys@TICKET> create table test as select * from dba_objects
2  union all select * from dba_objects
3  union all select * from dba_objects
4  union all select * from dba_objects
5  union all select * from dba_objects
6  union all select * from dba_objects
7  union all select * from dba_objects
8  union all select * from dba_objects
9  union all select * from dba_objects
10  union all select * from dba_objects
11  union all select * from dba_objects
12  union all select * from dba_objects
13  union all select * from dba_objects
14  union all select * from dba_objects
15  union all select * from dba_objects
16  union all select * from dba_objects;
表已创建。
sys@TICKET>
sys@TICKET> commit;
提交完成。
sys@TICKET> commit;
提交完成。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
88

统计信息
----------------------------------------------------------
22  recursive calls
0  db block gets
96  consistent gets
1  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> truncate table test;
表被截断。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
1

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> drop table test;
表已删除。
sys@TICKET> create table test as select * from dba_objects
2  union all select * from dba_objects
3  union all select * from dba_objects
4  union all select * from dba_objects
5  union all select * from dba_objects
6  union all select * from dba_objects
7  union all select * from dba_objects
8  union all select * from dba_objects
9  union all select * from dba_objects
10  union all select * from dba_objects
11  union all select * from dba_objects
12  union all select * from dba_objects
13  union all select * from dba_objects
14  union all select * from dba_objects
15  union all select * from dba_objects
16  union all select * from dba_objects;
表已创建。
sys@TICKET>
sys@TICKET> commit;
提交完成。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
88

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> truncate table test drop storage;
表被截断。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
1

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> drop table test;
表已删除。
sys@TICKET> create table test as select * from dba_objects
2  union all select * from dba_objects
3  union all select * from dba_objects
4  union all select * from dba_objects
5  union all select * from dba_objects
6  union all select * from dba_objects
7  union all select * from dba_objects
8  union all select * from dba_objects
9  union all select * from dba_objects
10  union all select * from dba_objects
11  union all select * from dba_objects
12  union all select * from dba_objects
13  union all select * from dba_objects
14  union all select * from dba_objects
15  union all select * from dba_objects
16  union all select * from dba_objects;
表已创建。
sys@TICKET> commit;
提交完成。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
88

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> truncate table test reuse storage;
表被截断。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
88

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> select * from test;
未选定行

统计信息
----------------------------------------------------------
323  recursive calls
1  db block gets
40  consistent gets
1  physical reads
96  redo size
1124  bytes sent via SQL*Net to client
405  bytes received via SQL*Net from client
1  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
0  rows processed
sys@TICKET> drop table test;
表已删除。
sys@TICKET> create table test as select * from dba_objects
2  union all select * from dba_objects
3  union all select * from dba_objects
4  union all select * from dba_objects
5  union all select * from dba_objects
6  union all select * from dba_objects
7  union all select * from dba_objects
8  union all select * from dba_objects
9  union all select * from dba_objects
10  union all select * from dba_objects
11  union all select * from dba_objects
12  union all select * from dba_objects
13  union all select * from dba_objects
14  union all select * from dba_objects
15  union all select * from dba_objects
16  union all select * from dba_objects;
表已创建。
sys@TICKET>
sys@TICKET> commit;
提交完成。
sys@TICKET> select extents from user_segments where segment_name='TEST';
EXTENTS
----------
88

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
90  consistent gets
0  physical reads
0  redo size
418  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
sys@TICKET> drop table test;
表已删除。
sys@TICKET> select extents from user_segments where segment_name='TEST';
未选定行

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
66  consistent gets
0  physical reads
0  redo size
284  bytes sent via SQL*Net to client
405  bytes received via SQL*Net from client
1  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
0  rows processed
sys@TICKET> spool off;
由以上可以看出得出一下信息:
1.如果从性能的角度来看,truncate  reuse   storage 主要是针对大量extent 的字典管理表空间.
2.DROP TABLE的时候,Extents要被回收。而truncate table test reuse storage没有Extents要被回收.
3.truncate table test drop storage 的时候,Extents要被回收,HWM会变化 。
4.truncate table test功能和truncate table test drop storage差不多.
5.truncate table reuse storage在性能上比truncate table  drop storage好,


  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-255601-1-1.html 上篇帖子: DMP数据文件导入Oracle 下篇帖子: Oracle按笔画,部首,拼音排序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表