I built this deployment script which runs when my debian 6.0 server is deployed. I have shown it here before (this is a linode stackscript incase anyone else is wondering):
#!/bin/bash
#
# Install PostgreSQL
#
# Copyright (c) 2010 Filip Wasilewski <en@ig.ma>.
#
# My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb
function postgresql_install {
aptitude -y install postgresql postgresql-contrib postgresql-dev libpq-dev
}
function postgresql_create_user {
# postgresql_create_user(username, password)
if [ -z "$1" ]; then
echo "postgresql_create_user() requires username as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_user() requires a password as the second argument"
return 1;
fi
echo "CREATE ROLE $1 WITH LOGIN ENCRYPTED PASSWORD '$2';" | sudo -i -u postgres psql
}
function postgresql_create_database {
# postgresql_create_database(dbname, owner)
if [ -z "$1" ]; then
echo "postgresql_create_database() requires database name as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_database() requires an owner username as the second argument"
return 1;
fi
sudo -i -u postgres createdb --owner=$2 $1
}
postgresql_install
postgresql_create_user(username, password)
postgresql_create_database(dbname, username)
I deployed my server with this script, which was built on top of Filip’s version, but then when I try to see if postgresql is running by typing pg_ctl it says command not found.
Where I have I gone wrong on this? Since it deploys when the server runs I am not able to see where it is going wrong.
As people say it looks like you don’t have the PostgreSQL bin directory on your path. In my experience on Ubuntu with PostgreSQL 9.1/9.2 on install from apt, the postgres user is created but it doesn’t properly set up your environment, so
pg_ctlandinitdbetc are not on yourPATH.I can’t see what PostgreSQL version you’re using, but my 9.1 & 9.2 instances store the binaries in
/usr/lib/postgresql/9.2/binCheck that directory to see if it contains pg_ctl and other binaries. If it does,
try running:
and see if that allows you to run
pg_ctl. If so, you’ll need to execute that at login from.bashrcor similar