• postgres 得到所有表空间 和 表空间的位置



    import psycopg2


    def get_all_databasename():
    databasenames = []
    conn = get_connection("postgres")
    rows = excute_sql(conn,"select pg_database.datname from pg_database")
    for row in rows:
    print row[0]
    close_conn(conn)

    def get_data_basedirectory(conn):
    rows = excute_sql(conn, "show data_directory;")
    for row in rows:
    print row[0]
    # close_conn(conn)

    def get_all_tablespace(conn):
    rows = excute_sql(conn, "select spcname, pg_tablespace_location(oid) from pg_tablespace;")
    for row in rows:
    for i in range(len(row)):
    print row[i],
    print

    def get_connection(databsename):
    conn = psycopg2.connect(database=databsename, user="postgres", password="postgres", host="",
    port="5432")
    return conn

    def excute_sql(conn,sql):
    cur = conn.cursor()
    cur.execute(sql)
    rows = cur.fetchall()

    return rows

    def close_conn(conn):
    if conn != None:
    conn.close()

    if __name__ == '__main__':
    conn = get_connection('postgres')
    get_data_basedirectory(conn)
    get_all_tablespace(conn)
    close_conn(conn)
  • 相关阅读:
    软考相关试题
    qt中的toUtf8, toLatin1, Local8bit, toUcs4(转)
    qt的中文乱码问题
    《左耳听风》-ARTS-打卡记录-第八周
    杂题
    图论
    基础数据结构
    整除
    同余
    常用数学
  • 原文地址:https://www.cnblogs.com/dasheng-maritime/p/7449984.html
Copyright © 2020-2023  润新知