[英]Can't connect to Postgresql
有類似的問題,但對我來說沒有任何作用。
我在運行Ubuntu Server 16.04的服務器上安裝了一個postgres。
在postgresql.conf我設置:
listen_addresses = '*'
port = 5432
postgres的狀態給出:
●postgresql.service - PostgreSQL RDBMS已加載:已加載(/lib/systemd/system/postgresql.service;已啟用;供應商預設:已啟用)活動:已激活(已退出)自2019-06-19 Wed 09:30:25 UTC; 3min 24s ago Process:23683 ExecStart = / bin / true(code = exited,status = 0 / SUCCESS)主PID:23683(代碼=退出,狀態= 0 /成功)
Jun 19 09:30:25 ip-172-31-43-128 systemd [1]:啟動PostgreSQL RDBMS ... Jun 19 09:30:25 ip-172-31-43-128 systemd [1]:啟動PostgreSQL RDBMS。
我在流復制模式下設置了postgresql,有3個從屬。
我的pg_hba.conf文件如下所示:
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
host all all 172.31.43.128/24 md5
host replication all 172.31.32.119/32 trust # the slave1
host replication all 172.31.40.107/32 trust # the slave2
host replication all 172.31.44.8/32 trust # the slave3
host postgres pgpool 172.31.33.203/32 trust # the client
host postgres postgres 172.31.33.203/32 trust # new
host all all 172.31.33.203/32 md5 # the client
我嘗試連接到python中的master實例:
import psycopg2
import matplotlib.pyplot as plt
import sys
import time
import pprint
def connect_postgrs():
try:
conn = psycopg2.connect("dbname=my_pgpool_db user=postgres password=antonis host=172.31.43.128")
print "Connected"
except psycopg2.Error as e:
print str(e)
if __name__ == "__main__":
connect_postgrs()
我收到錯誤:
無法連接到服務器:連接超時服務器是否在主機“172.31.43.128”上運行並接受端口5432上的TCP / IP連接?
命令: netstat -nlt
給出以下輸出:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 172.31.43.128:5432 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
有誰知道我做錯了什么?
設置listen_addresses = '*'
后你重啟了Postgres嗎?
通常,你會看到
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
代替
tcp 0 0 172.31.43.128:5432 0.0.0.0:* LISTEN
您可能需要在pg_hba.conf中更改此條目
host all all 172.31.43.128/24 md5
以下任何一個:
host all all 172.31.43.0/24 md5
host all all 172.31.43.128/32 md5
然后重新加載您的配置:
sudo service postgresql reload
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.