[Fixed]-Django app with postgres backend throwing error in new set up (Azure VM)

1👍

According your description, it seems a PostgreSQL configuration issue. As I have a quick test on ubuntu + PostgreSQL + python27 + psycopg2 to test the connection to local PostgreSQL on Azure VM. However, I cannot reproduce your issue, it works fine on my side. Here are my steps of installing PostgreSQL service and test on python, for your information:

1, remote to Azure VM, and install PostgreSQL via sudo apt-get update, sudo apt-get install PostgreSQL postgresql-contrib

2, create a new PostgreSQL user: psql , ` create user someuser password ‘somepassword’;

3, install PostgreSQL service which is required by psycopg2 : sudo apt-get install postgresql-server-dev-9.4

4, install python package psycopg2: sudo apt-get install python-pip and sudo apt-get install python-psycopg2

5, And test in python code:

import psycopg2

try:
    conn = psycopg2.connect("dbname='postgres' user=' someuser' host='localhost' password='somepassword'")
    cur = conn.cursor()
    cur.execute("""SELECT 1=1""")
    rows = cur.fetchall()
    for row in rows:
        print "   ", row[0]
except:
    print "I am unable to connect to the database"

And specific to your issue, I think you can quick check the following points for troubleshooting:

1, make sure your PostgreSQL service is running, because of here is an issue with the same error message with you Posgresql connection through port 5432.

2, make sure the host setting of PostgreSQL in your Django app is “localhost”, and you can easy test in psql –h localhost -Usomeuser to login on PostgreSQL. If you occur the issue, you can try to configure your PostgreSQL server shown in Postgresql and TCP/IP connections on port 5432.

Leave a comment