Thin PostgreSQL Clones
github.com
github.com
The shell script that implements the idea with LVM snapshots (relies on an existing Postgres physical replica) is not too long. It's used over SSH.
$ wc -l /usr/local/bin/snapshot-*
164 /usr/local/bin/snapshot-create
16 /usr/local/bin/snapshot-drop
180 total
Had this tool existed at the time, I'd have probably used it (monitoring and REST API might be handy). Still, the core idea can be implemented very easily.[1]: https://www.sedlakovi.org/blog/2019/03/fast-postgres-snapsho...
All that's left is to diff what's changed between clone and main database, and merge the changes back up for a full, safe workflow for master data and content management.
(Postgres.ai founder here)
I've previously spent a fair bit of time tuning postgres for fast/less durable settings to speed up testing, and this puts all of that to shame when you need to start with any non-trivial schema/data and revert back to it.
I had been testing out some ideas with `docker commit` to save derived images which included a premade db, then reverting to that, but I don't think it's worth bothering with since I found dblab.
Haven't yet tried using it CI, and I suspect it might need a somewhat-custom-than-normal VM setup to use ZFS than you could easily do on most hosted CI runners, but it's on my list of things to investigate/setup eventually.
For more real-life feedback, welcome to the Database Lab Community Slack: https://slack.postgres.ai/
In one company, it grew into a cluster of a few servers for higher capacity and availability. This load balancing and management code is a quite more complex than the original single-server snapshotting script. Unfortunately, it's not open source. For several years, the single server was enough. Go for it. :-)
How do you specify data types for columns or schema names for tables?
For modern Postgres versions it's also recommended to use standard compliant identity columns rather than the proprietary serial "types"
>How do you specify data types for columns or schema names for tables?
For now, to keep it simple, all datatypes will be created as varchar and foreign keys as int, to declare any other column as int, need to write id keyword anywhere in name when defining syntax.
> For modern Postgres versions it's also recommended to use standard compliant identity columns rather than the proprietary serial "types"I have ran it in Postgres version 14 using psql(shell) and it is working fine, but I shall look into it.
Thanks for reviewing it Thanks
I am struggling to come up with scenarios where that would be a good idea.
If the data is too big to fit on my machine, I might clone to a nearby colocated server. Testing your DB backup and restoration mechanism becomes even MORE important if you have huge amounts of data.
With something like this https://www.getsynth.com/docs/blog/2021/03/09/postgres-data-... (disclaimer: no affiliation with them, I've not used their product but it appears to be fully open source)
Random data may give incorrect results when optimizing a query.
in a team: 10 developers working on 32 issues: --> need at least 32 separated environments.
To make this more complex, it's not a simple process where I read vendor data then generate analysis. My model is generated in several steps, which involves reading vendor data, generating output, then combining the output I generated in a previous step with more vendor data to generate the next step of output.
Backtests are "prod-like" in that they must use real vendor data and must generate correct results that drive business decisions. But they are "dev-like" since I don't want my backtest to interfere with my production system, which generates the version of the model that I currently trade. For a backtest I might want to make a new database table, or change the behavior of an existing process that generates data.
I've tried 2 solutions to this: One is have classes to handle all data reads and writes, and configuration that causes functions to read or write from a dev or production DB as needed. This is a pain to set up, but works well.
The other solution is DB clones. One advantage of DB clones is that it lets me write SQL that joins data I've generated on vendor data. I don't love having business logic in SQL for the obvious reasons, but it can be very performant and easy to maintain. Using classes for data access means that I can't easily do a SQL join between vendor data (which is always on the production DB) and data I generate (which might be on the dev DB.)
Database Lab Engine provides some possible solutions to protect sensitive data: https://postgres.ai/docs/database-lab/masking
By the way, the Database Lab Engine maintainer is here.