Skip to content

KernelMaker/pgStrata

 
 

pgStrata

PostgreSQL with built-in versioned layer storage and Time Travel. See your database as it existed at any point in time.

pgStrata Time Travel Demo

What is this

pgStrata adds a versioned layer storage engine inside PostgreSQL 18. Instead of letting PG write pages directly to disk via md.c, strata shadows all I/O and stores data as immutable (Key, LSN) entries in layer files. PG's own data files stay untouched.

The interesting part: since every version of every page is kept in layers, you can SET a timestamp and query the entire database as it was at that moment. Dropped a table last week? Schema looked different yesterday? Just time travel back.

How it works

An async background worker reads WAL from disk and ingests not only relation page changes but also SLRU (CLOG, multixact), relmapper, checkpoint, and other metadata into an in-memory memtable. When the memtable is full, a flush worker writes it as an immutable L0 layer file. A compaction worker merges L0s into L1 files with narrow key ranges.

When a session enters Time Travel mode, strata intercepts all page reads, collects the relevant deltas from layers, and reconstructs each page at the target LSN.

For Time Travel, SET strata.travel_time resolves your timestamp to an LSN via timestamp-to-LSN mappings stored in the layers, then all reads reconstruct at that historical LSN.

Build & run

./configure --prefix=$(pwd)/build --enable-debug --enable-cassert \
    --enable-tap-tests CFLAGS="-O0 -g3"
make -j$(nproc)
make install

export PATH=$(pwd)/build/bin:$PATH
initdb -D run/data
echo "strata_enabled = on" >> run/data/postgresql.conf
echo "io_method = sync" >> run/data/postgresql.conf
pg_ctl -D run/data -l run/server.log start

psql -d postgres

Strata reconstructs pages synchronously in smgr_readv(), which is not compatible with PG18's async I/O workers. Async I/O support is planned for a future release.

Try Time Travel

CREATE TABLE demo (id serial PRIMARY KEY, name text, amount numeric);
INSERT INTO demo (name, amount) VALUES ('Alice', 100.00);

-- remember this timestamp
SELECT now();  -- e.g., 2026-04-06 10:00:00+00

ALTER TABLE demo ADD COLUMN email text;
INSERT INTO demo (name, amount, email) VALUES ('Bob', 200.00, 'bob@example.com');
DROP TABLE demo;

-- go back
SET strata.travel_time = '2026-04-06 10:00:00+00';
SELECT * FROM demo;  -- table is back, original schema, 1 row

-- back to present
RESET strata.travel_time;

Where things stand

Five phases done, more to go.

Phase What it does
1. Layer Store Library StrataKey, in-memory/delta/image layers, file index, page reconstruction
2. smgr + WAL Ingest Replace md.c with strata, WAL ingest, heap + btree redo engines
3. Full I/O Routing SLRU, relmapper, controlfile, async ingest worker, lock-free snapshots
4. Time Travel SET strata.travel_time for connection-level historical queries
5. Compaction Background compaction worker, L0/L1 two-level disk, layer manifest

Still on the list:

1125 subtests across 20 test files. Run them with:

# Build first (see Build & run above), then:
make -C src/test/strata check

About

PostgreSQL with built-in versioned layer storage and Time Travel. See your database as it existed at any point in time.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

No contributors

Languages

  • C 83.1%
  • PLpgSQL 7.6%
  • Perl 4.8%
  • Yacc 1.2%
  • Meson 0.7%
  • Makefile 0.6%
  • Other 2.0%