by brilliantcode · 9y ago · 0 comments
but I dream the dream...
There are other "remember everything" schemes you can play with clever triggers, but it always comes back to how you end up using the stored data and how easy it is to bring it back to a queryable state.
However, nothing about pgSQL is designed for this approach, so i imagine the performance would be terrible.
Interestingly enough, that was a part of the original design from the Berkeley days.
http://db.cs.berkeley.edu/papers/ERL-M85-95.pdf
Our proposed approach is to treat the log as normal data managed by the DBMS which will simplify the recovery code and simultaneously provide support for access to the historical data.
...
3.3. Time Varying Data
POSTQUEL allows users to save and query historical data and versions [KATZ85, WOOD83]. By default, data in a relation is never deleted or updated. Conventional retrievals always access the current tuples in the relation. Historical data can be accessed by indicating the desired time when defining a tuple variable.
...
Finally, POSTGRES provides support for versions. A version can be created from a relation or a snapshot. Updates to a version do not modify the underlying relation and updates to the underlying relation will be visible through the version unless the value has been modified in the version.
One of the purposes of the much-maligned VACUUM command was to push the historical data to archival (optical) media.
The archival store holds historical records, and the vacuum demon can ensure that ALL archival records are valid.
> POSTQUEL allows users to save and query historical data and versions [KATZ85, WOOD83]. By default, data in a relation is never deleted or updated. Conventional retrievals always access the current tuples in the relation. Historical data can be accessed by indicating the desired time when defining a tuple variable.
Or, to put it another way [1]:
"Since one can't change the past, this implies that the database accumulates facts, rather than updates places, and that while the past may be forgotten, it is immutable."
&:)
[1] https://www.infoq.com/articles/Datomic-Information-Model
[1] https://www.postgresql.org/docs/current/static/contrib-spi.h...
Let me just say: it's a very interesting approach, but it's also very complicated and has a large overhead in development time and infrastructure complexity.
For most problems, it's A LOT easier to do classic CRUD + some distributed task queue.
You can combine those two. It's pretty easy to just emit an additional event for each write into some event store (Apache Kafka, Postgres, whatever), so you can get a 'best of both worlds' state.
Postgres's logical replication slots do provide way to implement your own change streaming.