Here's my setup script:
def setup_pgsql():
run('apt-get install -y postgresql python-psycopg2 postgresql-contrib')
sudo('psql -c "ALTER USER postgres WITH ENCRYPTED PASSWORD \'%(pw)s\';"'
% env, user='postgres')
sudo('psql -c "CREATE DATABASE %(db)s WITH OWNER postgres"' % env,
user='postgres')
run('/etc/init.d/postgresql-8.4 restart')

