Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart postgres in a docker environment

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!

like image 350
Raphael Avatar asked Nov 14 '14 17:11

Raphael


1 Answers

For me, changing the config and doing

$ docker restart <postgres_container>

on the host works just fine.

like image 136
Risadinha Avatar answered Sep 16 '22 18:09

Risadinha