cur = con.cursor()
show_query('current database', 'SELECT current_database()')
cur.execute('CREATE DATABASE ' + dbname)
show_query('available databases', 'SELECT * FROM pg_database')
cur.close()
con.close()
print('connecting to %s ...' % dbname)
con = connect(user='postgres', database=dbname, host='localhost', password=
    '*****', port=5492)
cur = con.cursor()
show_query('current database', 'SELECT current_database()')
cur.close()
con.close()
change database (postgresql) in python using psycopg2 dynamically