Digital Ocean에서 간단한 웹 서버를 설정하려고 하는데 sqlalchemy를 통해 데이터베이스에 연결하기 위해 URI를 사용하는 데 문제가 있습니다.
달리기
root@maudlin:/server/http/maudlin# psql postgresql://maudlin:<password>@localhost/maudlin
psql: error: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
실패했지만 실행 중
root@maudlin:/server/http/maudlin# psql -U maudlin
Password for user maudlin: <password>
psql (12.7 (Ubuntu 12.7-0ubuntu0.20.04.1))
Type "help" for help.
maudlin=>
통과하다.
내가 아는 한, 내 pg_hba.conf 파일은 로컬 IP 연결을 허용합니다.
# This file is read on server startup and when the server receives a
# SIGHUP signal. If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
host maudlin maudlin <personal ip 1>/32 md5
host maudlin maudlin <personal ip 2>/32 md5
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
선 없음
host all all 127.0.0.1/32 md5
md5를 사용하여 localhost에서 비밀번호로 ipv4 연결을 허용한다는 의미입니까?
나는 외부 IP의 최상위 목록에 컴퓨터의 IP를 추가하고 이를 통해 연결을 라우팅할 수 있다고 생각하지만 그것은 나쁜 생각인 것 같습니다™
디버깅 팁이나 제안 사항이 있는 사람이 있나요?
답변1
listen_addresses
내가 수정한 것으로 밝혀졌습니다 postgresql.conf
.
변화
listen_addresses = '<machine ip>' # what IP address(es) to listen on;
도착하다
listen_addresses = '<machine ip>, localhost' # what IP address(es) to listen on;
다시 시작하면 문제가 해결되었습니다.