1

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 ?

8
  • Is your problem this one?
    – harrymc
    Commented Jul 5, 2020 at 8:32
  • Not an answer, but: For automated tests, consider using a different database name (what you put as dbname in the connection string, and see with \c in psql) 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.
    – dirkt
    Commented Jul 5, 2020 at 9:31
  • @harrymc no. As I wrote, I can use another location, it only fails on /tmp. Commented Jul 5, 2020 at 11:21
  • @dirkt not possible in my case, the software in test uses postgres-specific features, and I would need to export the existing postgres data in a format the other database understands Commented Jul 5, 2020 at 11:23
  • Did you check if the permissions are identical on the source/target directories?
    – harrymc
    Commented Jul 5, 2020 at 14:21

1 Answer 1

0

systemd services can have a private /tmp directory for security reasons. From systemd documentation:

PrivateTmp=

Takes a boolean argument. If true, sets up a new file system namespace for the executed processes and mounts private /tmp/ and /var/tmp/ directories inside it that are not shared by processes outside of the namespace

When you say it's not true that /tmp/postgres/data is empty or non-existing, that's from the point of view of your shell, not the point of view of the postgres service if PrivateTmp=true.

1
  • I learned something new. And by setting it to false, it worked. thanks. Commented Aug 5, 2020 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .