首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将服务器上的postgres连接到本地的postico

无法将服务器上的postgres连接到本地的postico
EN

Stack Overflow用户
提问于 2020-07-11 04:09:24
回答 1查看 195关注 0票数 1

当我将服务器上的postgres连接到本地的postico时,我会得到以下错误

代码语言:javascript
复制
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文件,所以我创建了这些文件,如下所示

我找到了这个解释,但仍然没有解决我的问题。

代码语言:javascript
复制
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的

代码语言:javascript
复制
port=5432
listen_addresses='*'

这里我是如何配置pg_hba.conf的

代码语言:javascript
复制
 host    all             all              0.0.0.0/0                       md5
 host    all             all              ::/0                            md5

当我跑的时候

代码语言:javascript
复制
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防火墙,没有打开,我的服务器在数字海洋上使用Ubuntu16.04.6 (LTS) x64。

这是postgres文件的路径

代码语言:javascript
复制
postgres@borroupapi:~/9.5/main$

当我运行find / -name postgresql.conf时,我得到了这个

代码语言:javascript
复制
/usr/lib/tmpfiles.d/postgresql.conf

但是我找不到在postgres用户中登录的路径

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-15 14:25:58

尝试此方法修复postgres 9.5中的问题,postgresql.conf和pg_hba.conf文件位于

代码语言:javascript
复制
/etc/postgresql/9.5/main/

不在

代码语言:javascript
复制
/var/lib/postgresql/9.5/main/

您必须以服务器root用户的身份登录,并运行每个命令,这将给出文件的位置。

代码语言:javascript
复制
find / -name postgresql.conf

find / -name pg_hba.conf

在我的例子中,当我运行命令时,我得到了以下命令

代码语言:javascript
复制
/var/lib/postgresql/9.5/main/postgresql.conf
/etc/postgresql/9.5/main/postgresql.conf
/usr/lib/tmpfiles.d/postgresql.conf
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62845100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档