I want to deploy my Rails application on an Ubuntu VPS with nginx & PostgreSQL but I can’t seem to get PostgreSQL to connect.

What I did:

1) Update apt-get

2) Install required tools

apt-get install curl git-core python-software-properties

3) Add nginx ppa to apt-get, update apt-get again and install nginx

add-apt-repository ppa:nginx/stable

4) Start nginx, check on nginx whether it works (it works)

5) Install PostgreSQL (version 9.1.3 got installed)

apt-get install postgresql libpq-dev

When I tried to connect through the below methods, it failed:

psql -U postgres 
psql -U postgres -h localhost
psql -U postgres -h localhost -p 5432

What I have tried so far:

  1. Config file is located in /usr/share/postgresql/9.1/postgresql.conf.sample. I have tried renaming it without “.sample” and restarted the server. Still, failed.
  2. Adding the ppa:pitti/postgresql to apt-get and installing it, 9.1 still got installed
  3. Giving 0777 permissions on postgresql.conf (ref to number 1 to know which file I am talking about)
  4. Editing the postgresql.conf
    Content of the conf file:

Error log:

psql: could not connect to server: Connection refused
Is the server running on host "localhost" ( and accepting
TCP/IP connections on port 5432?