Connection refused with postgresql using psycopg2
<blockquote>
  <p>psycopg2.OperationalError: could not connect to server: Connection refused</p>
</blockquote>

<p>Is the server running on host "45.32.1XX.2XX" and accepting TCP/IP connections on port 5432?</p>

<p>Here,I've open my sockets.</p>

<pre><code>tcp        0      0 127.0.0.1:5432          0.0.0.0:*  LISTEN      11516/postgres                
tcp6       0      0 ::1:5432                :::*       LISTEN      11516/postgres
</code></pre>

<p>I googled that I should modify this <code>pg_hba.conf</code>ï¼but in my <code>postgresql</code>root files, I didn't find this file at all.</p>

<p>Also I've succeed in connecting my another server.</p>

<p>Thanks.</p>

<p>Here,I've modified the <code>pg_hba.conf</code>,updated this<code>host all all 218.3.A.B trust</code> and reloaded.But it didn't work either.</p>

<p>Your netstat output shows that postgres is listening on <code>127.0.0.1</code>, but your error suggests you are trying to connect to <code>45.32.1XX.2XX</code>.  I am pretty sure you have already diagnosed your problem.  </p>

<p>You will need to modify the <code>listen_addresses</code> setting your <code>postgresql.conf</code> file (<em>not</em> <code>pg_hba.conf</code>).  The <code>postgresql.conf</code> file is found in your postgresql data directory, which is often something like <code>/var/lib/postgresql/data</code> or <code>/var/lib/pgsql/data</code>.</p>

<p>The <code>listen_addresses</code> parameter is documented <a href="https://www.postgresql.org/docs/9.5/static/runtime-config-connection.html" rel="nofollow">here</a>.</p>

python postgresql python-3.x