Creating an Azure Web App with Postgresql database (is that possible?)
Question: I use Heroku to host a Django web app with a postgres back-end. I'm now
looking to migrate this web app to Azure, taking advantage of a great deal
Azure recently offered me.

But I'm confused about one thing: how can I create a Django website on Azure
with **postgresql as the database**? I successfully created a Django website,
connected it to git, but I can't seem to change it's DB to postgresql.

Hence, when I do `git push azure master`, I get the error: **Command python
setup.py egg_info failed with error code 1 in
D:\home\site\wwwroot\env\build\psycopg2** It fails on psycopg2 (postgresql).

Secondly, once I do successfully install postgresql on an Azure Web App, I'd
need to tweak its postgresql.conf file to tune the settings (defaults are too
low). How would I do that?

* * *

The documentation only talks about how to install PG for an Azure VM with
Linux, not an Azure Web App: <https://azure.microsoft.com/en-
us/documentation/articles/virtual-machines-linux-postgresql/>


Answer: 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](http://www.yolinux.com/TUTORIALS/LinuxTutorialPostgreSQL.html) 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](http://i.stack.imgur.com/4CP5k.png)](http://i.stack.imgur.com/4CP5k.png)

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](http://i.stack.imgur.com/YDtNM.png)](http://i.stack.imgur.com/YDtNM.png)

Then you can test the connection of your PG service:

    
    
    import psycopg2
    
    try:
        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"
    

