zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    AC自动机解题记录
    German Collegiate Programming Contest 2018​ A. Attack on Alpha-Zet
    UVa-1152 4 Values Whose Sum Is 0
    2018 宁夏省赛 F. Moving On
    F
    PIL之基础应用
    数字数据转图片
    随机梯度下降实现
    回归分析效果度量
    线性回归分析
  • 原文地址:https://www.cnblogs.com/dasheng-maritime/p/7449984.html
Copyright © 2011-2022 走看看