How to show compression ratio on ZFS

I have two servers. One is running Ubuntu Linux with ext4 filesystem and another is FreeBSD server with ZFS. When I run du -ch on both FreeBSD and Ubuntu I get different file size.

cd /app/
du -ch

Both are syncd using rsync but I get:

  • FreeBSD ZFS : 46GB
  • Ubuntu Linux ext4: 58GB

I know ZFS have compression. How can I see compression ratio on ZFS for /app/? Can I see detailed report about compression ratio on ZFS for each dataset and pool?

You can use the following commands when using zfs on FreeBSD or Solaris Unix or Linux:

To check ZFS compression

zfs get compression storage
zfs get compression zroot
zfs get compression tank
zfs get compression  zroot/webroot

How to check compression ratio when using zfs

Try the following command:

zfs get compressratio storage
zfs get compressratio zroot
zfs get compressratio tank
zfs get compressratio zroot/webroot

Here is what I see from the last command running on FreeBSD with zroot:

NAME             PROPERTY       VALUE  SOURCE
zroot/rsnapshot  compressratio  1.37x  -

To see all properties run:

zpool get all storage
zpool get all tank
zpool get all zroot/jails

How to set ZFS compression

The syntax is:

zfs set compression=on {STORAGE}
zfs set compression=on zroot/backups
zfs get compression zroot/backups

See zfs man page[1]:

man zfs

[1]https://www.freebsd.org/cgi/man.cgi?zfs

What about refcompressratio as told in man page? It was useful for me too to see the compression ratio for the ZFS dataset on the pool

zfs get refcompressratio zroot/var/log

It said the refcompressratio will only show the compression ratio for that specific dataset, not the descendant datasets. To include the child datasets, the command looks like this:

zfs get compressratio zroot/var

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki