gp_gather_object_size script
来源:互联网 发布:c语言 百度网盘 编辑:程序博客网 时间:2024/05/16 11:33
由于数据库对象(table)太多太大,而且业务比较繁忙,在收集统计对象大小信息的过程中经常会增删改对象,导致数据库报对象不存在的错误,于是写了个脚本用于完成上述功能,并到处到csv文件便于分发相关维护、开发人员。
gp_gather_object_size script
#!/usr/bin/env python# -*- coding: UTF-8 -*-## Copyright [Gtlions Lai].# Create Date:# Update Date:"""summarization ahout this script.detail ahout this script Class(): summarization about Class ... function(): summarization about function ..."""__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'import psycopg2import csvdb = psycopg2.connect(dbname="gtlions", user="gpadmin", host="10.1.1.1")# db = psycopg2.connect(dbname="gtlions", user="gpadmin", host="10.1.1.1")# db = psycopg2.connect(dbname="gtlions", user="gpadmin", host="10.1.1.1")cur = db.cursor()cur.execute('select current_database()')current_database = cur.fetchone()f = open("gp_object_size" + current_database[0] + ".csv", "w")writer = csv.writer(f, lineterminator="\n", quoting=csv.QUOTE_NONNUMERIC)cur.execute( '''select a.schemaname ,a.tablename ,a.tableowner from pg_tables a where a.schemaname not like 'pg_temp%' and a.schemaname not in ('gp_toolkit','information_schema','pg_catalog','gpmg') order by 1,2;''')writer.writerow(("schemaname", "tablename", "tableowner", "size-1", "size-byte"), )for object in cur.fetchall(): objectname = object[0] + '.' + object[1] try: cur.execute( "select pg_size_pretty(pg_total_relation_size('" + objectname + "')),pg_total_relation_size('" + objectname + "');") sizeinfo = cur.fetchone() writer.writerow(object + sizeinfo) except psycopg2.ProgrammingError, e: print ef.close()cur.close()db.commit()db.close()
-E0F-
0 0
- gp_gather_object_size script
- script
- script
- script
- script
- script
- script
- script
- <script>
- script
- script
- script
- script
- script
- script
- script
- Script
- <script></script>
- ORA-12154: TNS: 无法解析指定的连接标识符
- Spring的IOC
- Eclipse中10个最有用的快捷键组合
- git常见操作命令
- Golang 命令行字体颜色
- gp_gather_object_size script
- Mac上使用Source Tree的一些总结
- 关于sony等机型拍照后返回重载了Activity的问题
- Python linecache、glob模块
- iOS学习 textFile的键盘
- SSO跟踪
- android支付宝支付
- android冒烟测试与单元测试
- import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包