sudo touch /etc/apt/sources.list.d/pgdg.list
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-9.3 libpq-dev postgresql-contrib-9.3
sudo apt-get autoremove
sudo pg_dropcluster --stop 9.3 main
sudo pg_createcluster --start -e UTF-8 9.3 main
#Change username and password as desired. Username need not be put in quotes but password need to be.
#In case of any extensions, login to psql with psql -h <hostname> -d <database_name> -U <username> -P
#Enter Password:
#You can avoid entering password always, by maintaining .pgpass.
sudo -u postgres psql -c "create role <username> with PASSWORD '<password>' SUPERUSER CREATEDB LOGIN;"
sudo -u postgres psql -c 'grant all on schema public to <username>;'
sudo service postgresql start