我一直認為mysql的logfile,就是data檔案下那幾個ib_logfile就是在硬碟上的,但是今天看到關于innodb_flush_log_at_trx_commit引數的解釋后迷茫了,其中一段解釋如下:
With a value of 2, the contents of the InnoDB log buffer are written to the log file after each transaction commit and the log file is flushed to disk approximately once per second. Once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues. Because the flush to disk operation only occurs approximately once per second, you can lose up to a second of transactions in an operating system crash or a power outage.
很奇怪,這里的意思我感覺是:logfile是駐留在記憶體中(或檔案系統快取中?),設為2后先從log buffer寫入logfile,再從快取中的logfile寫入disk上的logfile? logfile
uj5u.com熱心網友回復:
難道不應該是log buffer直接flush到disk上的logfile嗎,怎么看官網解釋中間還多了一層uj5u.com熱心網友回復:
樓主這個鏈接解釋得挺清楚的:http://blog.csdn.net/liqfyiyi/article/details/51137764
寫只是寫到作業系統的記憶體中,刷才是持久化到磁盤。設定為2會在事務提交的時候寫到作業系統的內容,但是重繪還是每秒的。斷電的時候也可能丟失超過一秒的事務。
uj5u.com熱心網友回復:
回復樓上:以上英文片段是官網5.6版本的原文。
在查閱了大量中英文資料比對后,我暫時作如下結論:
在官網正確的前提下,'log buffer are written to the log file'是指呼叫write()方法將redo log buffer寫入OS檔案系統快取,‘log file is flushed to disk’是指呼叫fsync()方法將檔案系統快取寫入disk,這意味這段里邊的log file是指的檔案系統快取里的log file,在disk上的log file塊檔案則直接用disk蓋過去了。
這意味著mysql的寫日志還會考慮檔案系統快取這一層,也可能是因為oracle和sqlserver原始碼不公開,這部分直接被大家忽略了而已。
uj5u.com熱心網友回復:
這個我也一直沒弄懂我的理解似乎是 myql 接管了磁盤高速快取
Linux 不太清楚,Windows 的磁盤有高速快取這個東東,寫檔案是寫這個,然后從這個真正寫入磁盤(物理寫入)
uj5u.com熱心網友回復:
剛才又翻了下檔案,我前面說的應該不對,應該是 mysql 自己的 bufferThe innodb_flush_method options for Unix-like systems include:
fsync: InnoDB uses the fsync() system call to flush both the data and log files. fsync is the default setting.
The innodb_flush_method options for Windows systems include:
async_unbuffered: InnoDB uses Windows asynchronous I/O and non-buffered I/O. async_unbuffered is the default setting on Windows systems.
----------------- 這個說明默認是用作業系統的 flush,那么 mysql 的那個 buffer 跟作業系統的 flush 時的 buffer 就無關了
uj5u.com熱心網友回復:
上午我總結了一篇博客,暫時計劃這么理解:http://www.cnblogs.com/leohahah/p/8176553.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/99581.html
標籤:MySQL
上一篇:求一條mysql陳述句
下一篇:Mysql sql陳述句優化問題
