I have a Django app where the app and database reside in two separate VMs. I use Azure. In trying to connect to a postgresql backend hosted in a separate Azure VM, I'm writing: conn = psycopg2.connect("dbname='dbname' host='dnsname'")
, where value of host was gotten off the Azure portal from here:
I have also tried the Virtual IP address above as the host. Both approaches fail and I get a connection error: could not connect to server: Connection refused. Is the server running on host "myapp.cloudapp.net" (23.132.341.192) and accepting TCP/IP connections on port 5432?
Please note that I changed the IP address when pasting the error here.
The Azure VM hosting the postgresql database has port 5432
added to its Endpoints. Moreover, my app to which this postgresql backend belongs is a Django/Python app. My VMs have Ubuntu 14.04. In setting up postgresql, I ran the following installation commands on both app and database VMs separately:
sudo apt-get update
sudo apt-get install PostgreSQL postgresql-contrib
sudo apt-get install postgresql-server-dev-all
sudo apt-get install libpq-dev
And even though both app and database VMs have all of the above installed in them, the database itself was only created in the latter VM. I didn't create a separate user; I instead did:
sudo su postgres
psql -d postgres -U postgres
And then
CREATE DATABASE dbname;
How do I fix the psycopg2.connect
error? Ask for more information if needed.