PostgreSQL: could not connect to server: Connection timed out

戏子无情 提交于 2019-12-23 04:23:42

问题


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 error message:

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?

I've been reading all sorts of previously asked questions on this topic but without success. Does anyone see what might be going wrong?

Do I perhaps need to makes change to the pg_hba.conf file? The current version of the file:

# 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

database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  host: 'mydomain.c9.io'
  pool: 5
  username: my_username
  password: my_password
development:
  <<: *default
  database: app_development
test:
  <<: *default
  database: app_test
production:
  <<: *default
  database: app_production

I have gem 'pg' in the Gemfile and have run bundle install. Also, I have created the database app_development (used sudo service postgresql start, sudo sudo -u postgres psql and then create database "app_development";) as well as the database app_test. And lastly, I created a new user in psql with CREATE USER my_username SUPERUSER PASSWORD 'my_password';.

Using sudo nano /etc/postgresql/9.3/main/postgresql.conf I also set listen_addresses = '*' but that made no difference.

What might be causing the error message?


回答1:


Are you sure that your cloud 9's has postgres port(5432) open for access? I assume the cloud 9 host is not listening on port 5432. You can check out this link for detais

http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html



来源:https://stackoverflow.com/questions/30233999/postgresql-could-not-connect-to-server-connection-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!