`
longgangbai
  • 浏览: 7332406 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Oracle truncate 和drop 的区别测试

 
阅读更多
  设置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好,



 

分享到:
评论

相关推荐

    delete,truncate和drop的区别

    ### delete,truncate和drop的区别详解 #### 一、概述 在数据库管理中,经常会遇到需要删除数据或表的情况。为了确保数据的准确性和安全性,理解`delete`、`truncate`和`drop`这三个命令的区别至关重要。本文将详细...

    详解Truncate delete drop三者的区别

    详细阐述了Oracle中三种删除的方式truncate,drop和delete三者的区别和联系.

    Oracle_审计表_sys.aud$_授权给用户Truncate权限.docx

    本文档将详细介绍如何为特定用户授予截断`SYS.AUD$`表的权限,并提供一系列与之相关的Oracle数据库管理和优化操作。 #### 关键知识点 ##### 1. 授予用户截断审计表的权限 为了确保只有授权的用户能够截断审计表`...

    Oracle_授权审计表Truncate权限.docx

    Oracle 授权审计表 Truncate 权限 Oracle 数据库中的授权审计表是指系统自动生成的审计表,用于记录数据库中各种...这些语句可以用于实现 Oracle 数据库中的授权审计表 Truncate 权限,提高数据库的安全性和可靠性。

    oracle truncate恢复工具

    PRM DUL for oracle恢复被truncate截断掉的表 Oracle DBA神器:PRM灾难恢复工具,Schema级别数据恢复。PRM For Oracle Database – schema级别oracle数据库数据恢复特性 ,PRM即ParnassusData Recovery Manager是...

    利用 Oracle 系统触发器防止误删除表操作

    为了应对这类问题,可以通过创建Oracle系统触发器来实现对`DROP TABLE`和`TRUNCATE TABLE`命令的监控与阻止。以下详细介绍两种不同的Oracle版本(10g和8i)下如何创建相应的系统触发器。 ### Oracle 10g环境下的...

    Oracle给用户授权truncatetable的实现方案

    然而,Oracle不支持直接为用户授予针对单个表的`TRUNCATE`权限,而是通常将更广泛的`DROP ANY TABLE`权限赋予用户,但这可能会带来安全隐患。本文将探讨两种实现为用户授权`TRUNCATE TABLE`的方案,以确保安全性和可...

    oracle数据库删除数据Delete语句和Truncate语句的对比.docx

    Oracle 数据库删除数据 Delete 语句和 Truncate 语句的对比 Delete 语句和 Truncate 语句是 Oracle 数据库中两种常用的删除数据的方法,但是它们之间存在着明显的差异。 一、Delete 语句 Delete 语句是一种 DML...

    oracle 自动收集统计信息 测试

    在本文中,我们将对 Oracle 自动收集统计信息进行测试,了解其工作机理和应用场景。 一、测试环境 在本测试中,我们使用 Oracle 11.2.0.3 版本的数据库作为测试环境。 二、测试步骤 ### 1. 创建测试表 首先,...

    oracle恢复测试.sql

    对Oracle各种恢复进行测试汇总,包括delete、update、drop、insert、truncate、init文件、临时文件、数据文件等。

    SQL语句中----删除表数据drop、truncate和delete的用法

    SQL语句中----删除表数据drop、truncate和delete的用法,对你爱不完

    truncate 表恢复

    这个存储过程包利用Oracle的表扫描机制和数据嫁接机制来恢复因`TRUNCATE`操作而丢失的数据。 - **编写语言**: 纯PL/SQL - **下载来源**: 网络 #### 恢复步骤详解 接下来详细介绍如何通过`Fy_Recover_Data`存储...

    ODU在ORACLE数据库中的应用.pdf

    3. 其他特点:ODU 支持 Oracle 所有版本,同时支持 ASM 磁盘数据恢复,支持 Truncate、drop 等操作后的数据恢复,具有恢复速度快、运行稳定和使用简单等优点。 ODU 的配置 1. 控制文件的配置:ODU 的配置文件为 ...

    DB2与ORACLE常用语句对照

    在数据库管理领域,DB2和Oracle都是广泛应用的关系型数据库管理系统,它们都支持SQL语言,但具体语法和功能上存在一些差异。"DB2与ORACLE常用语句对照"的主题旨在帮助用户理解和转换这两种数据库系统中的SQL命令。...

    oracle数据库删除数据Delete语句和Truncate语句的使用比较

    在Oracle数据库中,删除表中数据有两种主要方式:Delete语句和Truncate语句。两者在功能上相似,但有着显著的区别,适用于不同的场景。 **Delete语句** Delete语句是一种灵活的数据删除方式,它可以有条件地删除...

    Oracle 大数据量操作性能优化

    例如,添加分区可以使用 alter table add partition 语句,删除分区可以使用 alter table drop partition 语句,Truncate 分区可以使用 alter table truncate partition 语句,合并分区可以使用 alter table merge ...

    Oracle恢复误删除数据

    Oracle 恢复误删除数据 Oracle 数据库是企业级的关系数据库管理系统,广泛应用于各种行业。然而,在实际操作中,误删除数据是...Oracle 恢复误删除数据需要了解闪回方法的使用和限制,同时也需要注意空间占用的问题。

Global site tag (gtag.js) - Google Analytics