Disabling disk caching in Ubuntu
来源:互联网 发布:淘宝店铺招牌素材 编辑:程序博客网 时间:2024/06/06 08:34
Amongst the many interesting discussions I had at Build Stuff last week was about how it’s desirable to switch off disk caching for the disks used for Event Store databases to help ensure that data is durable in the face of power failures.
This is actually true of many databases, indeed, postgres gives you a warning about the possible dire consequences of having write caching switched on when you may experience power failure.
You can find out fairly easily whether disk caching is enabled on your disk or not by using the hdparm
utility, like this:
$sudo hdparm -i /dev/sdaModel=INTEL SSDMCEAC060B3, FwRev=LLLi, SerialNo=CVLI303201QK060KConfig={ Fixed }RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSec=16CurrCHS=16383/16/63, CurSecs=16514064, LBA=yes, LBAsects=117231408IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}PIO modes: pio0 pio3 pio4DMA modes: mdma0 mdma1 mdma2UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 udma6AdvancedPM=yes: unknown setting WriteCache=enabledDrive confirms to: unknown: ATA/ATAP-2,3,4,5,6,7
* signifies the current active mode
The important part here is in bold, WriteCache=enabled
, which is not what we want! To disable the write cache, edit /etc/hdparm.conf
, and uncomment the second of these two lines so that it looks like this:
# -W Disable/enable the IDE drive's write-caching featurewrite_cache = offAfter a restart, the output of hdparm -i /dev/sda should look like this:$sudo hdparm -i /dev/sdaModel=INTEL SSDMCEAC060B3, FwRev=LLLi, SerialNo=CVLI303201QK060KConfig={ Fixed }RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSec=16CurrCHS=16383/16/63, CurSecs=16514064, LBA=yes, LBAsects=117231408IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}PIO modes: pio0 pio3 pio4DMA modes: mdma0 mdma1 mdma2UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 udma6AdvancedPM=yes: unknown setting WriteCache=disabledDrive confirms to: unknown: ATA/ATAP-2,3,4,5,6,7* signifies the current active mode
Obviously here you should replace /dev/sda
with whichever device your database is on!
Note that simply disabling drive caching is actually not enough to ensure that writes are durable – many drives still misbehave (especially the Intel 520 series SSDs)!
- Disabling disk caching in Ubuntu
- Disabling the Laptop TouchPad in Ubuntu Linux
- How to resize disk partitions in ubuntu
- Caching in ASP.NET
- Caching in Cassandra 1.1
- Advanced Caching in Rails
- Caching in .Net
- Disabling Shortcut Keys in Full Screen mode
- Disabling baloo indexer in Kali KDE
- Caching in ASP.NET MVC
- Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio
- Disabling Copy/Paste in a Textbox control in C#
- about ubuntu hard disk
- ubuntu - yandex disk
- ubuntu add disk
- Ubuntu /Boot disk full
- Disabling the flood of kernel messages in Debian console
- [JAVA] 禁用HTTPS认证(Disabling Certification validation in HTTPS)
- 如何断点调试多线程? .
- Dede二次开发程序详解(dede爱好者必备)
- C# textBox用法总结 [持续更新]
- Java:String、StringBuffer和StringBuilder的区别
- hiho一下 第二十七周:最小生成树二·Kruscal算法
- Disabling disk caching in Ubuntu
- LeetCode Construct Binary Tree from Inorder and Postorder Traversal
- Appium 服务器端从启动到case完成的活动分析
- Linux RHEL4下安装SNMP并配置
- nyoj 915 +-字符串
- DedeCMS-ajax无刷新会员登录修改方法
- Android JNI的第一步——从HelloWorld开始
- 新手如何学好PHP
- 著名黑客雷蒙评价最重要的几种编程语言