title: Connection Error while connecting to PostgreSQL as postgres user?
body: <p>I am not able connect to PostgreSQL remotely using python and psycopg2:</p>
  
  <p>Here is my code.</p>
  
  <pre><code>&gt;&gt;&gt; import psycopg2
  &gt;&gt;&gt; conn_string = "host='localhost' dbname='mydb' user='postgres'"
  &gt;&gt;&gt; print "Connecting to database\n     -&gt;%s" % (conn_string)
      Connecting to database
        -&gt;host='localhost' dbname='mydb' user='postgres'
  &gt;&gt;&gt; conn = psycopg2.connect(conn_string)
  
  Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/tools/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
  conn = _connect(dsn, connection_factory=connection_factory, async=async)
  psycopg2.OperationalError: could not connect to server: Connection refused
  Is the server running on host "localhost" (::1) and accepting
  TCP/IP connections on port 5432?
  </code></pre>
  
  <p>could not connect to server: Connection refused
      Is the server running on host "localhost" (127.0.0.1) and accepting
      TCP/IP connections on port 5432?</p>
  
  <p>The password is not set for postgres user. </p>
  
  <p>Generally, I can connect to database by running following method on host.</p>
  
  <pre><code> 1. SSH to box
   2. su - postgres
   3. psql
   4. \c mydb
  </code></pre>
  
  <p>The server runs PostgreSQL 9.1.</p>