Rake db:创建无法连接到服务器:没有这样的文件或目录

问题描述:

我想上传一个rails应用程序到heroku,我遇到了问题,将我的应用程序从sqlite3更改为postgres,主要是当我运行rake db:create我得到:Rake db:创建无法连接到服务器:没有这样的文件或目录

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"? 

这是我的database.yml的样子:

default: &default 
    adapter: postgresql 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: anagram_development 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    <<: *default 
    database: anagram_test 

production: 
    <<: *default 
    database: anagram_production 

你有本地安装PostgreSQL的?如果是这样,请仔细检查它是否正在运行。您的database.yml文件也缺少一些连接到postgres数据库所需的信息。您需要提供用户名,密码和主机名。

下面是它连接到本地的Postgres数据库我的一个例子:

development: 
    adapter: postgresql 
    encoding: unicode 
    database: app_development 
    pool: 10 
    username: <%= %x(whoami) %> 
    password: 

对于Heroku的/制作,您可以使用以下命令:

production: 
    url: <%= ENV['DATABASE_URL'] %> 
    pool: <%= ENV['DB_POOL'] || 10 %>