by spellboots · 4mo ago · 0 comments
CREATE DATABASE new_db TEMPLATE templatedb STRATEGY FILE_COPY
Combined with set file_copy_method = 'clone'
This copies arbitrarily sized DBs sub-second - I use it on dbs larger than 1TB regularly - and has the advantage of being copy-on-write - the new db doesn't take up any extra disk space until you start writing to it in which case only the differences are used.Only supported on linux and macos AFAIK
https://www.postgresql.org/docs/18/runtime-config-resource.h...
What I don't know is if it's faster to copy than a regular copy on a ram tmpfs - since it may be essentially be doing "nothing" - updating some pointers instead of copying stuff in ram.
So if your workload is limited by copy not execution speed it might be worth testing.
However at that point you're running on a regular FS so if you're trying to benefit test speed by having all your regular postgres operations on a ramdisk, that part will end up being slower.
Obviously operations after that will be a lot slower reading / writing to a normal disk