Direct I/O and Redo writes.
今天再論壇看到一個問題 關於 lost write 突然想到LGWR 在commit 時是如何保證寫道磁碟的 在網上查到一篇文章很好的解釋了這個
Direct I/O and Redo writes.
Here is a subject that has bothered me for some time. When you make a database change and then issue a subsequent COMMIT, how can you guarantee that the change has been recorded and written to disk? I guess the real question is: Are you really sure your transactions are safe?
If we take a look at the Oracle database architecture, we are told that when we issue a commit, the change which has already been recorded in the Redo Log buffer is flushed to disk.
Linux likes to utilize all available memory, so for example if the O/S reports having free, then a good chunk of this will be used for O/S I/O caching. We can verify this with the free command:
free -m
total used free shared buffers cached
Mem: 6022 5983 38 0 26 3736
Notice here that my Linux machine is using over 3GB of the physical 6GB for I/O caching.
Caching at the O/S level is generally a good idea, however when we specifically look at Oracle, this mechanism has the affect of double caching our database data blocks and skewing our disk write time performance statistics. Database block writes (via DBWR) are no longer disk writes, they become cached disk writes.
The follow up question that springs into mind may also be: What about LGWR ? Does this also imply that when a user commits, the redo log entry is written to the Linux I/O cache before being written to disk? If so, surly I can then loose changes, even after they have been posted to disk..... This is something I needed to pursue with Oracle for peace of mind.
According to Oracle, the LGWR process uses an O/S option called "Direct IO". Direct IO instructs Linux to write directly to the disk I/O subsystem. Basically, bypassing the O/S I/O buffering mechanism. As a DBA, this makes me feel better. But we are not there yet.
Further investigations in this area (this time via Redhat) provides the final piece of the jigsaw. Although Direct IO does bypass the O/S cache, it cannot instruct your storage devices to bypass any physical caching that is taking place. In my case, I have direct attached storage with a controller which is caching reads and writes. By default, I also have physical disk read/write caching too! - All of these options are configurable. But, out of the box, in my environment, I have 2 levels of caching for LGWR, and 3 levels forDBWR ( DBWR does not implement DIRECT I/O by default*)
Ultimately, this investigation demonstrates that we DBA's do need to understand the O/S and Hardware that we are using. Secondly, we should not take everything we hear at face value.
I have heard several times (even on DBA training courses) that once a commit is issued, the change is guaranteed to be written to disk. However, if you have not thought about the extra possible levels of software and hardware caching there will be a split second when Oracle thinks it has written your valuable change to disk, but in fact it will be hanging around in a hardware cache - some place between your database server and the physical disk platter , just waiting for that inevitable power cut!
* Incidentally, DIRECT I/O can be enabled for DBWR by using thefilesystemio_options database parameter. This, I will save for another entry.
If we take a look at the Oracle database architecture, we are told that when we issue a commit, the change which has already been recorded in the Redo Log buffer is flushed to disk.
Linux likes to utilize all available memory, so for example if the O/S reports having free, then a good chunk of this will be used for O/S I/O caching. We can verify this with the free command:
free -m
total used free shared buffers cached
Mem: 6022 5983 38 0 26 3736
Notice here that my Linux machine is using over 3GB of the physical 6GB for I/O caching.
Caching at the O/S level is generally a good idea, however when we specifically look at Oracle, this mechanism has the affect of double caching our database data blocks and skewing our disk write time performance statistics. Database block writes (via DBWR) are no longer disk writes, they become cached disk writes.
The follow up question that springs into mind may also be: What about LGWR ? Does this also imply that when a user commits, the redo log entry is written to the Linux I/O cache before being written to disk? If so, surly I can then loose changes, even after they have been posted to disk..... This is something I needed to pursue with Oracle for peace of mind.
According to Oracle, the LGWR process uses an O/S option called "Direct IO". Direct IO instructs Linux to write directly to the disk I/O subsystem. Basically, bypassing the O/S I/O buffering mechanism. As a DBA, this makes me feel better. But we are not there yet.
Further investigations in this area (this time via Redhat) provides the final piece of the jigsaw. Although Direct IO does bypass the O/S cache, it cannot instruct your storage devices to bypass any physical caching that is taking place. In my case, I have direct attached storage with a controller which is caching reads and writes. By default, I also have physical disk read/write caching too! - All of these options are configurable. But, out of the box, in my environment, I have 2 levels of caching for LGWR, and 3 levels forDBWR ( DBWR does not implement DIRECT I/O by default*)
Ultimately, this investigation demonstrates that we DBA's do need to understand the O/S and Hardware that we are using. Secondly, we should not take everything we hear at face value.
I have heard several times (even on DBA training courses) that once a commit is issued, the change is guaranteed to be written to disk. However, if you have not thought about the extra possible levels of software and hardware caching there will be a split second when Oracle thinks it has written your valuable change to disk, but in fact it will be hanging around in a hardware cache - some place between your database server and the physical disk platter , just waiting for that inevitable power cut!
* Incidentally, DIRECT I/O can be enabled for DBWR by using thefilesystemio_options database parameter. This, I will save for another entry.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-761332/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Direct I/O (DIO) and Concurrent I/O (CIO) on AIX 5LAI
- WARNING:Could not increase the asynch I/O limit to 164 for SQL direct I/OMITSQL
- WARNING:Could not lower the asynch I/O limit to 160 for SQL direct I/O.MITSQL
- expdp匯出時卡死 Could not increase the asynch I/O limit to for SQL direct I/OMITSQL
- WARNING:Could not increase the asynch I/O limit to 224 for SQL direct I/O.MITSQL
- expdp匯出時卡死 Could not increase the asynch I/O limit to XXX for SQL direct I/OMITSQL
- Redo Logging I/O-Related Wait EventsAI
- Veritas Quick I/O and Cached Quick I/OUI
- 計算機I/O與I/O模型計算機模型
- I/O埠和I/O記憶體記憶體
- Java I/OJava
- Java(8)I/OJava
- 【java】I/O流Java
- Java I/O流Java
- 檔案I/O
- I/O基礎
- java的I/OJava
- c++ I/OC++
- Python教程:精簡概述I/O模型與I/O操作Python模型
- goldengate extract abended unable to queue I/O, I/O beyond file sizeGo
- 【面試】I/O 複用面試
- Java 非同步 I/OJava非同步
- 網路I/O模型模型
- 系統級 I/O
- JAVA I/O系統Java
- GDAL並行I/O並行
- 優化磁碟I/O優化
- 02. I/O 操作
- 從資料庫層面理解:隨機 I/O & 順序 I/O資料庫隨機
- Linux下的5種I/O模型與3組I/O複用Linux模型
- not set asynch I/O limit to nnnn for SQL directo I/O.It is set to 200_848859.1MITSQL
- 流?I/O 操作?阻塞?epoll?
- python 非同步 I/OPython非同步
- 理解I/O Completion Port
- NodeJs 非同步 I/ONodeJS非同步
- Hadoop的I/O操作Hadoop
- Java™ 教程(命令列I/O)Java命令列
- [Oracle Script] check File I/OOracle