Creating an Azure Web App with Postgresql database (is that possible?) Creating an Azure Web App with Postgresql database (is that possible?) postgresql postgresql

Creating an Azure Web App with Postgresql database (is that possible?)


Azure Web Apps Service is a PaaS which provides several services to host your web site apps. And we have limit permission to install PostgreSQL on it.

Currently, to host PostgreSQL on Azure, you can leverage virtual machines with linux as @theadriangreen mentioned. And you can use SSH command ssh user@VMhost to remote on your linux VM and set your PG configurations. You may refer to YoLinux Tutorial: The PostgreSQL Database and Linux for more about PG on Linux.

And additionally, you can create a docker contain with PostgreSQL image in Azure add-on market.

Login preview manage portal, click new=>search “postgres” in search bar, you can find the postgres service provided by docker.

enter image description here

You also can remote to this VM via SSH to set your PG configurations.

If you want a direct tcp connection to the PG server, you need to add 5432 port in the Inbound security rules.

In “All settings” of the VM server you created above, click “Network interfaces”=>click the interface in use=>click the network security group name in use, you can find the Inbound security rules in the settings page.

enter image description here

Then you can test the connection of your PG service:

import psycopg2try:    conn = psycopg2.connect(database="postgres", user="postgres", password="{password}", host="{host_ip}", port="5432")    print "Opened database successfully"    cur = conn.cursor()    cur.execute("SELECT ARRAY[1.1,2.1,3.1]::int[] = ARRAY[1,2,3]");    rows = cur.fetchall()    print(rows)    conn.commit()    print "Records created successfully";    conn.close()except Exception, e:    print "I am unable to connect to the database"


Azure Web Apps only offers web apps, since the database is provided by another service. Typically this is either Azure SQL, which provides a SQL Server database as a service, or ClearDB, which provides MySQL.

Thus to get your Django app up and running with Postgres, you're going to need to deploy the Postgres DB somewhere. Initially you could try with your settings.py pointed at your Heroku Postgres DB, however you might run into some firewall settings on the DB side.

If you were to follow the steps in the link (https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-postgresql/) then you could use that instance as your Postgres DB and adjust your settings.py file to point to that machine. You would also be able to change the postgresql.conf since you own the machine.