当我尝试连接服务器以创建数据库时。我收到了这个错误。
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "socket"=>"/var/run/postgresql/.s.PGSQL.5432", "pool"=>5, "min_messages"=>"error", "database"=>"rails_contributors_test"}
-- enable_extension("plpgsql")
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
我尝试了很多,但没有取得成功。寻求帮助。
Postgres版本我有
which postgres
=> /usr/local/bin/postgres
postgres --version
=> postgres (PostgreSQL) 9.4.4
答案 0 :(得分:9)
尝试在Mac OSX上安装Postgres.app。
并启动postgres,即点击Question2
。
然后,重新启动rails服务器。
在此之后,它应该解决您的问题。
要解决此问题,请删除Open psql
文件。找到postgres数据目录。在使用自制程序的Mac OSX上,它是PID
。
要确保这是问题所在,请查看日志文件(/usr/local/var/postgres/
)。在最后一行,您会看到:server.log
如果是,FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
重新启动服务器。在Mac OSX上,执行:
rm postmaster.pid
launchctl unload homebrew.mxcl.postgresql.plist