I'm running automated integration tests using data stored in a postgres database. I need to start every test run with the same database contents. Instead of always clearing the database and importing a dump, I want to copy the database to /tmp and run it from there. If it works, it is easier and faster. This is what I did:
mkdir -p /tmp/postgres/data
chown -R postgres:postgres /tmp/postgres
rsync -vacHAX /var/lib/postgres/data/ /tmp/postgres/data/
and adapted the postgresql.service
file to the new location (including systemctl daemon-reload
).
But if I try to start postgres with this setup, it fails and systemctl status postgresql.service
says
"/tmp/postgres/data" is missing or empty.
which is just not true.
I double-checked that the postgres user owns and has access to /tmp/pgsql/data/. Free space on /tmp is also sufficient (over 2 times the database size).
I've tried a different location and it worked. So my changes in the postgresql.service
file are sufficient to use a non-default locattion. It only fails on /tmp.
What am I missing ?
dbname
in the connection string, and see with\c
inpsql
) as test database. Copy it initially from your main database, change the connection string in your automated tests, and do each test inside a transaction; rollback after test is finished. Then every test will execute against a defined database state. No need to copy the database files on the filesystem to somewhere else.