2013-07-06 458 views
0

我試圖在本地機器上使用pg_dump工具。但是,當我輸入的pg_dump database_name到我的終端窗口中,我得到了消息:pg_dump與數據庫的連接失敗

pg_dump: [archiver (db)] connection to database "demo" failed: 
could not connect to server: No such file or directory 

收到此錯誤消息後,我走進我的postgressql.conf文件(Postgres的配置文件)和將listen_addresses設置爲*。我的連接字符串如下出現:

- Connection Settings - 

#listen_addresses = '*'  # what IP address(es) to listen on; 
       # comma-separated list of addresses; 
       # defaults to 'localhost'; use '*' for all 
       # (change requires restart) 
#port = 5432    # (change requires restart) 
max_connections = 20   # (change requires restart) 
# Note: Increasing max_connections costs ~400 bytes of shared memory per 
# connection slot, plus lock space (see max_locks_per_transaction). 
#superuser_reserved_connections = 3 # (change requires restart) 
#unix_socket_directory = ''  # (change requires restart) 
#unix_socket_group = ''   # (change requires restart) 
#unix_socket_permissions = 0777  # begin with 0 to use octal notation 
       # (change requires restart) 
#bonjour = off    # advertise server via Bonjour 
       # (change requires restart) 
#bonjour_name = ''   # defaults to the computer name 
       # (change requires restart) 

我再重新啓動我的機器,希望當我在pg_dump在控制檯類型,不同的事情會發生。但是,即使在重新啓動後,我仍然無法連接到服務器錯誤消息(如上所述)。

接下來我應該嘗試哪些步驟來解決此問題?

謝謝你提前

回答

4

你是在Mac OS X,對不對?

您的PATH錯誤,它發現psql,pg_dump等來自Apple的內置副本psql PostgreSQL,而不是您單獨安裝的副本。

嘗試使用-h /tmp-h localhost。如果這有效,那證實這是問題。要正確地修復它,你需要調整你的PATH,以便正確的PostgreSQL二進制文件在那裏。

(我對Apple在OS X中捆綁PostgreSQL的工具與默認系統PATH上的工具以及與任何用戶安裝的工具發生衝突感到非常惱火)。

您的後續評論確認這是問題所在。您需要從安裝的PostgreSQL版本運行pg_dump。既然你沒有說你如何安裝PostgreSQL,你的操作系統或其他任何東西,我建議你通過搜索這個問題的現有提及來做到這一點。一種類似搜索:

「OS X」 的PostgreSQL路徑

將知識性。所以會this Stack Overflow search

或者,您可以明確指定路徑pg_dump。它取決於你如何安裝PostgreSQL,你沒有提到。它可以是/usr/local/bin/pg_dump,/opt/等。

+0

克雷格!太棒了。謝謝 –

+0

'-h localhost'在linux上的pg_dump上工作(ubuntu 16) –