欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PostgreSQL之連接失敗的問題及解決

 更新時間:2023年05月05日 14:27:39   作者:asin929  
這篇文章主要介紹了PostgreSQL之連接失敗的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

PostgreSQL連接失敗問題

問題

在pgAdmin中,將本地數(shù)據(jù)庫連接的host由localhost或127.0.0.1改為自己的真實ip–10.xxx.xxx.xxx后,連接失敗

報錯如下:

psql: could not connect to server: Connection refused  
Is the server running on host "my host name" (IP) and accepting  
TCP/IP connections on port 5432?  

解決

出現(xiàn)上述問題時,需修改postgresql.conf和pg_hba.conf文件。

此文件位于postgresql數(shù)據(jù)文件目錄中,默認(rèn)為/var/lib/pgsql/data/。

將postgresql.conf修改如下:listen_addresses = '*'。

pg_hba.conf中增加需要連接該數(shù)據(jù)庫主機的ip地址。

如下所示,增加對主機10.xxx.xxx.xxx的信任。

host    all             all             10.xxx.xxx.xxx/32         trust

如上設(shè)置后,使用10.xxx.xxx.xxx可正常連接。

解釋

原來,在客戶端訪問PostgreSQL數(shù)據(jù)庫時,PostgreSQL會讀取文件pg_hba.conf判斷是否信任該主機,故所有需要連接PostgreSQL Server的主機都應(yīng)當(dāng)在pg_hba.conf中添加對其信任,即使是Server主機也不例外!

PostgreSQL連接出錯 could not connect to server:Connection refused(0x0000274D/10061)

使用navicat連接本地PostgreSQL數(shù)據(jù)庫時報錯:

could not connect to server: Connection refused (0x0000274D/10061)  Is the server running on host"localhost" (:1) and acceptingTCP/IP connections on port 5433 ?

could not connect to server: Connection refused (0x0000274D/10061)  Is the server running on host"localhost" (127.0.0.1) and acceptingTCP/IP connections on port 5433?

首先檢查一下是不是沒有啟動PostgreSQL服務(wù),因為沒啟動服務(wù)可能會報這個錯誤(我就是);

方法如下

win+R打開輸入命令框,輸入services.msc打開服務(wù)列表。

右鍵啟動

再次嘗試連接數(shù)據(jù)庫,看是否成功。

如果沒成功那就進行以下步驟              

 1、在postgresql的安裝文件夾\9.5\data\pg_hba.conf里面找到“# IPv4 local connections:”

然后在這行上面添加“local pgsql all trust”,             

在它下面的“host    all         all         127.0.0.1/32          md5”             

下面添加一行,內(nèi)容為“host all all 192.168.91.1/24 md5”   

注:127.0.0.1/32和192.168.91.1/24中的32與24,用32表示該IP被固定,用24表示前3位固定,后面一位可以由自己設(shè),這樣,前3位ip地址與該設(shè)定相同的計算機就可以訪問postgresql數(shù)據(jù)庫。                 

2、PostgreSQL\9.5\data\postgresql.conf文件中,找到“#listen_addresses = 'localhost'”,把它改成“listen_addresses = '*'”。

這樣,postgresql就可以監(jiān)聽所有ip地址的連接。   

   

3、然后重啟postgresql服務(wù)。如果系統(tǒng)啟用了防火墻,請先關(guān)閉。如果要使用pgadmin連接遠程的數(shù)據(jù)庫服務(wù)器,須在SSL的選項中選擇允許。

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論