
On Sun, Mar 14, 2021 at 04:06:41AM +0500, Ignat Insarov wrote:
Do you know where the majority of the time is spent? I.e. can you just drop the schema without re-creating the cluster? I'd guess it'd be fast but I don't know your setup.
The first step would be to keep the cluster, yes. It takes a few seconds, although we can use a `tmpfs` backed by RAM to cut this down to about one second. But initializing the data base from prepared `*.sql` files also takes a few seconds.
I don't know your setup but if the problem is not with the creation of your schema it does feel like a waste to tear it down and re-create it from a tmpfs each time.
At $WORK we do this: property tests on PSQL data dropping data between tests, but we know which tables are modified so we can just truncate the affected ones.
So how exactly do you do that? Like, do you write the SQL statements needed to reset the data base for every check by hand? And what sort of statements do you use? Do you drop the table or delete the rows?
Depends on the test but it's a lot more common to just call "truncate table foo" when necessary.
It would be ideal if I could somehow detect the tables that were touched and reset them automatically. But I cannot think of a simple way to do that. I cannot simply erase all the data because some data needs to be in place for the application to even start.
It's possible I'm answering an X/Y question[0] right now, but: - Can you create a function that populates this essential data and only call that function after truncating? - If your data is timestamped you could always delete all "new" rows? Tom [0] https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem