Rails:rake db:create:all无法连接到PostgreSQL数据库

JJD*_*JJD 6 postgresql ruby-on-rails ruby-on-rails-3 rails-postgresql postgresql-9.1

我正在尝试创建一个使用PostgreSQL的Rails应用程序.这是对我所做的描述.


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

  • 我添加了一个数据库用户,该用户具有与我的Ubuntu帐户同名的数据库的超级用户权限.
  • 我用它启动数据库守护进程sudo service postgresql start.
  • 我通过由Gerfried Fuchs维护的ppa:rhonda/pgadmin3安装了pgadmin3,版本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
Run Code Online (Sandbox Code Playgroud)

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

  • 我通过RVM安装了Ruby 1.9.3-p125.
  • 我将Rails 3.2.3安装到Gemset ruby​​-1.9.3-p125@global中.
  • 我为应用程序创建了一个.rvmrc和Gemset.
  • 我通过创建了一个Rails应用程序rails new my_test_app -d postgresql.
  • 我配置了user名称,并passwordconfig/database.yml中进行开发测试,并删除了生产.
  • 余配置host: localhostport: 5433配置/ database.yml中.

这是我的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
Run Code Online (Sandbox Code Playgroud)

问题:
但是,当我运行时,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"}
Run Code Online (Sandbox Code Playgroud)

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

JJD*_*JJD 18

@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
Run Code Online (Sandbox Code Playgroud)

  • @AmySukumunu您可以在配置文件中配置**端口**,您可以在这里找到:`/ etc/postgresql/<VERSION>/main/postgresql.conf`.更多信息[这里](http://ubuntumanual.org/posts/505/how-to-install-postgresql-on-ubuntu).据我所知,默认端口是5432. (2认同)