Implementing efficient data history/versioning in django + postgres

I'm trying to track changes to persisted data in a django + postgresql stack by saving operations on rows and 'replaying' events from the beginning (or a smaller number of snapshots) to restore an arbitrary past version. After some research I'm pretty sure I want this to be done via postgresql triggers and that one should store the pg_current_xact_id() value to get a logical order of transactions (is the latter correct?).

Looking around for libraries that do this, django-pghistory seems perfect for this, but upon inspection of the data structures this library only stores UUIDs and timestamps. The former is not ordered and the latter seems prone to race conditions since two parallel transactions can start at the same time (within clock precision). Am I missing something here?

Additionally, I find it essential for performance to save a full snapshot of an object/table after a large number of changes so that the execution time to jump to a specific version does not deteriorate with many changes. However, none of the available solutions I found seem to be doing this. Am I missing something here? Is the performance negligible for most applications? Do people start rolling their own version when it does matter?

Back to Top