title: Running PostgreSQL with Supervisord
body: <p>I want to run PostgreSQL 9.1 using Supervisor on Ubuntu 10.04. At the moment, I manually start PostgreSQL using the init script:</p>
  
  <pre><code>/etc/init.d/postgresql start
  </code></pre>
  
  <p>According to this post: <a href="http://nicksergeant.com/using-postgresql-with-supervisor-on-ubuntu-1010/" rel="noreferrer">http://nicksergeant.com/using-postgresql-with-supervisor-on-ubuntu-1010/</a>, I need to modify the PostgreSQL config to make it run on TCP port instead of Unix socket, in order to make PostgreSQL work with Supervisor.</p>
  
  <p>I have two questions regarding this approach:</p>
  
  <ol>
  <li><p>Considering this is more of hack, is there any implication (e.g. security/permissions, performance, etc) of doing this?</p></li>
  <li><p>Why cannot we just run the same init script <code>postgresql</code> in Supervisor config? Instead, as shown in the link above, it runs <code>postmaster</code>?</p></li>
  </ol>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Thanks to the useful suggestions from both answers below, I have setup a script for Supervisor to invoke PostgreSQL directly:</p>
  
  <pre><code>#!/bin/sh
  
  # This script is run by Supervisor to start PostgreSQL 9.1 in foreground mode
  
  if [ -d /var/run/postgresql ]; then
      chmod 2775 /var/run/postgresql
  else
      install -d -m 2775 -o postgres -g postgres /var/run/postgresql
  fi
  
  exec su postgres -c "/usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf"
  </code></pre>
  
  <p>I also set the config: <code>/etc/postgresql/9.1/main/start.conf</code> to <code>manual</code> so that PostgreSQL does not start automatically on boot (however, it's not clear to me whether this config is loaded). And then I setup the Supervisor config for postgres as:</p>
  
  <pre><code>[program:postgres]
  user=root
  group=root
  command=/usr/local/bin/run_postgresql.sh
  autostart=true
  autorestart=true
  stderr_logfile=/home/www-data/logs/postgres_err.log
  stdout_logfile=/home/www-data/logs/postgres_out.log
  redirect_stderr=true
  stopsignal=QUIT
  </code></pre>
  
  <p>So now, I can start PostgreSQL in <code>supervisorctl</code> by doing <code>start postgres</code>, which runs fine. <strong>However, after I issue <code>stop postgres</code>, although <code>supervisorctl</code> declares postgres is stopped, the server apparently is still running as I can psql into it.</strong></p>
  
  <p>I wonder if this is a Supervisor config issue, or a PostgreSQL issue. Any suggestion welcome!</p>