title: Postgresql server remote connection
body: <p>I am trying to set up a postgresql 9.1 server on ubuntu, for remote access of data.  I have postgres properly installed, the server process is running and I am trying to configure it so that I can access the server remotely over the internet from a few other computers outside my LAN.</p>
  
  <p>I have already modified my pg_hba.conf with:</p>
  
  <pre><code>host    all     all     0.0.0.0     trust
  </code></pre>
  
  <p>and the postgresql.conf with:</p>
  
  <pre><code>listen_addresses = '*'
  port = 5432
  </code></pre>
  
  <p>I have additionally modified my iptables to accept connections on port 5432.  </p>
  
  <p>When I try to connect using psycopg2 on python:</p>
  
  <pre><code>conn=psycopg2.connect('host=XX.XX.XX.XX port=5432 dbname=postgres user=myUser password=mypassword')
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
  connection_factory=connection_factory, async=async) 
  psycopg2.OperationalError: could not connect to server: Connection refused
  Is the server running on host "XX.XX.XX.XX" and accepting
  TCP/IP connections on port 5432?
  </code></pre>
  
  <p>I am not sure if I inserted the correct IP address, and I am curious how I would figure out exactly what IP address to use here to connect to my server.  I used the public IP of my computer which is running the postgres server, but I'm not sure that is correct.  Or is there a whole other step I am still missing?  I know this is bad security style, but for the moment I would like to just establish a connection.  Also my computer is behind a router, so how would I access my server specifically?</p>
  
  <p>Any help greatly appreciated.</p>