title: PostgreSQL: could not connect to server: Connection timed out
body: <p>I've been trying to make the switch to PostgreSQL (from SQLite). I'm developing in the environment of Cloud9. However, on db migration I get the <strong>error message</strong>:</p>
  
  <blockquote>
    <p>PG::ConnectionBad: could not connect to server: Connection timed out.
    Is the server running on host "mydomain.c9.io" (IP address) and
    accepting TCP/IP connections on port 5432?</p>
  </blockquote>
  
  <p>I've been reading all sorts of previously asked questions on this topic but without success. Does anyone see what might be going wrong?</p>
  
  <p>Do I perhaps need to makes change to the <strong>pg_hba.conf</strong> file? The current version of the file:</p>
  
  <pre><code># Database administrative login by Unix domain socket
  local   all             postgres                                peer
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  # "local" is for Unix domain socket connections only
  local   all             all                                     peer  
  # IPv4 local connections:
  host    all             all             xxx.0.0.1/32            md5
  # IPv6 local connections:
  host    all             all             ::1/128                 md5
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  #local  replication     postgres                                peer
  #host   replication     postgres        xxx.0.0.1/32            md5
  #host   replication     postgres        ::1/128                 md5
  </code></pre>
  
  <p><strong>database.yml:</strong></p>
  
  <pre><code>default: &amp;default
    adapter: postgresql
    encoding: unicode
    host: 'mydomain.c9.io'
    pool: 5
    username: my_username
    password: my_password
  development:
    &lt;&lt;: *default
    database: app_development
  test:
    &lt;&lt;: *default
    database: app_test
  production:
    &lt;&lt;: *default
    database: app_production
  </code></pre>
  
  <p>I have <code>gem 'pg'</code> in the <strong>Gemfile</strong> and have run <code>bundle install</code>. Also, I have <strong>created the database</strong> app_development (used <code>sudo service postgresql start</code>, <code>sudo sudo -u postgres psql</code> and then <code>create database "app_development";</code>) as well as the database app_test. And lastly, I <strong>created a new user</strong> in psql with <code>CREATE USER my_username SUPERUSER PASSWORD 'my_password';</code>.</p>
  
  <p>Using <code>sudo nano /etc/postgresql/9.3/main/postgresql.conf</code> I also set <code>listen_addresses = '*'</code> but that made no difference. </p>
  
  <p>What might be causing the error message?</p>