簡體   English   中英

無法將服務器上的 postgres 連接到我本地的 postico

[英]can't connect postgres on the server to postico on my local

當我將服務器上的 postgres 連接到本地的 postico 時,出現此錯誤

could not connect to server: Operation timed out
Is the server running on host "http://159.65.65.203/" (92.242.140.2) and accepting
TCP/IP connections on port 5432?

我在任何地方都找不到 postgresql.conf 和 pg_hba.conf 文件,所以我創建了這些文件,如下圖所示

在此處輸入圖像描述

我找到了這個解釋,但仍然沒有解決我的問題

Ubuntu does not use the standard pg_ctl for postgreSQL. Instead, it 
uses pg_ctlcluster.
That in turn controls the different PostgreSQL clusters. When you do 
an install of a new cluster, pg_ctlcluster is smart enough to put
postgresql.conf & pg_hba.conf into separate dirs.
So to be specific, /usr/lib/tmpfiles.d/postgresql.conf is just a tmp 
file that you can ingnore, /etc/postgresql/9.4/main/postgresql.conf is 
the original version for the 9.4 cluster and
/var/lib/postgresql/9.4/main/postgresql.auto.conf is the actual, live
version of the 9.4 cluster that you need to change to affect the 9.4
cluster. Likewise for the pg_hba.conf.
reference https://www.postgresql.org/message- 
id/CANu8FiygR5CdeqRTiE0YM+BQk6aK+qZyw2frH_FWV27J1exong@mail.gmail.com

這里我如何配置 postgresql.conf

port=5432
listen_addresses='*'

這里我是如何配置 pg_hba.conf

 host    all             all              0.0.0.0/0                       md5
 host    all             all              ::/0                            md5

當我跑步時

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program 
name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      
29761/postgres
tcp6       0      0 :::22                   :::*                    LISTEN      -

顯然 5432 並非對所有連接都開放。 當我使用 postman 進行 api 調用時似乎有效。 我目前使用的 mac 防火牆沒有打開,我的服務器在 digitalocean 上使用 Ubuntu 16.04.6 (LTS) x64。

這是 postgres 文件的路徑

postgres@borroupapi:~/9.5/main$

當我運行 find / -name postgresql.conf 我明白了

/usr/lib/tmpfiles.d/postgresql.conf

但我找不到登錄 postgres 用戶的路徑

試試這個來解決 postgres 9.5 中的問題 postgresql.conf 和 pg_hba.conf 文件位於

/etc/postgresql/9.5/main/

不在

/var/lib/postgresql/9.5/main/

您必須以服務器 root 用戶身份登錄並運行每個命令,這將給出文件在哪里

find / -name postgresql.conf

find / -name pg_hba.conf

在我的例子中,當我運行命令時,我得到了這個

/var/lib/postgresql/9.5/main/postgresql.conf
/etc/postgresql/9.5/main/postgresql.conf
/usr/lib/tmpfiles.d/postgresql.conf

暫無
暫無

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

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