PgSQL查询当前数据库列表
#!/usr/bin/env python #-*- encoding:utf-8 -*- import os db_user = 'backup' db_port = 5432 db_lists = os.popen(''' psql -h localhost -U %s -p %s -d postgres -t -c "SELECT datname FROM pg_database \ where datistemplate = false and datname != 'postgres'" ''' %(db_user, db_port)) db_names = db_lists.read() db_name = "" for line in db_names.splitlines(): db_name += line print(db_name)