Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 8 min read Deep dive hardMaster

Taming PostgreSQL GUC “extra” Data

PostgreSQL GUC check and assign hooks can pre-parse a custom string setting into a structured value, but only if the "extra" data follows the GUC API's memory rules. For pg_clickhouse v0.1.1, the session_settings key/value string moved from per-query parsing to parse-on-assignment after several failed attempts. Mutating session state in the check hook breaks speculative checks and RESET, and allocating in the assign hook risks errors. The working design follows ConvertTimeZoneAbbrevs(): the check hook builds the whole parsed list as one guc_malloc() block using a flexible array member, and the assign hook only assigns the pointer, leaving cleanup to guc.c.

Assumes: C pointers and memory allocationPostgreSQL extension developmentPostgreSQL GUC configuration

Related posts

  • What's New in pg_clickhouse v0.3.2: Postgres 19, TLS, Regex, and Memory

    ClickHouse mediumAdept

    pg_clickhouse v0.3.2, the Postgres extension for querying ClickHouse, adds support for PostgreSQL 19 Beta1 and needs no restart or ALTER EXTENSION UPDATE. New CREATE SERVER options cover TLS behavior (`secure` on/off/auto, `min_tls_version`) and native protocol compression. Regex flag pushdown has been corrected, with a mapping table and a warning that Postgres and ClickHouse treat negated character classes differently around newlines. The release also fixes memory ballooning in repeatedly re-scanned parameterized foreign scans and in unbuffered HTTP queries, pushes down capture-free regexp_match(), and fixes empty-array ANY() errors on older ClickHouse.

  • Memory safety for Postgres extensions in C/C++

    ClickHouse hardMaster

    Postgres's palloc/MemoryContext allocation and setjmp/longjmp-based error handling clash with C++ new/delete, destructors and exceptions: longjmp skips destructors (undefined behavior), exceptions bypass PG_CATCH, and an uncaught exception aborts the process and forces cluster-wide crash recovery. Four ClickHouse extensions each take a different approach. pg_clickhouse replaces C++ entirely with a new C library (clickhouse-c), and pg_re2 confines C++ to a wrapper that never calls Postgres. pg_chdb moves libchdb into a separate forked helper executable so its crashes don't trigger recovery. pg_stat_ch routes std::terminate through ereport(FATAL) in a background worker, which is a mitigation rather than true isolation, and plans to move to the helper-process model.

  • pg_clickhouse & chdb updates: Encoding, nesting, and types

    ClickHouse mediumAdept

    pg_clickhouse v0.11.0 and the chdb extension v0.1.2 improve Postgres–ClickHouse type compatibility. A new `check_encoding` option (fail, remove, replace, truncate) handles invalidly encoded text, and ClickHouse Interval types now import as Postgres `interval` with pushdown of expressions like `start_at + duration`. Parameterized JSON columns map to jsonb so `ORDER BY` on a property pushes down correctly, and unflattened Nested columns map to 2-D text arrays or to matching composite-type arrays. The release also adds mappings for large integers, geo and time types, pushes down the sha*/digest functions, removes `clickhouse_raw_query()` and drops PostgreSQL 13 support.

  • What's New in pg_clickhouse - JSONB Support, SQL value functions, Streaming, and more

    ClickHouse mediumAdept

    pg_clickhouse, the Postgres foreign data wrapper for querying ClickHouse, now pushes down far more operations to ClickHouse. JSONB accessors (->, ->>, jsonb_extract_path) are translated to ClickHouse sub-column syntax. CURRENT_DATE, CURRENT_TIMESTAMP and clock_timestamp() are translated to ClickHouse now()/now64()/nowInBlock64 calls that use the Postgres session time zone and timestamp precision. Array functions now map to their ClickHouse equivalents. Streaming of HTTP driver results in roughly 50MB batches kept container memory under about 100MiB during a full NYC taxi table scan, versus about 600MiB without it.

  • You can’t UPDATE what you can’t find: ClickHouse vs PostgreSQL

    ClickHouse mediumAdept

    ClickHouse 25.7's SQL-standard UPDATEs were benchmarked against PostgreSQL 17.5 on identical hardware using the 600M-row TPC-H lineitem table, with cold and hot runs. ClickHouse wins bulk updates by up to 4,000× because most bulk WHERE clauses can't use the primary key index. That forces full scans, where PostgreSQL takes 380–390 s and ClickHouse's columnar, parallel scan takes 0.09–5.23 s. Point updates are roughly at parity and cached point updates stay competitive. The comparison isn't apples-to-apples: PostgreSQL wraps every statement in a transaction and fsyncs WAL at commit by default, while ClickHouse skips per-statement transactions and defaults to fsync_after_insert=false.

The quest for software engineering knowledge.

Look:
Layout: