[Answered ]-Psycopg2.connect failing with error 'connection refused' (Django app+db hosted on separate VMs)

2๐Ÿ‘

โœ…

As to separate PostgreSQL into another Azure VM, we need to configure several settings both on Azure VM side and your PostgreSQL service.

1, modify the listen_addresses="*" at /etc/postgresql/9.4/main/postgresql.conf ,to allow other client beside local to request your PostgreSQL service.

2, Add the following line as the first line of /etc/postgresql/9.4/main/pg_hba.conf. It allows access to all databases for all users with an encrypted password:

# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all all 0.0.0.0/0 md5

3, run command sudo service postgresql restart to restart the service

4, login Azure manage portal, add a request rule in Endpoints page of your VM, configure public port 5432 to private port 5432:
enter image description here

๐Ÿ‘คGary Liu

Leave a comment