4.2. CFS (Compressed File System) #

CFS enables page-level compression in Shardman. Compression can only be enabled for separate tablespaces. To compress a tablespace, you need to enable the compression option when creating this tablespace. For example:

CREATE TABLESPACE data LOCATION '/mnt/data-{rgid}' WITH (global, compression='zlib');

Now you can create tables and indexes in this tablespace or move existing table or index to it.

CREATE TABLE pgbench_branches (
       bid integer NOT NULL PRIMARY KEY USING INDEX TABLESPACE data,
       bbalance integer,
       filler character(88)
)
WITH (distributed_by = 'bid') TABLESPACE data;

The table compression ratio can be estimated using the cfs_estimate(relation) function. This function takes the first ten percent of relation blocks (but no more than 100 blocks), compresses them, and returns the average compression ratio. For example, a value of 7.8 indicates that the compressed table will occupy about eight times less space than the original. The calculation is performed for all available compression algorithms.

Warning

cfs_estimate(relation) should be used only after a checkpoint to avoid incorrect estimations.

The cfs_compression_ratio() function returns the actual compression ratio for all segments of the compressed relation. However, it returns NaN for partitioned and foreign tables, so it works only for local partitions of a sharded table.

Complete CFS documentation can be found here.