title: Create a Postgres database using python
body: <p>I want to create Postgres database using Python.</p>
  
  <pre><code>con = psql.connect(dbname='postgres',
        user=self.user_name, host='',
        password=self.password)
  
  cur = con.cursor()
  cur.execute("CREATE DATABASE %s  ;" % self.db_name)
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>InternalError: CREATE DATABASE cannot run inside a transaction block
  </code></pre>
  
  <p>I am using psycopg2 to connect. I don't understand what's the problem.
  What am I trying to do is to connect to database (Postgres):</p>
  
  <pre><code>psql -postgres -U UserName
  </code></pre>
  
  <p>And then create another database:</p>
  
  <pre><code>create database test;
  </code></pre>
  
  <p>This is what I usually do and I want to automate this by creating Python script.</p>