I recently created a ZFS volume to test its compression capabilities. I'm comparing it side by side to an ext4 volume. After creating the new volume and turning compression on with sudo zfs set compression=gzip postgres-zfs
I copied a ~3GB file from the ext4 volume to the ZFS file but the file is the same exact size on the ZFS drive (I used ls -alh
to see this). I gzipped the file manually to see what the compression should be (I understand there are different levels but just to get a ballpark) and just using gzip file
the file size was cut in half. My ZFS settings also show compression is turned on:
# zfs get all
NAME PROPERTY VALUE SOURCE
postgres-zfs type filesystem -
postgres-zfs creation Thu Apr 5 17:17 2018 -
postgres-zfs used 1.54G -
postgres-zfs available 143G -
postgres-zfs referenced 1.54G -
postgres-zfs compressratio 1.34x -
postgres-zfs mounted yes -
postgres-zfs quota none default
postgres-zfs reservation none default
postgres-zfs recordsize 128K default
postgres-zfs mountpoint /postgres-zfs default
postgres-zfs sharenfs off default
postgres-zfs checksum on default
postgres-zfs compression gzip local
postgres-zfs atime on default
postgres-zfs devices on default
postgres-zfs exec on default
postgres-zfs setuid on default
postgres-zfs readonly off default
postgres-zfs zoned off default
postgres-zfs snapdir hidden default
postgres-zfs aclinherit restricted default
postgres-zfs canmount on default
postgres-zfs xattr on default
postgres-zfs copies 1 default
postgres-zfs version 5 -
postgres-zfs utf8only off -
postgres-zfs normalization none -
postgres-zfs casesensitivity sensitive -
postgres-zfs vscan off default
postgres-zfs nbmand off default
postgres-zfs sharesmb off default
postgres-zfs refquota none default
postgres-zfs refreservation none default
postgres-zfs primarycache all default
postgres-zfs secondarycache all default
postgres-zfs usedbysnapshots 0 -
postgres-zfs usedbydataset 1.54G -
postgres-zfs usedbychildren 132K -
postgres-zfs usedbyrefreservation 0 -
postgres-zfs logbias latency default
postgres-zfs dedup off default
postgres-zfs mlslabel none default
postgres-zfs sync standard default
postgres-zfs refcompressratio 1.34x -
postgres-zfs written 1.54G -
postgres-zfs logicalused 2.07G -
postgres-zfs logicalreferenced 2.07G -
postgres-zfs filesystem_limit none default
postgres-zfs snapshot_limit none default
postgres-zfs filesystem_count none default
postgres-zfs snapshot_count none default
postgres-zfs snapdev hidden default
postgres-zfs acltype off default
postgres-zfs context none default
postgres-zfs fscontext none default
postgres-zfs defcontext none default
postgres-zfs rootcontext none default
postgres-zfs relatime on temporary
postgres-zfs redundant_metadata all default
postgres-zfs overlay off default
Any idea why this data is not being stored compressed?
The data is compressed, just the OS itself can't recognize the compression through normal commands, as the files are transparently decompressed when you access them.
In that list of the ZFS settings you see an entry called
compressratio
, which in your case reads x1.34. This shows how efficiently the files were compressed (on average):compressed size * compressratio = uncompressed size
You can also see used and logicalused, which display the absolute compressed size and absolute uncompressed size of the complete pool (although logicalused doesn't seem to match up with the mentioned filesize of the test file).
You can find more information about those values here
I also put together a short list containing all the commands and what they output:
ls
: Shows the uncompressed size on files, but the compressed size on folderszfs get used <pool>
: Shows the compressed space of all files in the poolzfs get logicalused <pool>
: Shows the uncompressed space that all the files in the pool would usezfs get compressratio <pool>
: Shows the average compressratio of the pooldu -h --apparent-size
: Shows the uncompressed size of the given files/foldersdu -h
: Shows the compressed size of the given files/folders