問題解決:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


問題解決:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

錯誤提示:

psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
 
出現該問題的很多,以下是目前碰到的幾種情況,之后碰到繼續補充:
 
1.刪除了/tmp路徑中的.s.PGSQL.5432 與.s.PGSQL.5432.lock文件
 
解決:重啟數據庫 $sudo service postgresql restart 
 
2.修改監聽端口:
之前用5434監聽,后來改為5432,數據庫啟動,但是psql無法進入數據庫,通過psql -p 5432可以進入。
 
解決:安裝時配置了端口PGPORT。修改~/.bash_profile或/etc/profile文件中的端口指定。
 
3.修改了postgresql.conf 中的unix_socket_directories

分析見兩篇博文:
http://francs3.blog.163.com/blog/static/40576727201332594924829/
http://blog.csdn.net/huguangshanse00/article/details/40413549

引用其中:
"先來看看 socket 文件 "/tmp/.s.PGSQL.1921",其中 1921 是 pg 的端口號; socket 文件可以通過
postgresql.conf 文件以下參數配置:
#unix_socket_directory = ''
#unix_socket_permissions = 0777
備注:其中參數 unix_socket_directory 用來配置 socket 文件的目錄,默認是 /tmp 目錄,參數 
unix_socket_permissions 用來設置 socket 文件的權限。"
       
解決方法:指定host,用psql -h 連接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM