简体   繁体   中英

PostgreSQL: could not connect to server: Connection timed out

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM