20

I have troubles restarting a dockerized postgres database (I use Core OS). The database is started in a bash script using the command

# boot.sh
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf

which works. I have another script called by confd which is run when some etcd keys change (this part is ok, the file is correctly called) and must restart postgres (not reload, because some config changes require a restart). Here are the main options I tried, which failed...

# restart.sh
sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl --pgdata=/var/lib/postgresql/9.3/main restart

systematically raises an error:

%FATAL:  lock file "postmaster.pid" already exists
%HINT:  Is another postmaster (PID 273) running in data directory "/var/lib/postgresql/9.3/main"?

Furthermore,

# restart.sh
rm /var/lib/postgresql/9.3/main/postmaster.pid
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf

,

rm /var/lib/postgresql/9.3/main/postmaster.pid
/etc/init.d/postgresql start

,

/etc/init.d/postgresql restart

and

exec su postgres -c "/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf"

fail with

ERROR exit status 1

Any thought? Thank you in advance!

3
  • On the one hand, a restart.sh consisting of only this line works without error on my Ubuntu server: sudo -i -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl restart -D /var/lib/postgresql/9.3/main. (I don't see this syntax in your question.) On the other hand, I'm not running it in a Docker container. Commented Nov 14, 2014 at 17:34
  • Thanks Mike, it does work on an ubuntu server. The problem seems to be tied to Core OS or Docker, but I do not know yet exactly in what it consist... Commented Nov 14, 2014 at 17:40
  • try adding –cap-add SYS_PTRACE to your docker run command Commented Nov 14, 2014 at 18:31

1 Answer 1

24

For me, changing the config and doing

$ docker restart <postgres_container>

on the host works just fine.

Sign up to request clarification or add additional context in comments.

1 Comment

@MikhailM - docker sends a sigterm signal and only kills after so many seconds (default might be 10sec). If this is too short you can increase that time. See docs.docker.com/engine/reference/commandline/stop

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.