title: Creating a postgresql DB using psycopg2
body: <p>I'm trying to create a postgres DB using a python script. Some research showed that using the psycopg2 module might be a way to do it. I installed it and made the required changes in the <code>pg_hba.conf</code> file. I used the following code to create the DB:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  from psycopg2 import connect
  import sys
  from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
  
  con = None
  con = connect(user='****', host = 'localhost', password='****')
  
  dbname = "voylla_production1710"
  
  con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
  cur = con.cursor()
  cur.execute('CREATE DATABASE ' + dbname)
  cur.close()
  con.close()
  </code></pre>
  
  <p>I tried replacing <code>con = connect(user='nishant', host = 'localhost', password='everything')</code> with <code>con = connect(user='nishant', password='everything')</code></p>
  
  <p>But I'm getting the following Error:</p>
  
  <pre><code>con = connect(user='nishant', host = 'localhost', password='everything') 
   File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
  connection_factory=connection_factory, async=async)
   psycopg2.OperationalError: FATAL:  database "nishant" does not exist
  </code></pre>
  
  <p>Could someone please tell me the right way of doing it.
  Thanks</p>