Thursday, 15 March 2012

linux - How can i get the list of databases in Postgresql in python -



linux - How can i get the list of databases in Postgresql in python -

i want list of databases in postgresql server in python list. want create insode database not able it.

this have tried

config_read = { 'host':'psql-002', 'database':'tesdb', 'user':'pguser', 'port':'5432', 'password':'mypass' } class exportpsql(): def __init__(self): try: conn = psycopg2.connect(**config_read) self.conn = conn except: print "eror connecting database" def run(self): # list of databases : db_command=" psql -h localhost -u pguser tesdb -c '\l'" db_list = os.popen(db_command)

do pg_dumpall , psql superuser

pg_dumpall -h localhost -u postgres -f pg_dumpall.sql

if want re-create schema utilize --schema-only parameter.

to restore cluster

psql -f pg_dumpall.sql postgres

python linux postgresql

No comments:

Post a Comment