简体   繁体   English

Rails:rake db:create:all(无法连接到服务器)psql正常工作

[英]Rails: rake db:create:all (could not connect to server) psql works fine

I've looked here and here but still can't solve my problem. 我看过这里这里,但仍然无法解决我的问题。 I have my setup working perfectly on my normal linux but when I tried to recreate it on my mac postgres won't work with rails. 我的安装程序可以在普通Linux上正常运行,但是当我尝试在Mac上重新创建它时,postgres将无法在Rails上运行。 After following these instructions from railscasts I get to the point where I run rake:db:create:all 在遵循来自railscasts的这些说明之后,我到达了运行rake:db:create:all的地步

running rake db:create:all: 运行rake db:create:all:

$ 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/pgsql_socket/.s.PGSQL.5432"?

but running psql works fine: 但是运行psql可以正常工作:

$ psql
psql (9.3.1)
Type "help" for help.

crashandburn4=#

checking which port postgres is running on yields: 检查哪个port postgres在yield上运行:

$ cat /etc/services |grep post
postgresql      5432/udp    # PostgreSQL Database
postgresql      5432/tcp    # PostgreSQL Database

so it doesn't appear to be an incorrect port and my database.yml explicitely states the port: 因此它似乎不是一个错误的端口,而我的database.yml明确声明了该端口:

# database.yml
development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: myusername
  password:
  port: 5432

test:
  adapter: postgresql
  encoding: unicode
  database: blog_test
  pool: 5
  username: myusername
  password:
  port: 5432


production:
  adapter: postgresql
  encoding: unicode
  database: blog_production
  pool: 5
  username: myusername
  password:
  port: 5432

running netstat also looks fine (I think): 运行netstat看起来也不错(我认为):

$ netstat -a | grep postgre
tcp6       0      0  localhost.postgres     *.*                    LISTEN     
tcp4       0      0  localhost.postgresql   *.*                    LISTEN     
tcp6       0      0  localhost.postgres     *.*                    LISTEN     

which is about everything I could come up with to try and diagnose the problem other than calling a witchdocter :) anyone got any ideas? 除了打电话给巫医之外,这就是我想出的所有尝试和诊断问题的方法:)任何人都有任何想法吗?

EDIT: Solved my question (good old rubber duck debugging) figured I'd post anyway to help any other poor souls that spend an hour digging through and double checking config-files. 编辑:解决了我的问题(调试好的老橡皮鸭),我想无论如何都会发帖帮助其他花费一个小时进行挖掘并仔细检查配置文件的可怜人。

Incorrect config, this was fixed by including the hostname with the configuration (see below), one interesting note is that this is only necessary for the macbook pro that I'm running on and does not occur on the Linux box I use. 不正确的配置,此问题已通过在配置中包括主机名来解决(请参见下文),一个有趣的注意事项是,这仅对我正在运行的Macbook Pro必要,而在我使用的Linux机器上则不会出现。

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: myusername
  password:
  host: localhost
  port: 5432

test:
  adapter: postgresql
  encoding: unicode
  database: blog_test
  pool: 5
  username: myusername
  password:
  host: localhost
  port: 5432


production:
  adapter: postgresql
  encoding: unicode
  database: blog_production
  pool: 5
  username: myusername
  password:
  host: localhost
  port: 5432

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM