0

我在带有 IP 的 CentOS 远程机器上,而我的 postgres 在不同的 IP 上。我想用我的 rails 服务器访问 postgres。我编辑了 database.yml 文件并安装了 gem pg 并在 database.yml 文件中包含了主机 IP。但是我无法运行 rake db:migrate 和 rails 服务器。它显示 PG ERROR 如下。帮我解决这个问题. 我正在尝试从过去 4 天连接到服务器..但我不能...当我运行 db:migrate 它显示以下错误。

[root@vdimc04 My_Postgres]# rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
fe_sendauth: no password supplied
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/migration.rb:662:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/migration.rb:570:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/migration.rb:570:in `up'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/migration.rb:551:in `migrate'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:227:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:222:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/task.rb:152:in `invoke'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:99:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:99:in `block in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:108:in `run_with_threads'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:71:in `block in run'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/bin/rake:19:in `<main>'
/usr/local/rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate

   **my database.yml file**
development:
  adapter: postgresql
  encoding: unicode
  database: db_pchamara
  pool: 5
  username: db_test_user
  password: password
  host: 192.168.1.101
test:
  adapter: postgresql
  encoding: unicode
  database: db_pchamara_test
  pool: 5
  username: db_test_user
password: password


production:
  adapter: postgresql
  encoding: unicode
  database: db_pchamara_production
  pool: 5
  username: db_test_user
password: password
4

2 回答 2

2

它清楚地在本地机器上寻找 PostgreSQL:

服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?

database.yml应该包含这样的东西:

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password: very_Secure12/
  host: 224.13.156.78
  port: 5432

您可以dbserver.myvompany.com在该host行中使用 IP 或主机名。它不应包含以 . 开头的行socket。最后,PostgreSQL 必须接受来自该服务器的连接。

于 2012-12-07T05:50:50.447 回答
1

根据这个错误:

fe_sendauth: no password supplied

您需要检查pg_hba.conf远程服务器上文件中设置的权限。很可能,您不允许远程连接连接到服务器。它应该看起来像这样,例如:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               trust
# Remote connections
host    your_db     your_user   (Client IP ADDR)      md5

您可以使用0.0.0.0/0,但这将允许来自任何主机的连接。

于 2012-12-08T08:14:58.847 回答