tuple_fdw
tuple_fdw · Proof-of-concept C foreign data wrapper for append-only, LZ4-compressed binary tuple files used as cold storage.
Overview
Usage
Sources:
tuple_fdw stores PostgreSQL heap tuples in an append-only external binary file made of checksummed, LZ4-compressed blocks. It supports sequential reads and inserts while bypassing PostgreSQL’s buffer cache and autovacuum. It is experimental cold storage, not a transactional table replacement.
Core Workflow
Install liblz4 on the PostgreSQL server, create the extension and server, then define a foreign table with an absolute server-side file path. The validator creates a missing file using the PostgreSQL operating-system account.
Bulk insert in the intended physical order, then query normally. The FDW implements INSERT but not UPDATE or DELETE.
Foreign-Table Options
filename: required file path; created if absent.use_mmap: use memory-mapped reads instead offread; it can help read-heavy concurrency but does not make writes concurrent-safe.sorted: space-separated column names that tell the planner the file is ordered.lz4_acceleration: LZ4 speed/compression tradeoff, default1; higher values favor speed over compression ratio.
The sorted option is a promise, not an enforcement mechanism. If the physical file is not actually ordered by those columns, the planner can choose an invalid order-dependent plan and return wrong results.
Durability, Concurrency, and Portability
The external file is outside PostgreSQL WAL, MVCC, transaction rollback, logical/physical replication, and ordinary base-backup management. Although writes are fsynced and the FDW takes a relation lock, an aborted transaction does not undo file changes, and another database, foreign table, process, or host can access the same path without that lock. Upstream explicitly disallows concurrent writes and mixed concurrent reads/writes.
Single-row inserts repeatedly decompress and recompress the last block, so use bulk loads. The file stores raw heap-tuple bytes and depends on the foreign-table row layout and PostgreSQL binary representation; do not attach a different schema, architecture, or PostgreSQL build to an existing file without a proven migration. Back up and restore the file with an external, quiesced procedure, and verify its checksum and row count before exposing it again. mmap readers also require the file not to be replaced or truncated underneath them.