
连接数据库
跟着rails tutorial 学习rails框架时,遇到了db链接的问题 问题 1 2 3 4 5 rake db:create failed PG::ConnectionBad: 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"? Google之后发现是database.yml配置文件没有加上host:localhost配置项。 过一会,发现PATH没有包含psql命令。 1 2 3 4 5 6 7 vi ~/.bash_profile #添加下面一行内容 export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH" exit ## or echo export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH" >> ~/.zshrc 终于rake db:migrate 成功。 附录 附上database.yml(production环境使用heroku环境变量) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 5 development: <<: *default host: localhost database: xxx_development test: <<: *default host: localhost database: xxx_test production: <<: *default database: xxx username: xxx password: <%= ENV['xxx_xxx_PASSWORD'] %>