Event Store logo

sss https://eventstore.org Menu

Developer Blog

Disabling disk caching in Ubuntu

  |   Written by: James Nugent   |   Articles

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/sda

Model=INTEL SSDMCEAC060B3, FwRev=LLLi, SerialNo=CVLI303201QK060K
Config={ Fixed }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSec=16
CurrCHS=16383/16/63, CurSecs=16514064, LBA=yes, LBAsects=117231408
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes:  pio0 pio3 pio4
DMA modes:  mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 udma6
AdvancedPM=yes: unknown setting <strong>WriteCache=enabled</strong>
Drive confirms to: unknown:  ATA/ATAP-2,3,4,5,6,7

* signifies the current active mode
THISDFGJSDGKSJFGNJSDHFGNKSDJFNSJFHGN<ASDFKNSKFGHNSRKNSKDHNFNKXdfHGNDMFHGNDJKFHGSKDJFNDKFGNDKFJGDKFGNDKRGNDFG<JNDcKVUNSKGND<BJNXKGHNDFKGNDFMGJNDFG

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 feature
write_cache = off
After a restart, the output of hdparm -i /dev/sda should look like this:

$sudo hdparm -i /dev/sda

Model=INTEL SSDMCEAC060B3, FwRev=LLLi, SerialNo=CVLI303201QK060K
Config={ Fixed }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSec=16
CurrCHS=16383/16/63, CurSecs=16514064, LBA=yes, LBAsects=117231408
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes:  pio0 pio3 pio4
DMA modes:  mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 udma6
AdvancedPM=yes: unknown setting WriteCache=disabled
Drive 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)!


Subscribe to the Event Store blog

Get the latest news and tutorials when they are released

You might also like

    Guest post: Subscription service for Event Store

      |   Written by: Steven Blair   |   Articles

    VME Retail have released version 1.0.0 of their Subscription Service, which is intended to make life that little bit easier for delivering events from Event Store to clients. The Subscription Service has been used privately by VME Retail Ltd for a few years in various solutions, and they have decided to open the code up to the rest of the Event Store community.

    Read article

    Case Study: How Event Sourcing is Spurring Linedata’s Digital Transformation

      |   Written by: Dave Remy   |   Articles

    Event sourcing is relatively new to the financial services industry. By implementing Event Store’s approach to support its digital transformation strategy, Linedata can be more responsive to the changing needs of its customers and gain a competitive edge in the market. “The core benefits of event-driven architecture allowed us to improve quality, performance and respond quickly to our customers,” said Adrian Tovey, who leads Linedata’s global program management. “Event Store has helped us meet the demand for change in the industry, a change in the way applications are used to deliver services to our customers; Linedata is at the forefront of those changes.”

    Read article

    Testing Event Store HA

      |   Written by: Greg Young   |   Articles

    As we prepare to release Event Store 2.0.0 binaries (the source code was just merged to the master branch over on GitHub), we also will be opening up access to one of the test environments that we’ve been using for our commercial high availability clustered product, Event Store HA. We get many questions asking how the clustered version behaves during network partitions and server failures – now you can see for yourself! The cluster in...

    Read article