Oracle中flush buffer cache和x$bh

PiscesCanon發表於2017-05-30
實驗出發點:
今天做關於引數db_file_multiblock_read_count實驗的時候,詳情見http://blog.itpub.net/30174570/viewspace-2140241/,對oracle資料庫執行alter system flush buffer_cache;指令發現,x$bh表中已經存在的資訊並不會被清除。

實驗環境:
1.作業系統
  1. [oracle@oracle ~]$ uname -a
  2. Linux oracle.example.com 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
  3. [oracle@oracle ~]$ lsb_release -a
  4. LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
  5. Distributor ID: RedHatEnterpriseServer
  6. Description:    Red Hat Enterprise Linux Server release 6.5 (Santiago)
  7. Release:        6.5
  8. Codename:       Santiago
2.資料庫版本
  1. SYS@proc> select * from v$version where rownum=1;

  2. BANNER
  3. --------------------------------------------------------------------------------
  4. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

實驗過程:
  1. SYS@proc> drop table test purge;

  2. Table dropped.

  3. SYS@proc> create table test as select * from dba_objects;

  4. Table created.

  5. SYS@proc> select file#,dbablk,state from x$bh where obj=(select data_object_id from dba_objects where owner='SYS' and object_name='TEST') order by dbablk;

  6.      FILE#     DBABLK      STATE
  7. ---------- ---------- ----------
  8.          1      93952          1

  9. SYS@proc> shutdown immediate;
  10. Database closed.
  11. Database dismounted.
  12. ORACLE instance shut down.
  13. SYS@proc> startup;
  14. ORACLE instance started.

  15. Total System Global Area 521936896 bytes
  16. Fixed Size                 2254824 bytes
  17. Variable Size            159385624 bytes
  18. Database Buffers         356515840 bytes
  19. Redo Buffers               3780608 bytes
  20. Database mounted.
  21. Database opened.
  22. SYS@proc> select file#,dbablk,state from x$bh where obj=(select data_object_id from dba_objects where owner='SYS' and object_name='TEST') order by dbablk;

  23. no rows selected

  24. SYS@proc> select count(*) from test;

  25.   COUNT(*)
  26. ----------
  27.      86991

  28. SYS@proc> select file#,dbablk,state from x$bh where obj=(select data_object_id from dba_objects where owner='SYS' and object_name='TEST') order by dbablk;

  29.      FILE#     DBABLK      STATE
  30. ---------- ---------- ----------
  31.          1      93952          1
  32.          1      93952          3
  33.          1      93952          3
  34.          1      94668          1
  35. ...省略部分內容...
  36.      FILE#     DBABLK      STATE
  37. ---------- ---------- ----------
  38.          1      97609          1
  39.          1      97743          1
  40.          1      97744          1
  41.          1      97745          1

  42. 318 rows selected.
  43. SYS@proc> alter system flush buffer_cache;

  44. System altered.

  45. SYS@proc> select file#,dbablk,state from x$bh where obj=(select data_object_id from dba_objects where owner='SYS' and object_name='TEST') order by dbablk;

  46.      FILE#     DBABLK      STATE
  47. ---------- ---------- ----------
  48.          1      93952          0
  49.          1      93952          0
  50.          1      93952          0
  51.          1      94668          0
  52. ...省略部分內容...
  53.      FILE#     DBABLK      STATE
  54. ---------- ---------- ----------
  55.          1      97609          0
  56.          1      97654          0
  57.          1      97738          0
  58.          1      97739          0

需要注意的地方:
select file#,dbablk,state from x$bh where obj=(select data_object_id from dba_objects where owner='SYS' and object_name='TEST') order by dbablk;這裡的data_object_id在對錶做move後不能替換成object_id。
具體原因參見我的另一篇博文:http://blog.itpub.net/30174570/viewspace-2140058/

實驗結論:
oracle資料庫執行alter system flush buffer_cache;只能清除資料快取,並不能清除BH資訊。

其他資料:
The possible values of X$BH.STATE are:
0, FREE, no valid block image
1, XCUR, a current mode block, exclusive to this instance
2, SCUR, a current mode block, shared with other instances
3, CR,   a consistent read (stale) block image
4, READ, buffer is reserved for a block being read from disk
5, MREC, a block in media recovery mode
6, IREC, a block in instance (crash) recovery mode

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30174570/viewspace-2140062/,如需轉載,請註明出處,否則將追究法律責任。

相關文章