加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql 定时vacuum脚本

发布时间:2020-12-13 16:51:45 所属栏目:百科 来源:网络整理
导读:# -*- coding: utf-8 -*-import pg,multiprocessinglst=[{"dbname":"postgres","host":"127.0.01","port":5432,"user":"postgres","passwd":"123456"},]def exe_job(item): try: db = pg.DB(dbname=item['dbname'],host=item['host'],port=item['port'],user
# -*- coding: utf-8 -*-

import pg,multiprocessing

lst=[
{"dbname":"postgres","host":"127.0.01","port":5432,"user":"postgres","passwd":"123456"},]

def exe_job(item):
    try:
        db = pg.DB(dbname=item['dbname'],host=item['host'],port=item['port'],user=item['user'],passwd=item['passwd'])
        for table in db.get_tables():
            db.query("VACUUM %s ;" %(table))
            db.query("analyze %s ;" %(table))
            print("%s %s" % (item['dbname'],table))
    except Exception as e:
        print(e)
    finally:
        db.close()

if __name__ == '__main__':
    pool_size=16
    pool = multiprocessing.Pool(processes=pool_size)
    pool.map(exe_job,lst)
    pool.close() # no more tasks
    pool.join()  # wrap up current tasks

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读