title: Restart postgres in a docker environment
body: <p>I have troubles restarting a dockerized postgres database (I use Core OS). The database is started in a bash script using the command </p>
  
  <pre><code># 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
  </code></pre>
  
  <p>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...</p>
  
  <pre><code># restart.sh
  sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl --pgdata=/var/lib/postgresql/9.3/main restart
  </code></pre>
  
  <p>systematically raises an error:</p>
  
  <pre><code>%FATAL:  lock file "postmaster.pid" already exists
  %HINT:  Is another postmaster (PID 273) running in data directory "/var/lib/postgresql/9.3/main"?
  </code></pre>
  
  <p>Furthermore,</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>,</p>
  
  <pre><code>rm /var/lib/postgresql/9.3/main/postmaster.pid
  /etc/init.d/postgresql start
  </code></pre>
  
  <p>,</p>
  
  <pre><code>/etc/init.d/postgresql restart
  </code></pre>
  
  <p>and</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>fail with </p>
  
  <pre><code>ERROR exit status 1
  </code></pre>
  
  <p>Any thought? Thank you in advance!</p>