[英]Amazon Ubuntu Postgres - Won't Connect to Localhost
我正在尝试使用以下引擎字符串连接到postgres: sql_alchemy_conn = postgresql://username:password@localhost:5439/dbname
我得到以下错误:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "172.31.43.180" and accepting
TCP/IP connections on port 5439?
我知道该服务正在运行:
sudo service postgresql status
返回:
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2017-08-27 19:21:06 UTC; 4min 21s ago
Process: 1310 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1310 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
Aug 27 19:21:06 ip-loc-al-ip-add systemd[1]: Starting PostgreSQL RDBMS...
Aug 27 19:21:06 ip-loc-al-ip-add systemd[1]: Started PostgreSQL RDBMS.
此外,它似乎确实在本地主机上监听('我也尝试过将其提供给ip而不是dns),至少:
netstat -anpt | grep 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 -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::5432 :::* LISTEN -
另外,配置文件中的以下内容:
postgresql.conf
:#-连接设置-
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
pg_hba.conf
:
local all all trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 127.0.0.1/24 md5
# IPv6 local connections:
host all all ::1/128 md5
最后,我不需要或不希望从外部连接访问此文件。 这仅仅是一个本地访问的数据库。
您在端口号上有一个错误,应该在postgresql:// username:password @ localhost:5432 / dbname上连接,而不是postgresql:// username:password @ localhost:5439 / dbname 54
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.