title: psql cant connect to PostgreSQL server (postmaster) on IP and port 5432?
body: <p>Please read before replying it as duplicate (as it perhaps can happen). I am running my postmaster (postgres) server. See below for 'sudo netstat -anp|grep 5432' output?</p>
  
  <pre><code>tcp  0  0 127.0.0.1:5432    0.0.0.0:*     LISTEN      29606/postmaster       
  unix  2      [ ACC ]     STREAM     LISTENING     1650581 29606/postmaster /var/run/postgresql/.s.PGSQL.5432
  unix  2      [ ACC ]     STREAM     LISTENING     1650582 29606/postmaster    /tmp/.s.PGSQL.5432               
  </code></pre>
  
  <p>I am able to connect from localhost using </p>
  
  <pre><code>psql -h localhost (OR 127.0.0.1) -d &lt;DB&gt; -U user -W
  </code></pre>
  
  <p>But when I try to connect from other hosts using tcp, by specifying</p>
  
  <pre><code>psql -h ip_add_postmaster -d &lt;DB&gt; -U user -W
  </code></pre>
  
  <p>It throws:</p>
  
  <blockquote>
    <p>psql: could not connect to server: Connection refused
    Is the server running on host XXXXXX and accepting TCP/IP connections on port 5432? </p>
  </blockquote>
  
  <p>What's wrong here?</p>
  
  <pre><code>pg_hba.conf
  
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  
  # "local" is for Unix domain socket connections only                  
  local   all             all                                     peer  
  # IPv4 local connections:                                             
  host    all             all             127.0.0.1/32            md5   
  # IPv6 local connections:                                             
  host    all             all             ::1/128                 md5   
  </code></pre>
  
  <p>In postgresql.conf,</p>
  
  <pre><code>listen_addresses = 'localhost, 127.0.0.1, ip_add_postmaster'
  
  Note: ip_add_postmaster is same as my Elastic IP and not public DNS. If this information
  matters.
  </code></pre>
  
  <p>What am I doing wrong here? Machine is hosted on Amazon EC2 and have open the port 5432. </p>