title: Unable to connect to postgres sever from google colab using psycopg2
body: <p>i keep getting errors attemping to connect to postgres from google colab,however on pycharm these same code connects to the server easily. Here is the code:</p>
  <pre><code>import psycopg2
  
  params = {
      &quot;host&quot;      : &quot;localhost&quot;,
      &quot;database&quot;  : &quot;somedb&quot;,
      &quot;user&quot;      : &quot;postgres&quot;,
      &quot;password&quot;  : &quot;mypassword&quot;
  }
  def connect(params):
      &quot;&quot;&quot; Connect to the PostgreSQL database server &quot;&quot;&quot;
      conn = None
      try:
          # connect to the PostgreSQL server
          print('Connecting to the PostgreSQL database...')
          conn = psycopg2.connect(**params)
      except (Exception, psycopg2.DatabaseError) as error:
          print(error)
           
      return conn
  
  connect(params)
  
  </code></pre>
  <p>errors i am getting</p>
  <pre><code>OperationalError: could not connect to server: Connection refused
      Is the server running on host &quot;localhost&quot; (127.0.0.1) and accepting
      TCP/IP connections on port 5432?
  could not connect to server: Cannot assign requested address
      Is the server running on host &quot;localhost&quot; (::1) and accepting
      TCP/IP connections on port 5432?
  </code></pre>