Restart postgres in a docker environment
Asked Answered
N

1

19

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!

Nowise answered 14/11, 2014 at 17:16 Comment(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.Lapointe
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...Nowise
try adding –cap-add SYS_PTRACE to your docker run commandPoler
S
23

For me, changing the config and doing

$ docker restart <postgres_container>

on the host works just fine.

Sorrows answered 30/5, 2017 at 11:36 Comment(1)
@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/stopSorrows

© 2022 - 2024 — McMap. All rights reserved.