我在最近的Ubuntu(Debian)服务器上使用Postgres 9.X,并且一直在寻找维护脚本的例子,不幸的是空着。
Postgres文档是全面的维护抽象主题 – 其数据库应定期:
不幸的是,文档没有得到一个具体的例子,也许是因为涉及到很多变数。 不过,我会很感激一个基准维护脚本的例子:
我已经开始了,请帮助改进:
#!/bin/bash # this script maintains a Postgres Database Cluster # set any needed env vars: # PGDATABASE, PGUSER, PGPASSWORD, PGHOST, PGPORT, etc. read -p "Press ENTER to stop Postgres Clients, start maintenance..." sudo stop websrvr1 sudo stop websrvr2 sleep 2 echo -e "\nStarting backup ..." # another script for another question echo -e "\nStarting maintenance ..." # What is the best order for these? sudo -u postgres reindexdb --all --system sudo -u postgres clusterdb --all sudo -u postgres vacuumdb --all --analyze # --full # warned against # log rotation? Supposed to be handled automatically, # but I not yet seen more than one log file. echo Complete. Type ... to start services.
Autovacuum默认打开。 重新编程和集群并不是真正的基线维护任务。 你可以在需要改善performance或(重新索引)来修正指数腐败时做到这一点,但是这并不是你经常盲目做的事情。 日志旋转由Debian包装框架自动处理。 所以作为一个基准,你不需要自己做这些事情。
实际上你应该做的是设置备份(一开始,每天从一个cron作业运行pg_dumpall )和监视(像Nagios和Munin,或许是一开始)。 然后基于这样的监控,您将定期调整服务器设置并尝试提高查询性能。
我认为抽真空应该有一些门槛 – 比如浪费的数据库空间/行数大于30%。 这将节省大量的时间和无谓的努力。