Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2885483
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2012-02-15 17:42:01

user rollbacks  :每当用户发出rollback,user rollbacks计数将会增加1。
user commits: 每当事务提交user commits 计数增加1,对于没有事务的commit,计数不变。
 

C:\>sqlplus yansp/yansp
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 15 17:09:28 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
> col name format a30
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                          0
 
> rollback;
 
回退已完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                          1

可以看到user rollbacks 计数从0变为1。
 
> rollback;
 
回退已完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                          2
 
再次执行rollback,user rollbacks 计数从1变为2。

> begin
  2    for i in 1..100 loop
  3      rollback;
  4    end loop;
  5  end;
  6  /
 
PL/SQL 过程已成功完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                        102

循环100次rollback,user rollback计数将增加100。

> commit;
 
提交完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                        102
 
> commit;
 
提交完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            0
user rollbacks                        102

对于没有事务的commit,user commits不会增加。

> insert into t1 values(1);
insert into t1 values(1)
*
第 1 行出现错误:
ORA-00001: 违反唯一约束条件 (TEST.SYS_C005716)

> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
NAME                                VALUE
------------------------------ ----------
user commits                            1
user rollbacks                        102

> insert into t values(999);
insert into t values(999)
            *
第 1 行出现错误:
ORA-00942: 表或视图不存在

> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            2
user rollbacks                        102

不过如果语句执行失败,将会导致user commits计数增加。
 
> commit;
 
提交完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            2
user rollbacks                        102

随后的commit都不会导致user commits  增加,除非有事务存在。
 
> insert into t1 values(9999);
 
已创建 1 行。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
NAME                                VALUE
------------------------------ ----------
user commits                            2
user rollbacks                        102
 
> commit;
 
提交完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            3
user rollbacks                        102
 
> begin
  2    for i in 1..100 loop
  3      commit;
  4    end loop;
  5  end;
  6  /
 
PL/SQL 过程已成功完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                            3
user rollbacks                        102
 
> begin
  2    for i in 1..100 loop
  3      insert into t1 values(i+100000);
  4      commit;
  5    end loop;
  6  end;
  7  /
 
PL/SQL 过程已成功完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user commits','user rollbacks') and b.sid=userenv('sid');
 
NAME                                VALUE
------------------------------ ----------
user commits                          103
user rollbacks                        102
 
从上面可以看出,通过user commits计数可以大体估算事务的提交次数。而user rollbacks计数却不能估算出事务回滚的次数。因为只要用户执行过rollback,
不管事务是否回滚,都会导致user rollbacks计数的增加。事务的回滚需要通过通过transaction rollback计数才估算。
 
看如下一个例子:
   
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user rollbacks','transaction rollbacks') and b.sid=userenv('sid
');
NAME                                          VALUE
---------------------------------------- ----------
user rollbacks                                  102
transaction rollbacks                             1
 
> rollback;
 
回退已完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user rollbacks','transaction rollbacks') and b.sid=userenv('sid
');
 
NAME                                          VALUE
---------------------------------------- ----------
user rollbacks                                  103
transaction rollbacks                             1
 
> insert into t1 values(888);
 
已创建 1 行。
 
> rollback;
 
回退已完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user rollbacks','transaction rollbacks') and b.sid=userenv('sid
');
 
NAME                                          VALUE
---------------------------------------- ----------
user rollbacks                                  104
transaction rollbacks                             2
 
> begin
  2    for i in 1..100 loop
  3      rollback;
  4    end loop;
  5  end;
  6  /
 
PL/SQL 过程已成功完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user rollbacks','transaction rollbacks') and b.sid=userenv('sid
');
 
NAME                                          VALUE
---------------------------------------- ----------
user rollbacks                                  204
transaction rollbacks                             2
 
> begin
  2    for i in 1..100 loop
  3      update t1 set c1=c1 where rownum=1;
  4      rollback;
  5    end loop;
  6  end;
  7  /
 
PL/SQL 过程已成功完成。
 
> select a.name,b.value
  2  from v$statname a,v$sesstat b
  3  where a.statistic#=b.statistic# and
  4  a.name in ('user rollbacks','transaction rollbacks') and b.sid=userenv('sid
');
 
NAME                                          VALUE
---------------------------------------- ----------
user rollbacks                                  304
transaction rollbacks                           102
阅读(3496) | 评论(0) | 转发(0) |
0

上一篇:不平衡索引

下一篇:优化器-系统统计信息

给主人留下些什么吧!~~