前端之家收集整理的这篇文章主要介绍了
postgresql 定时vacuum脚本,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
# -*- 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
原文链接:https://www.f2er.com/postgresql/193750.html