Oracle 了解 DDL 操作与 REDO 的关系

目录

  • 了解 DDL 操作与 REDO 的关系

    • DDL是否会产生REDO
    • 通过 10046 trace 来分析create 和drop
    • 如果drop失败,redo的变化

了解 DDL 操作与 REDO 的关系

DDL是否会产生REDO

用到的SQL:

---查看redo的大小
SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
-------------------------------------- ----------
redo size                                   0        

---创建一个表,查看产生的redo大小

SQL> create table kyeup_tb1 as select * from v$datafile;

Table created.

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                    VALUE
------------------ ----------
redo size               61072
  

---从上面看出创建表的时候redo大小为61072字节,那么删除这个表会产生redo多大呢?

SQL> drop table kyeup_tb1;

Table dropped.

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                    VALUE
-----------------   ----------
redo size              101420

---drop表产生的redo大小:101420-61072= 40348

drop table 语句产生 bytes 的 redo 数据,少于 create table;

这里我们需要查看 DDL 语句执行过程。

通过 10046 trace 来分析create 和drop

可能是 create table 时 Oracle 需要向基表中 insert 数据,而 drop table时则需要delete/update 数据

我们下面用 10046 来跟踪一下 create table 与 drop table 到底做了哪些操作?

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                                 0

SQL> oradebug setmypid;
Statement processed.
SQL> oradebug tracefile_name;
/oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55251.trc
SQL> oradebug event 10046 trace name context forever,level 1;
Statement processed.
SQL> create table kyeuptb1(id int,name varchar2(12));

Table created.

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                                  8880

---分析trace

[[email protected] ~]# cat /oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55251.trc |egrep ‘insert|update|delete|create‘
create table kyeuptb1(id
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (1)‘;
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (2)‘;
     m_stmt:=‘call mderr.raise_md_error(‘‘MD‘‘, ‘‘SDO‘‘, -13391, ‘‘GeoRaster reserved names cannot be used to create regular triggers.‘‘)‘;
insert into obj$(owner#,name,namespace,obj#,type#,ctime,mtime,stime,status,remoteowner,linkname,subname,dataobj#,flags,oid$,spare1,spare2,spare3) values(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18)
insert into seg$ (file#,block#,type#,ts#,blocks,extents,minexts,maxexts,extsize,extpct,user#,iniexts,lists,groups,cachehint,hwmincr, spare1, scanhint, bitmapranges) values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,DECODE(:17,0,NULL,:17),:18,:19)
insert into tab$(obj#,ts#,file#,block#,bobj#,tab#,intcols,kernelcols,clucols,audit$,flags,pctfree$,pctused$,initrans,maxtrans,rowcnt,blkcnt,empcnt,avgspc,chncnt,avgrln,analyzetime,samplesize,cols,property,degree,instances,dataobj#,avgspc_flb,flbcnt,trigflag,spare1,spare6)values(:1,:2,:3,:4,decode(:5,0,null,:5),decode(:6,0,null,:6),:7,:8,decode(:9,0,null,:9),:10,:11,:12,:13,:14,:15,:16,:17,:18,:19,:20,:21,:22,:23,:24,:25,decode(:26,1,null,:26),decode(:27,1,null,:27),:28,:29,:30,:31,:32,:33)
insert into col$(obj#,name,intcol#,segcol#,type#,length,precision#,scale,null$,offset,fixedstorage,segcollength,deflength,default$,col#,property,charsetid,charsetform,spare1,spare2,spare3)values(:1,:2,:3,:4,:5,:6,decode(:5,182/*DTYIYM*/,:7,183/*DTYIDS*/,:7,decode(:7,0,null,:7)),decode(:5,2,decode(:8,-127/*MAXSB1MINAL*/,null,:8),178,:8,179,:8,180,:8,181,:8,182,:8,183,:8,231,:8,null),:9,0,:10,:11,decode(:12,0,null,:12),:13,:14,:15,:16,:17,:18,:19,:20)
     m_stmt:=‘begin SDO_GEOR_UTL.createDMLTrigger(:1,:2); end;‘;
   m_stmt:=‘delete from sdo_geor_ddl__table$$ where id=2‘;
   m_stmt:=‘delete from sdo_geor_ddl__table$$‘;
update seg$ set type#=:4,blocks=:5,extents=:6,minexts=:7,maxexts=:8,extsize=:9,extpct=:10,user#=:11,iniexts=:12,lists=decode(:13, 65535, NULL, :13),groups=decode(:14, 65535, NULL, :14), cachehint=:15, hwmincr=:16, spare1=DECODE(:17,0,NULL,:17),scanhint=:18, bitmapranges=:19 where ts#=:1 and file#=:2 and block#=:3

---create表的时候进行了insert,update等操作,现在开始跟踪下drop表(退出来重新做)

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                                 0

SQL> oradebug setmypid;
Statement processed.
SQL> oradebug tracefile_name;
/oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55296.trc
SQL> oradebug event 10046 trace name context forever,level 1;
Statement processed.
SQL> drop table kyeuptb1;

Table dropped.

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                                  8552

---drop产生的redo要比create产生的要少;分析trace

[[email protected] ~]# cat /oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55296.trc |egrep ‘insert|update|delete|create‘
         ‘Need use delete_topo_geometry_layer() to deregister table ‘
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (1)‘;
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (2)‘;
     m_stmt:=‘call mderr.raise_md_error(‘‘MD‘‘, ‘‘SDO‘‘, -13391, ‘‘GeoRaster reserved names cannot be used to create regular triggers.‘‘)‘;
insert into sdo_geor_ddl__table$$ values (2)
select decode(u.type#, 2, u.ext_username, u.name), o.name,        t.update$, t.insert$, t.delete$, t.enabled,        decode(bitand(t.property, 8192),8192, 1, 0),        decode(bitand(t.property, 65536), 65536, 1, 0),       decode(bitand(t.property, 131072), 131072, 1, 0),       (select o.name from obj$ o          where o.obj# = u.spare2 and o.type# =57)  from sys.obj$ o, sys.user$ u, sys.trigger$ t, sys.obj$ bo where t.baseobject=bo.obj# and bo.name = :1 and bo.spare3 = :2  and bo.namespace = 1  and t.obj#=o.obj# and o.owner#=u.user#  and o.type# = 12 and bitand(property,16)=0 and bitand(property,8)=0  order by o.obj#
delete from object_usage where obj# in  (select a.obj# from object_usage a, ind$ b where  a.obj# = b.obj# and b.bo# = :1)
delete from sys.cache_stats_1$ where dataobj# = :1
delete com$ where obj#=:1
delete from hist_head$ where obj# = :1
delete from compression$ where obj#=:1
     m_stmt:=‘begin SDO_GEOR_UTL.createDMLTrigger(:1,:2); end;‘;
   m_stmt:=‘delete from sdo_geor_ddl__table$$ where id=2‘;
   m_stmt:=‘delete from sdo_geor_ddl__table$$‘;
delete from sdo_geor_ddl__table$$ where id=2
delete from col$ where obj#=:1
delete from icol$ where bo#=:1
delete from icoldep$ where obj# in (select obj# from ind$ where bo#=:1)
delete from jijoin$ where obj# in ( select obj# from jijoin$ where tab1obj# = :1 or tab2obj# = :1)
delete from jirefreshsql$ where iobj# in ( select iobj# from jirefreshsql$ where tobj# = :1)
delete from ccol$ where obj#=:1
delete from ind$ where bo#=:1
delete from cdef$ where obj#=:1
delete ecol$ where tabobj# = :1
delete from tab$ where obj#=:1
delete from idl_ub1$ where obj#=:1 and part=:2
delete from idl_char$ where obj#=:1 and part=:2
delete from idl_ub2$ where obj#=:1 and part=:2
delete from idl_sb4$ where obj#=:1 and part=:2
delete from ncomp_dll$ where obj#=:1 returning dllname into :2
delete coltype$ where obj#=:1
delete from subcoltype$ where obj#=:1
delete ntab$ where obj#=:1
delete lob$ where obj#=:1
delete refcon$ where obj#=:1
delete from opqtype$ where obj#=:1
delete from cdef$ where obj#=:1
delete from objauth$ where obj#=:1
delete from obj$ where obj# = :1
update seg$ set type#=:4,blocks=:5,extents=:6,minexts=:7,maxexts=:8,extsize=:9,extpct=:10,user#=:11,iniexts=:12,lists=decode(:13, 65535, NULL, :13),groups=decode(:14, 65535, NULL, :14), cachehint=:15, hwmincr=:16, spare1=DECODE(:17,0,NULL,:17),scanhint=:18, bitmapranges=:19 where ts#=:1 and file#=:2 and block#=:3
delete from seg$ where ts#=:1 and file#=:2 and block#=:3

如果drop失败,redo的变化

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                                 0

SQL> oradebug setmypid;
Statement processed.
SQL> oradebug tracefile_name;
/oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55343.trc
SQL> oradebug event 10046 trace name context forever,level 1;
Statement processed.
SQL> drop table kyeuptb111;
drop table kyeuptb111
           *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                               384

SQL> create table aa;
create table aa
              *
ERROR at line 1:
ORA-00906: missing left parenthesis

SQL> select b.name,a.value from v$mystat a,v$statname b where a.statistic#=b.statistic# and b.name=‘redo size‘;

NAME                                      VALUE
---------------------------------------------------------------- ----------
redo size                               384

SQL> 

在create失败的时候不会产生redo,但是drop失败的时候是产生redo的(在删除的时候有insert into发生;

---分析如下

[[email protected] ~]# cat /oracle/app/oracle/diag/rdbms/kyeupdbfs/kyeupdbfs/trace/kyeupdbfs_ora_55343.trc |egrep ‘insert|update|delete|create‘
         ‘Need use delete_topo_geometry_layer() to deregister table ‘
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (1)‘;
   m_stmt:=‘insert into sdo_geor_ddl__table$$ values (2)‘;
     m_stmt:=‘call mderr.raise_md_error(‘‘MD‘‘, ‘‘SDO‘‘, -13391, ‘‘GeoRaster reserved names cannot be used to create regular triggers.‘‘)‘;
insert into sdo_geor_ddl__table$$ values (2)
create table aa
[[email protected] ~]# 

原文地址:https://www.cnblogs.com/kyeup/p/9286705.html

时间: 2024-10-18 12:22:09

Oracle 了解 DDL 操作与 REDO 的关系的相关文章

Goldengate 实现Oracle for Oracle 单向DDL操作同步

在http://lqding.blog.51cto.com/9123978/1695162 文章中我们实现了表的DML操作同步. 我们做如下测试 在源端执行表的truncate SQL> truncate table tcustmer; Table truncated. 在目的端,查看表数据 SQL> select count(*) from tcustmer;   COUNT(*) ----------  2 数据并没有同步 我们如何让Goldengate实现DDL操作的同步呢? 要想支持D

MySQL/MariaDB基础性知识及DDL操作详解

前言 MySQL/MariaDB是一个开放源码的小型关联式数据库管理系统,由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL/MariaDB作为网站数据库. 基础架构 MySQL核心组件 连接池:认证.线程重用.连接数限制.内存检查.缓存 SQL接口:DDL, DML, 关系型数据库的基本抽象 parser: 查询转换.对象权限检查 优化器:访问路径,性能相关的统计数据 caches和buffers:与存储引擎自身相关的I/O性

Oracle中DDL语句对事务的影响

 1.Oracle中DDL语句对事务的影响 在Oracle中,执行DDL语句(如Create Table.Create View等)时,会在执行之前自动发出一个Commit命令,并在随后发出一个Commit或者Rollback命令,也就是说,DDL会象如下伪码一样执行: Commit;DDL_Statement; If (Error) then Rollback; Else Commit;End if; 我们通过分析下面例子来看Oracle中,DDL语句对事务的影响: Insert into

oracle学习----DDL锁理解

DDL锁分为三种 1.排他DDL锁 2.共享DDL锁 3.可中断解析锁 大部分DDL都带有排他DDL锁,如一个表被修改中,可以使用select查询数据,但是大多数操作都是不允许执行的,包括所有其他DDL语句. 但是在oracle中,有一些DDL操作没有DDL锁也发生.比如online创建索引 在线创建索引,会带有DL,OD,低级TM锁,但是没有排他DDL锁 DL 直接加载锁,对表进行直接加载路径与创建索引不能同时进行. OD锁 online DDL支持真正的联机. 低级TM锁 防止其他DDL发生

MySQL--各版本DDL 操作总结

MySQL 5.5 DDL 在MySQL 5.5版本前,所有DDL操作都使用Copy Table的方式完成,操作过程中原表数据库不允许写入,只能读取,在MySQL 5.5版本中引入FIC(Fast index creation)特性. FCI 操作流程: (1)对表加共享S锁,允许其他会话读操作,但禁止写操作, (2)根据当前表数据创建索引, (3)新索引创建完成,解除S锁,允许读写. FCI 优点: (1)创建索引不需要拷贝整表数据,创建速度快, (2)创建索引过程中,可以快速中止. FCI限

Oracle中IMU技术和redo private strand技术

oracle030 oracle030 Oracle中IMU技术和redo private strand技术 3.图解Oracle IMU机制 select * from v$sysstat where name like '%IMU%'; STATISTIC#, NAME,       CLASS, VALUE, STAT_ID 312     IMU commits     128     393     1914489094 313     IMU Flushes     128    

ORACLE 导入导出操作

1.导入命令: imp userId/[email protected] full=y  file=D:\data\xxx.dmp ignore=y 2.导出命令 exp userId/[email protected] file=d:\dkj\test.dmp tables=(wf_test) exp userId/[email protected] buffer=50000000 file=D:\data\xxx.dmp owner=userId 1.在安装完ORACLE 11g后,在sql

禁止用户对自己表的DDL操作

刚翻阅资料,查到一个数据库管理的小技巧,可以禁止用户对自己schema下的表进行DDL操作,原理是禁用表上的锁. SQL> alter table t1 disable table lock; Table altered. SQL> drop table t1 purge; drop table t1 purge * ERROR at line 1: ORA-00069: cannot acquire lock -- table locks disabled for T1 同时不影响该表的DM

监控数据库DDL操作日志

背景 为了监控好生产环境下各个数据库服务器上DDL操作日志,便于运维工程师管控好风险,我们有必要关注当前实例下的所有的DDL操作. 测试环境 Microsoft SQL Server 2012 - 11.0.2218.0 (X64) Jun 12 2012 13:05:25 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) 操作步骤 第一步.