SET datestyle = 'ISO'; -- Seed a small table through the http helper (clickhouse_raw_query is http). SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS compression_test'); clickhouse_raw_query ---------------------- (1 row) SELECT clickhouse_raw_query('CREATE DATABASE compression_test'); clickhouse_raw_query ---------------------- (1 row) SELECT clickhouse_raw_query('CREATE TABLE compression_test.t ( c1 Int32, c2 String ) ENGINE = MergeTree ORDER BY c1;'); clickhouse_raw_query ---------------------- (1 row) SELECT clickhouse_raw_query('INSERT INTO compression_test.t SELECT number, format(''row {0}'', toString(number)) FROM numbers(5);'); clickhouse_raw_query ---------------------- (1 row) -- One server, reconfigured per case: ALTER SERVER invalidates the cached -- connection, so each subsequent query reconnects with the new compression. CREATE SERVER comp FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 'compression_test', driver 'binary'); CREATE USER MAPPING FOR CURRENT_USER SERVER comp; CREATE FOREIGN TABLE ft (c1 int, c2 text) SERVER comp OPTIONS (table_name 't'); -- Default compression (lz4) when the option is omitted. SELECT * FROM ft ORDER BY c1; c1 | c2 ----+------- 0 | row 0 1 | row 1 2 | row 2 3 | row 3 4 | row 4 (5 rows) -- Explicit lz4. ALTER SERVER comp OPTIONS (ADD compression 'lz4'); SELECT * FROM ft ORDER BY c1; c1 | c2 ----+------- 0 | row 0 1 | row 1 2 | row 2 3 | row 3 4 | row 4 (5 rows) -- zstd; uppercase exercises case-insensitive parsing. ALTER SERVER comp OPTIONS (SET compression 'ZSTD'); SELECT * FROM ft ORDER BY c1; c1 | c2 ----+------- 0 | row 0 1 | row 1 2 | row 2 3 | row 3 4 | row 4 (5 rows) -- Disabled. ALTER SERVER comp OPTIONS (SET compression 'none'); SELECT * FROM ft ORDER BY c1; c1 | c2 ----+------- 0 | row 0 1 | row 1 2 | row 2 3 | row 3 4 | row 4 (5 rows) -- INSERT round-trips through the compressed write path. ALTER SERVER comp OPTIONS (SET compression 'zstd'); INSERT INTO ft VALUES (100, 'inserted'); SELECT * FROM ft WHERE c1 = 100; c1 | c2 -----+---------- 100 | inserted (1 row) -- Unknown value errors when the connection is opened. ALTER SERVER comp OPTIONS (SET compression 'bogus'); SELECT * FROM ft ORDER BY c1; ERROR: pg_clickhouse: invalid compression "bogus" HINT: valid values: none, lz4, zstd DROP FOREIGN TABLE ft; DROP USER MAPPING FOR CURRENT_USER SERVER comp; SELECT clickhouse_raw_query('DROP DATABASE compression_test'); clickhouse_raw_query ---------------------- (1 row) DROP SERVER comp CASCADE;