每天我从大表中删除成千上万条记录,然后进行一些计算(使用新数据)并替换之前删除的每条记录。我认为经常做vacuum tbl
会做到这一点。我知道它不会将磁盘空间返回到服务器,但是(因为pg文档)我以为因为我插入的记录数量与我删除的记录数量相同,所以我不会丢失任何/多少磁盘空间。但是,在将表移动到不同的名称空间之后(出于不相关的原因),该表从117GB变为44GB!所以......“替换插入”的最佳磁盘保存策略
有没有更好的策略比这使我的表不臃肿:
delete from tbl where ...etc... -- hundreds of thousands of rows removed
insert into tbl (...etc...) values (...etc...) -- hundreds of thousands of rows added back (fresh calcs)
.. repeat the above about 10 times a day ...
vacuum tbl
https://www.postgresql.org/docs/9.6/static/sql-vacuum.html
的PostgreSQL 9.6
我实际上没有减少表的大小是我的答案在这里: integer out of range and remaining disk space too small to convert id to bigint and other solutions
编辑1: 缺点vacuum full
对我来说太局限了。我正在全天候处理东西,所以我不能拥有这样的锁,并且我的可用磁盘空间在任何时间点都非常有限。试图以更好的方式来解决这个问题。
没有什么东西是绝对的“最好的”。根据某些特定标准,某物可能比其他物品更好。 'VACUUM FULL'可以帮助您压缩数据,从而节省CPU/IO和锁的开销。 – zerkms
@zerkms - 请参阅我的编辑1.谢谢! – mountainclimber