2013-03-05 122 views
0

這是我的錯誤。postgresql無法連接錯誤。

PG::Error - 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? 
could not connect to server: Connection refused 
    Is the server running on host "localhost" (fe80::1) and accepting 
    TCP/IP connections on port 5432? 

我使用自制軟件到/ usr/local/bin目錄/ PSQL 爲了得到它認識到這個版本,我不得不加入到我的bash文件安裝PostgreSQL的。

export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH" 

當我cd到我的Rails應用程序,並運行命令

rails s 

它開始了下面

=> Booting Thin 
=> Rails 4.0.0.beta1 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
>> Thin web server (v1.5.0 codename Knife) 
>> Maximum connections set to 1024 
>> Listening on 0.0.0.0:3000, CTRL+C to stop 

然後,當我嘗試查看應用程序上http://0.0.0.0:3000我得到的以上錯誤 任何人都可能知道爲什麼會發生這種情況。

回答

0

正如消息所述,導致此錯誤的最可能原因是您實際上並未運行postgres服務器。通常你會引導這個了*的/ etc/init.d /的pg_ctl,*但既然你安裝了這個通過釀造,只需在終端窗口

postgres 

運行以下命令,服務器應啓動。如果您沒有將此設置在啓動時自動啓動,則每次重新啓動計算機後都需要運行該命令。

+1

postgres不知道在哪裏可以找到服務器配置文件。 您必須指定--config-file或-D調用選項或設置PGDATA環境變量。 – user1096509 2013-03-06 00:16:00

+0

好的發現如何使用命令行'brew info postgres'啓動它。啓動行是'pg_ctl -D/usr/local/var/postgres -l /usr/local/var/postgres/server.log start' – user1096509 2013-03-06 00:26:30

+0

當我從mysql更改爲postgres時,在Nitrous.io上發生此錯誤。不得不重新啓動這個盒子,把我的database.yml改成'host:localhost'並把'listen address改爲'*''。 我的最終解決方案發現[這裏](https://serverfault.com/questions/461257/cant-connect-to-postgres-in-production/461265#461265) – Shadoath 2014-10-21 22:33:05