Thread

  1. Support specifying compression level in wal_compression

    Nikolay Samokhvalov <nik@postgres.ai> — 2025-05-27T09:08:53Z

    I thought it makes sense to extend wal_compression to support compression
    levels.
    
    The patch replaces the simple enum-based setting with string-based
    'method[:level]' syntax, similar to the --compress option in pg_dump.
    
    What's inside:
    - Unified GUC design: wal_compression = 'method[:level]'
    - Supported formats: 'off', 'on', 'pglz', 'lz4[:level]', 'zstd[:level]'
    - Algorithm-specific defaults: LZ4 defaults to level 1, ZSTD to level 3
    when no level is specified.
    - Parameter validation is performed at SET time.
    - The string is parsed only once during GUC assignment.
    - Backward compatibility for common settings: While the GUC type changes
    from enum to string, common previous boolean-like string values (e.g.,
    'off', 'true', '0') are handled, mapping to 'pglz' or 'off' correspondingly.
    - Includes docs change proposal, as well extensive new regression and TAP
    tests.
    
    Additionally, it adds LZ4HC support -- for LZ4, if levels 10-12 are
    specified, then, when available (checked at build time + runtime), it's
    supposed to use LZ4HC for higher compression ratio. This part needs
    additional testing.
    
    
    Originally, I considered adding wal_compression_level but eventually
    decided to exten wal_compression, because of two reasons:
    1. with a separate param, a question of defaults needs to be solved, and I
    didn't find an elegant solution;
    2. "method:level" syntax is already used in another place – pg_dump
    
    An early version of this patch was reviewed by Andrey Borodin off-list, and
    it was extremely helpful.
    
    looking forward to seeing feedback
    
    Nik