楼主: lozity

关于块清除的一个问题,谢谢

[复制链接]
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
11#
发表于 2008-6-19 01:19 | 只看该作者
原帖由 solearn 于 2008-6-17 21:54 发表

Could you describe ther difference between checkpoint and flush_cache briefly?


I haven't done any test. But what you need is to write modified or dirty buffers to datafiles, which is exactly what checkpoint does. Flush_cache is not designed to do that. It's meant to restore the buffer cache to what it was like before a data block was read from a datafile into buffer cache.

When you have time, please do a test and watch the change in v$bh or x$bh. Thanks.

Yong Huang

使用道具 举报

回复
论坛徽章:
5
生肖徽章2007版:猴
日期:2008-01-02 17:35:53生肖徽章2007版:鼠
日期:2008-01-02 17:35:532009新春纪念徽章
日期:2009-01-04 14:52:282009日食纪念
日期:2009-07-22 09:30:00ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51
12#
 楼主| 发表于 2008-6-19 05:59 | 只看该作者
It's meant to restore the buffer cache to what it was like before a data block was read from a datafile into buffer cache.

dx能解释下这句话吗?看得实在不是很懂…………谢谢

使用道具 举报

回复
论坛徽章:
14
奥运会纪念徽章:自行车
日期:2008-04-25 21:00:142013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-10 13:11:14奥运会纪念徽章:皮划艇激流回旋
日期:2012-08-13 10:25:38鲜花蛋
日期:2012-02-10 11:40:172010新春纪念徽章
日期:2010-03-01 11:04:58授权会员
日期:2010-01-12 09:40:47ITPUB元老
日期:2010-01-12 09:33:092009新春纪念徽章
日期:2009-01-04 14:52:28奥运会纪念徽章:拳击
日期:2008-10-24 13:22:33
13#
发表于 2008-6-19 09:09 | 只看该作者
原帖由 Yong Huang 于 2008-6-19 01:19 发表


I haven't done any test. But what you need is to write modified or dirty buffers to datafiles, which is exactly what checkpoint does. Flush_cache is not designed to do that. It's meant to restore the buffer cache to what it was like before a data block was read from a datafile into buffer cache.

When you have time, please do a test and watch the change in v$bh or x$bh. Thanks.

Yong Huang


Thanks for showing me the clue.



SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       11972
xcur          40

SQL> alter system set events 'immediate trace name flush_cache';

系统已更改。

SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       12012

SQL> select count(*) from dengsk.t8;

  COUNT(*)
----------
         9

SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       12006
xcur           6

SQL> select * from dengsk.t8;

C                ID
-------- ----------
az             1330
by             1331
Candy          1332
Deskbook       1333
EggReady       1334
finefine       1335
aaa              32
aaa              33
mourning       1329

已选择9行。

SQL> delete from dengsk.t8 where id=1329;

已删除 1 行。

SQL> commit;

提交完成。

SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       12001
xcur          11

SQL> alter system checkpoint;

系统已更改。

SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       11970
xcur          42

The above is a simple test. I haven't an idea how come it turned out yet. These days I am busy in dealing with an exam of our company at the end of this month. While I am free, I would like to probe it further.

使用道具 举报

回复
论坛徽章:
14
奥运会纪念徽章:自行车
日期:2008-04-25 21:00:142013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-10 13:11:14奥运会纪念徽章:皮划艇激流回旋
日期:2012-08-13 10:25:38鲜花蛋
日期:2012-02-10 11:40:172010新春纪念徽章
日期:2010-03-01 11:04:58授权会员
日期:2010-01-12 09:40:47ITPUB元老
日期:2010-01-12 09:33:092009新春纪念徽章
日期:2009-01-04 14:52:28奥运会纪念徽章:拳击
日期:2008-10-24 13:22:33
14#
发表于 2008-6-19 09:12 | 只看该作者
原帖由 lozity 于 2008-6-19 05:59 发表
It's meant to restore the buffer cache to what it was like before a data block was read from a datafile into buffer cache.

dx能解释下这句话吗?看得实在不是很懂…………谢谢


大概翻译一下:(flush cache)用于把buffer cache恢复到它读入文件上数据块之前的样子。

使用道具 举报

回复
论坛徽章:
5
生肖徽章2007版:猴
日期:2008-01-02 17:35:53生肖徽章2007版:鼠
日期:2008-01-02 17:35:532009新春纪念徽章
日期:2009-01-04 14:52:282009日食纪念
日期:2009-07-22 09:30:00ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51
15#
 楼主| 发表于 2008-6-19 13:34 | 只看该作者
大概翻译一下:(flush cache)用于把buffer cache恢复到它读入文件上数据块之前的样子。


不是这样的吧?我看eygle的深入浅出中写:强制刷新buffer cache ,将buffer cache中的数据写回到数据文件,如果像楼上那么说,那flush cache 之后岂不是dml会丢失?

使用道具 举报

回复
论坛徽章:
151
2014年新春福章
日期:2014-04-17 11:38:13奥运会纪念徽章:皮划艇静水
日期:2012-07-31 15:42:58奥运会纪念徽章:田径
日期:2012-07-10 16:21:10奥运会纪念徽章:跆拳道
日期:2012-06-20 22:07:29奥运会纪念徽章:皮划艇静水
日期:2012-06-16 02:55:21奥运会纪念徽章:曲棍球
日期:2012-06-13 10:09:19蛋疼蛋
日期:2012-05-19 23:20:41迷宫蛋
日期:2012-05-16 17:35:25版主2段
日期:2012-05-15 15:24:11双黄蛋
日期:2012-03-19 19:34:04
16#
发表于 2008-6-19 14:29 | 只看该作者
flush cache肯定会把脏数据块写入到数据文件中的,就算写到原来数据文件中的是原始的数据块,那么之后变更产生的UNDO块也会写入到UNDO表空间里面的.DML肯定不会丢失.

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
17#
发表于 2008-6-19 20:06 | 只看该作者
原帖由 solearn 于 2008-6-18 19:09 发表


Thanks for showing me the clue.



SQL> select status,count(*) from v$bh group by status;

STATU   COUNT(*)
----- ----------
free       11972
xcur          40

SQL> alter system set events 'immediate trace name flush_cache';

系统已更改。

...


How about checking v$bh.dirty instead of status before and after flush_cache and checkpoint?

Yong Huang

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
18#
发表于 2008-6-19 20:46 | 只看该作者
原帖由 Yong Huang 于 2008-6-19 06:06 发表

How about checking v$bh.dirty instead of status before and after flush_cache and checkpoint?

Yong Huang


I did a test in 10.2.0.1 database. I keep checking x$bh.flag:

select flag, count(*) from x$bh group by flag order by 1;

while I do flush buffer_cache and checkpoint. The flag column is documented at
http://www.jlcomp.demon.co.uk/buf_flag.html

It looks like flush buffer_cache does much more than checkpoint. Flushing cache reduces count of buffers with flags such as 8192 (gotten_in_current_mode), 524288 (only_sequential_access) and 33562625 (dirty and gotten_in_current_mode and redo_since_read). Checkpoint, on the other hand, does much less, but it does reduce dirty buffers.

I don't know much about some of the obscure (uncommon) flags. But it looks like flush buffer_cache does what checkpoint does, plus more. Then the question is How do we explain lozity's test (see his messages at 2008-6-17 16:46 and 2008-6-17 20:23)? Maybe I misunderstood his test.

Even if flush cache writes dirty buffers to datafiles as checkpoint does (as I guessed), Oracle does not consider it as a checkpoint. In my test, v$sysstat does not show increase for
DBWR checkpoints
background checkpoints started
background checkpoints completed
and only increases
physical writes non checkpoint.

If I can check the content of the checkpoint queue, it's possible flush buffer_cache does not change it.

Can jingjingxiaomei or biti_rainy shed some light on this? You have done more research on buffer cache than I.

Yong Huang

使用道具 举报

回复
论坛徽章:
5
生肖徽章2007版:猴
日期:2008-01-02 17:35:53生肖徽章2007版:鼠
日期:2008-01-02 17:35:532009新春纪念徽章
日期:2009-01-04 14:52:282009日食纪念
日期:2009-07-22 09:30:00ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51
19#
 楼主| 发表于 2008-6-20 09:54 | 只看该作者
多谢版主,我的测试是这样的:

首先对一个表做update,然后用dba用户登录,做flush cache操作,最后dump出表的数据块,发现其中没有ITL信息

我的理解是块在内存中已经被修改,然后做了flush cache以后再dump块,应该是可以看到ITL信息了,为什么看不到?

使用道具 举报

回复
论坛徽章:
14
奥运会纪念徽章:自行车
日期:2008-04-25 21:00:142013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-10 13:11:14奥运会纪念徽章:皮划艇激流回旋
日期:2012-08-13 10:25:38鲜花蛋
日期:2012-02-10 11:40:172010新春纪念徽章
日期:2010-03-01 11:04:58授权会员
日期:2010-01-12 09:40:47ITPUB元老
日期:2010-01-12 09:33:092009新春纪念徽章
日期:2009-01-04 14:52:28奥运会纪念徽章:拳击
日期:2008-10-24 13:22:33
20#
发表于 2008-6-27 14:49 | 只看该作者
原帖由 lozity 于 2008-6-18 06:46 发表
我做了这样一个测试(oracle 9.2.0.1):

SQL> update emp set sal=9000 where empno=7788;

1 row updated.

SQL> update emp set sal=9999 where empno=7900;

1 row updated.

SQL> alter system set events='immediate trace name flush_cache';

SQL> alter system dump datafile 4 block min 25 block max 32;

然后我查看trc文件,发现其中并没有ITL事务信息,我的问题是:既然内存中的数据块已经被修改过,而且已经写回数据文件,为什么看不到ITL信息,但是我提交之后再DUMP一次就可以看到了……?


我模拟了你的实验,可以看到事物信息。

Session 1:

SQL> update t8 set id=9999 where id=1330;

1 row updated.

SQL>

session 2:

SQL> connect / as sysdba
Connected.
SQL> alter system set events 'immediate trace name flush_cache';

System altered.

SQL> alter system dump datafile 6 block 20;

System altered.

SQL> connect / as sysdba
Connected.
SQL> select count(*) from v$transaction;

  COUNT(*)
----------
         1

在dump文件中可以看到:
Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   0x000e.015.0000000b  0x02000045.0010.33  ----    1  fsc 0x0000.00000000
0x02   0x000c.00f.00000007  0x0200001a.000c.13  C---    0  scn 0x0000.00639d60
0x03   0x000b.002.00000009  0x0200000a.0020.12  C-U-    0  scn 0x0000.0064768f

data_block_dump,data header at 0x5a1107c
===============


session1:
sql>commit;

session2:
SQL> select count(*) from v$transaction;

  COUNT(*)
----------
         0

[ 本帖最后由 solearn 于 2008-6-28 11:29 编辑 ]

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表