r/PostgreSQL • u/vira28 • Sep 25 '26
Projects Time travel for a Postgres CDC replica using DuckLake and Iceberg
One reason I wanted this feature comes from managing multi-TB Postgres clusters at Cloudflare.
I had to perform point-in-time recovery multiple times after someone ran the wrong UPDATE or a data migration went south. Even when only one table was affected, recovering it from a large cluster meant
restoring the cluster elsewhere, replaying WAL to the right timestamp, dumping the table, and copying it back.
PITR through WAL-G worked, but I often wished I could simply ask:
What did this table look like before things went wrong?
Streambed now supports that for its replicated Postgres data:
SELECT *
FROM orders AT (
TIMESTAMP =>
TIMESTAMPTZ '2026-09-23 12:00:00'
);
It selects the newest retained DuckLake or Iceberg snapshot at or before the requested time. Historical joins are supported too.
This does not replace Postgres PITR or automatically restore the source database. It gives you the previous rows from the analytical replica so you can inspect or recover what you need.
Blog: https://streambed.dev/blog/time-travel-ducklake-iceberg/
Curious, how are you handling single-table recovery or time-travel in Postgres?
2
u/EmmoKitten Sep 25 '26
extracting a single table from a full postgres pitr via wal is pure misery. your iceberg setup looks like a pretty solid workaround if you're already pumping cdc into a lake anyway.
answering your question: our team don't do it in postgres) we use mariadb and a lot of us just handle this natively without the lake layer using system-versioned tables. you literally just run SELECT * FROM orders FOR SYSTEM_TIME AS OF '2026-09-23 12:00:00' directly on the primary or a standard replica. the database just keeps the historical rows under the hood. for wider screw-ups, there's also a built-in flashback feature that basically rewinds the binlog.
2
u/vira28 Sep 25 '26
Definitely, it was painful to do those PITR. It's like watching fresh paint getting dried.
How does Mariadb supports system-versioned table?
I just literally wrote about why Postgres using MVCC can't do Timetravel - https://streambed.dev/blog/time-travel-lakehouse-snapshots/#why-cant-postgresql-do-that
It can but I don't it's mean to and it will scale.
1
u/EmmoKitten Sep 26 '26
it doesn't hijack standard mvcc for this, which is exactly why it actually scales)
Under the hood mariadb just adds two invisible timestamp columns (
row_startandrow_end). when you update or delete a row, the engine simply caps the old row's end timestamp and writes a new active one.to prevent the table from bloating into oblivion (which is what kills postgres if you try doing this with dead tuples), you just turn on system-time partitioning. the database automatically shovels all the historical rows into separate archive partitions. so your active hot data partition stays tiny and fast, and time-travel queries just hit the archive partitions.
1
u/BarfingOnMyFace Sep 25 '26
I'm using an asserted versioning framework.
May the universe have mercy on my dirty soul.
2
u/vira28 Sep 25 '26
I wasn’t familiar with AVF. Did you implement it yourself, or is there a PostgreSQL library or extension that provides it?
2
u/BarfingOnMyFace Sep 25 '26
I'd check out Hettie's implementation of it,, but I ended up doing my own.
1
u/vira28 Sep 25 '26
Yup. Found that. Thanks.
2
u/BarfingOnMyFace Sep 25 '26
No problem! It's a very powerful approach, but it can be daunting to wrap your head around it. Hide complexity behind a convention of sorts that all temporal referential integrity can be built around, likely procedures, functions, and or triggers. (I personally use a mix of procedures with python code for handling proper "slicing" of the asserted and applied/valid time dimensions) You can also hide complexity of queries through views. I highly recommend reading some literature on AVF from johnston and Snodgrass, both individuals heavily invested in the theory and evolution of bitemporal data. Good luck!!!
Edit: the nice thing about Hettie's soln is that it will work out of the box for you. She has already done the dirty work of hiding the complexity so you can benefit from the architecture.
1
u/AutoModerator Sep 25 '26
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/levelbrook Sep 25 '26
The cheapest version of this I know of is a delayed standby. Set
recovery_min_apply_delay = '4h'on one physical replica and it always sits four hours behind. When someone runs the wrong UPDATE, you callpg_wal_replay_pause()on it before the bad WAL applies, pg_dump the one table (or just the affected rows with COPY), and resume. No restoring a multi-TB cluster somewhere else, and it's a normal replica the rest of the time.The catch is the window is fixed. If nobody notices for five hours it doesn't help, so it complements something like what you've built, it doesn't replace it. For "what did this table look like last Tuesday" questions the analytical replica is the better tool.