NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
COMPRESSION NEW IN 1.1.0

Compress the columns that pay for it.

zstd compression per column or per row, at the level you choose, with trained dictionaries. Nothing is compressed unless a column or a table asks, so nothing pays for it by default.

Built into every 1.1.0 server. A directory that holds a compressed value cannot be opened by an older build.

1 / 3

Per column, per row

SQL
-- each value its own frame; 1 = fastest .. 22 = smallest
CREATE TABLE docs (id INT PRIMARY KEY,
                   body JSONB COMPRESSION zstd(9),
                   note TEXT  COMPRESSION zstd);
ALTER TABLE docs ALTER COLUMN note SET COMPRESSION zstd(19);

-- every text, jsonb, bytea and array value of a row in one frame
CREATE TABLE events (id INT, kind TEXT, msg TEXT) WITH (row_compression = 'zstd(6)');

-- rewrite what is stored, training dictionaries
ALTER TABLE docs RECOMPRESS;
SHOW TABLE STATS docs;   -- compression_raw_bytes, compression_stored_bytes
2 / 3

In the ORM

The migrator compares the model with what the table has and sets or resets compression to match. It never rewrites stored rows on its own: RECOMPRESS is the operator's call.

Rust
#[derive(Model)]
#[rdb(table = "events", row_compression = "zstd(6)")]
struct Event { #[rdb(primary_key)] id: i32, kind: String, msg: String }

#[derive(Model)]
struct Doc {
    #[rdb(primary_key)] id: i32,
    #[rdb(json, compression = "zstd(9)")] body: serde_json::Value,
    #[rdb(compression)] note: String,
}
3 / 3

What to compress

  • Documents, logs and long text, where zstd pays back many times
  • Cold history moving to S3: fewer bytes stored and transferred
  • Not keys or short columns you filter on constantly: the filter index already makes those cheap to scan
✓ page rendered in 99 µs axum + tera + htmx · no other javascript