3

I saw that it is not a good idea to use btrfs CoW functionality for big files, such as data directories of a PostgreSQL database.

Since I use docker for databases, I now ask myself, if I should disable CoW for the whole /var/lib/docker directory. But I'm not sure, because docker's layered filesystem makes use of this feature, or not?

Or is it possible, to disable CoW for just some specific volumes?

0

I don't think docker directly plugs into BTRFS (or any filesystem) CoW behavior; rather, it can use snapshots and/or reflinks to avoid replicating entire container images.

While disabling CoW will be surely benefical for performance, be aware that:

  • disabling it means no data checksum, so no protection against data loss;
  • snapshotting a volume automatically re-enables CoW;
  • reflink will not work anymore;
  • existing file will remain CoW-enabled (until you delete and recreate them).

While for a database (as PostgreSQL) the above points can be non-issues (ie: data checksum is done at the DB record level and snapshots are provided by the transactional layer), for a VM or container missing these features can be problematic.

Anyway, I really suggest you to read the BTRFS FAQ about nodatacow

1
  • 1
    When using docker on top of a btrfs filesystem, it creates a directory called /var/lib/docker/btrfs containing BTRFS subvolumes. So this looks like docker plugs into filesystem specific features. – Ethan Leroy Oct 8 '19 at 13:51
0

Put the following in /etc/docker/daemon.json:

{
    "storage-driver": "btrfs"
}

and disable copy-on-write on your volumes if they contain databases:

mkdir /var/lib/docker/volumes
chattr +C /var/lib/docker/volumes

Hoping that helps.

1
  • It's important, that the directory does not exists yet. chattr +C on a directory does only affect new files and directories in it. Enabling nodatacow on /var/lib/docker/volumes is only affecting new volumes. You should not disable CoW totally. I recommend to use a prepared directory as bind mount for database files and writeable image files. – sausix Jan 18 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.