我想获取所有数据库的列表Postgresql
python 列表中的服务器。
基本上我想在另一个数据库中创建它们
但我无法得到它。
这就是我尝试过的
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)
做这一切与pg_dumpall http://www.postgresql.org/docs/current/static/app-pg-dumpall.html and psql http://www.postgresql.org/docs/current/static/app-psql.html作为超级用户
pg_dumpall -h localhost -U postgres -f pg_dumpall.sql
如果您只想复制架构,则使用--schema-only
范围。
将其恢复到另一个集群
psql -f pg_dumpall.sql postgres
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)