Postgresql的客户端默认连接到以用户命名的数据库。这就是为什么您会收到错误致命提示:的原因 database "nishant" does not exist
。
您可以连接到默认系统数据库postgres
,然后发出查询以创建新数据库。
con = connect(dbname='postgres', user='nishant', host='localhost', password='everything')
编辑:顺便说一句,请检出?/ .pgpass文件以安全地存储密码,而不是在源代码中(http://www.postgresql.org/docs/9.2/static/libpq- pgpass.html)。libpq,Postgresql客户端库,请检查此文件以获取正确的登录信息。非常方便。