1

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.

asked Feb 2, 2018 at 9:24
4
  • Please edit your question and add the exact line with data_directory as it appears in postgresql.conf Commented Feb 2, 2018 at 9:40
  • The information is already present - I replaced the line using sed and the exact text I replaced it with is present in the sed command. After comparing with the original config file (by uninstalling and reinstalling) I realised I had used the wrong sort of quotes. I find it strange that normal double quotes are not accepted. Also the error message could have just told me that I used the wrong quotes and which quotes to use. Commented Feb 2, 2018 at 10:03
  • you showed us the command you used, but not the outcome of that command. I suspected the single quotes vs. double quotes problem, but without seeing the actual line in the file I couldn't tell (not really experienced in sed) Commented Feb 2, 2018 at 10:03
  • Ah ok, my bad. Sorry, one of those "obvious to me but not to you" moments. Commented Feb 5, 2018 at 10:15

1 Answer 1

0

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!

answered Feb 2, 2018 at 9:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.