[英]Unable to connect postgres server
When I try to connect server to create database. 当我尝试连接服务器以创建数据库时。 I am getting this error.
我收到此错误。
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?
I tried a lot but didn't get success. 我尝试了很多,但是没有成功。 Looking for help.
寻求帮助。
Postgres version I have as 我有的Postgres版本
which postgres
=> /usr/local/bin/postgres
postgres --version
=> postgres (PostgreSQL) 9.4.4
Try installing Postgres.app on your Mac OSX. 尝试在Mac OSX上安装Postgres.app 。
and start the postgres ie click on Open psql
. 并启动postgres,即单击
Open psql
。
Then, restart the rails server. 然后,重新启动Rails服务器。
After this, it should fix your issue. 之后,它应该可以解决您的问题。
To fix the issue, remove the PID
file. 要解决此问题,请删除
PID
文件。 Find the postgres data directory. 找到postgres数据目录。 On Mac OSX using homebrew it is
/usr/local/var/postgres/
. 在使用自制软件的Mac OSX上,它是
/usr/local/var/postgres/
。
To make sure this is the problem, look at the log file ( server.log
). 为确保这是问题所在,请查看日志文件(
server.log
)。 On the last lines you will see: FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
在最后
FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
行中,您将看到: FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
If so, rm postmaster.pid
如果是这样,
rm postmaster.pid
Restart your server. 重新启动服务器。 On Mac OSX, do:
在Mac OSX上,执行以下操作:
launchctl unload homebrew.mxcl.postgresql.plist
launchctl load -w homebrew.mxcl.postgresql.plist
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.