ruby-on-rails – Rails:rake db:create:all无法连接到PostgreSQL数据库

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails:rake db:create:all无法连接到PostgreSQL数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个使用Postgresql的Rails应用程序.这是对我所做的描述.

Postgresql设置:
我通过Martin Pitt维护的ppa:pitti/postgresql安装了Postgresql 9.1.3.之前安装了Postgresql 8.4;我不确定它是否仍然安装或消失.

>我添加了一个数据库用户,该用户拥有与我的Ubuntu帐户同名的数据库的超级用户权限.
>我用sudo服务postgresql start启动数据库守护进程.
>我通过Gerfried Fuchs维护的ppa:rhonda/pgadmin3安装了pgadmin3,Version 1.14.0 Beta 1.
>我可以使用我的用户帐户和密码以及端口5433通过pgadmin3连接.

我在pg_hba.conf中的postgres配置如下(为了便于阅读,删除了注释).

[...]
local   all             postgres                                peer
local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

Rails设置:
现在我想创建一个使用Postgresql的Rails应用程序.

>我通过RVM安装了Ruby 1.9.3-p125.
>我将Rails 3.2.3安装到Gemset ruby​​-1.9.3-p125@global中.
>我为应用程序创建了一个.rvmrc和Gemset.
>我通过rails new my_test_app -d postgresql创建了一个Rails应用程序.
>我在config / database.yml中配置了用户名和密码,用于开发和测试,并删除了生产.
>我在config / database.yml中配置了host:localhost和port:5433.

这是我的config / database.yml的内容(为了便于阅读,删除了注释).

development:
  adapter: postgresql
  encoding: unicode
  database: my_test_app_development
  pool: 5
  username: johndoe
  password: password    
  host: localhost
  port: 5433

test:
  adapter: postgresql
  encoding: unicode
  database: my_test_app_test
  pool: 5
  username: johndoe
  password: password

问题:
但是,当我运行bundle exec rake db:create:all我收到以下错误消息.

could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGsql.5432"?
[...]
Couldn't create database for {"adapter"=>"postgresql","encoding"=>"unicode","database"=>"my_test_app_test","pool"=>5,"username"=>"johndoe","password"=>"password"}

题:
为什么端口与我通过pgadmin3成功连接时使用的端口不同?

解决方法

@Riateche:最后,我看到测试环境的数据库配置错过了主机和端口的显式设置.将设置添加到测试环境后,我能够成功运行命令bundle exec rake db:create:all.
我必须说,我不喜欢他们建议开发环境的那些设置,但没有为其他环境添加它们.正如我所证明的那样,这很可能会错过它们.
test:
  adapter: postgresql
  encoding: unicode
  database: my_test_app_test
  pool: 5
  username: johndoe
  password: password
  host: localhost
  port: 5433
原文链接:https://www.f2er.com/ruby/274392.html

猜你在找的Ruby相关文章