PostgreSQL:无法连接到服务器:连接超时
PostgreSQL: could not connect to server: Connection timed out
我一直在尝试切换到 PostgreSQL(从 SQLite)。我在Cloud9的环境下开发。但是,在数据库迁移中,我收到 错误消息 :
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?
我一直在阅读关于此主题的各种先前提出的问题,但没有成功。有人看到可能出了什么问题吗?
我可能需要更改 pg_hba.conf 文件吗?文件的当前版本:
# 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
我在 Gemfile 中有 gem 'pg'
和 运行 bundle install
。另外,我创建了数据库 app_development(使用了sudo service postgresql start
、sudo sudo -u postgres psql
然后create database "app_development";
)以及数据库app_test。最后,我 使用 CREATE USER my_username SUPERUSER PASSWORD 'my_password';
.
在 psql 中创建了一个新用户
使用 sudo nano /etc/postgresql/9.3/main/postgresql.conf
我也设置了 listen_addresses = '*'
但这没有区别。
可能导致错误消息的原因是什么?
您确定您的 cloud 9 已打开 postgres 端口 (5432) 以供访问吗?我假设 cloud 9 主机没有在端口 5432 上侦听。您可以查看此 link 以获得详细信息
http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
我一直在尝试切换到 PostgreSQL(从 SQLite)。我在Cloud9的环境下开发。但是,在数据库迁移中,我收到 错误消息 :
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?
我一直在阅读关于此主题的各种先前提出的问题,但没有成功。有人看到可能出了什么问题吗?
我可能需要更改 pg_hba.conf 文件吗?文件的当前版本:
# 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
我在 Gemfile 中有 gem 'pg'
和 运行 bundle install
。另外,我创建了数据库 app_development(使用了sudo service postgresql start
、sudo sudo -u postgres psql
然后create database "app_development";
)以及数据库app_test。最后,我 使用 CREATE USER my_username SUPERUSER PASSWORD 'my_password';
.
使用 sudo nano /etc/postgresql/9.3/main/postgresql.conf
我也设置了 listen_addresses = '*'
但这没有区别。
可能导致错误消息的原因是什么?
您确定您的 cloud 9 已打开 postgres 端口 (5432) 以供访问吗?我假设 cloud 9 主机没有在端口 5432 上侦听。您可以查看此 link 以获得详细信息
http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html