Trying to setup Postgresql 9.5 with different data directory Ultimately I want Postgresql 9.5 running in a docker container using a mounted volume for the data so it can be persistent. As part of that I am experimenting with setting up the Postgresql server to use an alternative data directory.

I read that it isn't possible to use a FAT32 or VFAT directory, so I have, for the time being, abandoned using the Samba mount from our backed up NAS and am trying something simpler.

I am working on Ubuntu 16.04.3 LTS. The commands I ran (as root (sudo su -)) were:

service postgresql stop
mkdir -p /blah/data
chown postgres /blah/data
sudo -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /blah/data
sed -i 's#.*data_directory = .*#data_directory = "/blah/data"#' /etc/postgresql/9.5/main/postgresql.conf
service postgresql start


The initdb command completed perfectly, unlike when I ran it on my samba mount where I got fsync errors.

If I now type sudo -u postgres psql I get told:

Error: Invalid line 41 in /etc/postgresql/9.5/main/postgresql.conf: »data_directory = "/blah/data"«


I have followed everything I can find on the internet about this, especially the official documentation. It should just work. It doesn't. Apparently the documentation needs some improvement.

Can anyone help me get this to work, please?

If anyone can help me to then extend it to work in a docker container using a volume mounted from a directory on the host which is in turn a samba mount, I would be very grateful.
The command I typed:

sed -i 's#.*data_directory = .*#data_directory = "/blah/data"#' /etc/postgresql/9.5/main/postgresql.conf


should be:

sed -i "s#.*data_directory = .*#data_directory = '/blah/data'#" /etc/postgresql/9.5/main/postgresql.conf


The quotes around the directory path were the wrong sort. Can you believe it!