簡體   English   中英

無法連接Postgres服務器

[英]Unable to connect postgres server

當我嘗試連接服務器以創建數據庫時。 我收到此錯誤。

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

嘗試在Mac OSX上安裝Postgres.app

並啟動postgres,即單擊Open psql

然后,重新啟動Rails服務器。

之后,它應該可以解決您的問題。

更新(如果上述方法不起作用)

  • 要解決此問題,請刪除PID文件。 找到postgres數據目錄。 在使用自制軟件的Mac OSX上,它是/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"?行中,您將看到: FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?

  • 如果是這樣, rm postmaster.pid

  • 重新啟動服務器。 在Mac OSX上,執行以下操作:

    launchctl unload homebrew.mxcl.postgresql.plist
    launchctl load -w homebrew.mxcl.postgresql.plist

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM