赞
踩
天萃荷净
Oracle研究中心学习笔记:分享一篇关于Oracle数据库关于SQL语句战胜资源的信息,如何计算某个sql语句所产生的redo和undo大小?
本站文章除注明转载外,均为本站原创: 转载自love wife & love life —Roger 的Oracle技术博客
本文链接地址: 如何计算某个sql语句所产生的redo和undo大小?
如何计算 一个insert产生 的 redo 和 undo 大小
如下简单的测试,供大家参考。
SQL> CREATE TABLE oracleplus AS SELECT * FROM dba_objects;
TABLE created.
SQL> SELECT COUNT(*) FROM oracleplus;
COUNT(*)
----------
50100
SQL> SET autotrace traceonly statistics
SQL> SET LINES 150
SQL> UPDATE oracleplus
2 SET owner='www.oracleplus.net'
3 WHERE object_id >1000 AND object_id <1200;
199 ROWS updated.
Statistics
----------------------------------------------------------
51 recursive calls
208 db block gets
798 consistent gets
0 physical reads
53908 redo SIZE
668 bytes sent via SQL*Net TO client
619 bytes received via SQL*Net FROM client
3 SQL*Net roundtrips TO/FROM client
1 sorts (memory)
0 sorts (disk)
199 ROWS processed
此时我们知道这个update语句会产生53908 byte的redo 日志。
当然这个是sql未执行前就进行的计算,如果要计算某个sqOracleоl执行完毕以后所产生的redo size,我们还可以通过查询v$mystat试图获得结果,如下:
SQL> SET autot off
SQL> SELECT a.name, b.VALUE
2 FROM v$statname a, v$mystat b
3 WHERE a.statistic# = b.statistic#
4 AND a.name = 'redo size';
NAME VALUE
--------------------- ----------
redo SIZE 5807132
SQL> UPDATE oracleplus
2 SET owner='www.oracleplus.net'
3 WHERE object_id >1000 AND object_id <1200;
199 ROWS updated.
SQL> netmit;
netmit netplete.
SQL> SELECT a.name, b.VALUE
2 FROM v$statname a, v$mystat b
3 WHERE a.statistic# = b.statistic#
4 AND a.name = 'redo size';
NAME VALUE
--------------------- ----------
redo SIZE 5829644
SQL> SELECT 5829644 - 5807132 FROM dual;
5829644-5807132
---------------
22512
我们可以明显的看到,通过查询v$mystat 得出的结果跟前面通过看sql执行计划统计信息结果有较大的差别,区别在哪儿呢?
这是session级别的,因为还涉及到一些递归的操作,也会产生redo,所以上面单纯的查询session的redo产生大小,并不准确,我们应该查询整个db instacne的,如下:
SQL> CREATE TABLE oracleplus2 AS SELECT * FROM dba_objects;
TABLE created.
SQL> ALTER system checkpoint;
System altered.
SQL> ALTER system switch logfile;
System altered.
SQL> SELECT name,VALUE FROM v$sysstat WHERE name = 'redo size';
NAME VALUE
--------------------- ----------
redo SIZE 27301552
SQL> UPDATE oracleplus2
2 SET owner='www.oracleplus.net'
3 WHERE object_id >1000 AND object_id <1200;
199 ROWS updated.
SQL> netmit;
netmit netplete.
SQL> SELECT name,VALUE FROM v$sysstat WHERE name = 'redo size';
NAME VALUE
--------------------- ----------
redo SIZE 27355556
SQL> SELECT 27355556 - 27301552 FROM dual;
27355556-27301552
-----------------
54004
我们可以看到,此时的54004 跟最开始的50100算是比较接近了。
SQL> SELECT xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec FROM v$transaction;
no ROWS selected
SQL> SELECT ubafil,ubablk,start_ubablk,used_ublk FROM v$transaction;
no ROWS selected
SQL> DELETE FROM oracleplus WHERE rownum < 1000;
999 ROWS deleted.
SQL> SELECT xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec FROM v$transaction;
XIDUSN XIDSLOT XIDSQN UBABLK UBAFIL UBAREC
---------- ---------- ---------- ---------- ---------- ----------
10 39 354 1256 2 26
SQL> SELECT ubafil,ubablk,start_ubablk,used_ublk FROM v$transaction;
UBAFIL UBABLK START_UBABLK USED_UBLK
---------- ---------- ------------ ----------
2 1256 1229 28
SQL> conn /AS sysdba
Connected.
SQL> SELECT SUM(KTUXESIZ)
2 FROM x$ktuxe
3 WHERE KTUXEUSN=10 AND KTUXESLT=39 AND KTUXESQN=354;
SUM(KTUXESIZ)
-------------
28
SQL> SELECT 28*8192 FROM dual;
28*8192
----------
229376
从上我们可以看到该delete语句所产生的undo 大小是229376 BYTE。
--------------------------------------ORACLE-DBA----------------------------------------
最权威、专业的Oracle案例资源汇总之【学习笔记】Oracle查看计算出SQL语句占用的redo和undo大小的方法
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。