type
status
date
slug
summary
tags
category
icon
password
本參數於 8.4 版本已更新 UNIX 默認值為:O_DIRECT if supported, otherwise fsync
因此不太需要特別調整此參數,本篇僅記錄原文研究。
原文
- innodb_flush_method (MySQL 8.0)

設定
flush data
到 InnoDB data files
和 log files
使用的方法,此參數會影響到 IO 吞吐量- fsync(or 0):InnoDB use
fsync() system call
to flush data,這在 5.7、8.0 為默認設定。
- O_DSYNC(or 1):InnoDB use
O_SYNC
to open and flush thelog files
, andfsync()
to flush thedata file
。 InnoDB不直接使用O_DSYNC
因為在許多 Unix 版本上都存在問題。
- littlesync(or 2):此選項用於內部性能測試,目前版本不支持。使用後風險自負。(5.7、8.0)
- nosync(or 3):此選項用於內部性能測試,目前版本不支持。使用後風險自負。(5.7、8.0)
- O_DIRECT(or 4):InnoDB use
O_DIRECT (or directio() on Solaris)
to open thedate files
, and usefsync()
to flush both the data and log files. 此選項在某些 GNU/Linux 版本、 FreeBSD 和 Solaris 上可以使用。
- O_DIRECT_NO_FSYNC:InnoDB use
O_DIRECT
during flushing I/O, but skips thefsync() system call
after each write operation. - 在 5.7.25、8.0.14 之前,此設定不適用於
XFS
、EXT4
等 file system,因這類 file sysetm需要調用fsync()
來同步file system metadata
的變更,如果不確定是否需要請調整為O_DIRECT
。 - 在 5.7.25、8.0.14 開始,在建立新的文件、增加文件大小、關閉文件後這些變更到
file system metadata
的情況才會調用fsync()
,其餘情寫入操作會跳過fsync()
。 - 如果
data files
和log files
儲存在不同的設備,且data files
的儲存設備沒有後備電池,則可能導致數據丟失建議改為使用O_DIRECT
。
在 MySQL 8.0.14 開始,若
innodb_dedicated_server
啟用時,則會將 innodb_flush_method
設定為 O_DIRECT_NO_FSYNC
ㅤ | ㅤ | ㅤ | ㅤ | ㅤ |
fsync | ㅤ | fsync() | ㅤ | fsync() |
O_DSYNC | O_SYNC | O_SYNC | ㅤ | fsync() |
O_DIRECT | ㅤ | fsync() | O_DIRECT | fsync() |
O_DIRECT_NO_FSYNC | ㅤ | ㅤ | ㅤ | ㅤ |