I want to get the list of all databases in Postgresql server in python list.
Basically then i want to create those insode another database
But i am not able to get it.
This is what i 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):
# Get a list of databases with :
db_command=" psql -h localhost -U pguser tesdb -c '\l'"
db_list = os.popen(db_command)