Store Postgres databases on Amazon elastic file systems.
Easily and instantaneously attach read only datasets to multiple postgres instances using AWS EFS.
pip install pefs
Create some date in a local postgres instance:
echo "CREATE TABLE test (id int, value varchar); INSERT INTO test VALUES (1, 'test');" | psql mydb
Attach the EFS volume to /mnt/efs (or elsewhere), then use pefs to clone the database to the EFS:
pefs clone mydb /mnt/efs
On a different machine, mount the EFS volume and link the local postgres instance to it:
pefs link mynewdb /mnt/root echo "SELECT * FROM test" | psql mynewdb
Pefs will shutdown postgres servers and issue file cache flushes. Pefs is an experiment.
How it works
Cloning a database works by shutting down the postgres server and doing a file cache flush to write all data to disk. The postgres server is started back up and queried to determine all the tables in a database and where all those page files are located. The page files are copied on the EFS volume along with the DDL generated by pg_dump.
Linking a database works by taking all the DDLs on the EFS volume and applying them on the local postgres server, the paths to the empty page files are noted. The postgres server is shutdown and another file cache flush is performed. The empty page files are deleted and replaced with symlinks onto the EFS volume. The postgres server is started up again.