2013-10-02 50 views
3

以下是在heroku管理的postgresql 9.2数据库的所有表上运行手动真空操作之前和之后的顶级臃肿表。正如你所看到的,没有太大的变化,有些浪费甚至增加了...
原因是什么?这是正常的行为吗?postgres真空不会改变臃肿

前:

type | schemaname |  object_name  | bloat | waste 
-------+------------+------------------------+-------+------------ 
index | public  | table_1    | 1.4 | 113 MB 
table | public  | table_2    | 1.1 | 92 MB 
table | public  | table_3    | 1.1 | 70 MB 
index | public  | table_4    | 1.2 | 66 MB 
index | public  | table_5    | 1.2 | 65 MB 
index | public  | table_6    | 1.2 | 64 MB 
index | public  | table_7    | 1.1 | 34 MB 
table | public  | table_8    | 1.1 | 19 MB 

后:

type | schemaname |  object_name  | bloat | waste 
-------+------------+------------------------+-------+------------ 
index | public  | table_1    | 1.4 | 123 MB 
table | public  | table_2    | 1.1 | 82 MB 
table | public  | table_3    | 1.1 | 82 MB 
index | public  | table_4    | 1.3 | 72 MB 
index | public  | table_5    | 1.3 | 72 MB 
index | public  | table_6    | 1.3 | 71 MB 
index | public  | table_7    | 1.1 | 39 MB 
table | public  | table_8    | 1.1 | 19 MB 
+0

你可以用'真空FULL'收缩表,以最小尺寸,但效果将会是暂时性的。另外不要忘记吸尘指数。 –

回答

2

铊;博士版本:看起来并不奇怪。

当行被更新或删除时,mvcc将旧行标记为从txid开始已经死亡;为了插入和更新插入一个新的插件。

自动真空然后有时踢,并且对于正常的DB操作是正常的。

真空迫使周期性和本地自动真空通常会发生。比如,你会在重大更新或删除之后运行它。

真空吸尘器的功能基本上是修剪磁盘页面中的死行。而且,除非我误解了,否则通过拆分太满的磁盘页面(如离表格的填充因子太远)为未来的新行创建新的空间,或通过合并太空的磁盘页面来删除不必要的空间(用于同样的原因)。

3

如果您需要将表格打包为最小尺寸,请运行VACUUM FULLVACUUM不会尝试压缩数据页面或释放磁盘空间,除非从表格的末尾(这是一种便宜的操作)。

通常,VACUUM是最好的方法。死元组占用的空间可以在以后的更新中重用,更新后的行版本可以用这种方式写入同一个数据页面。如果你将所有东西紧紧包装,新的行版本总是必须附加到表格的末尾。一些松懈一般改善写性能 - 除了只读表,这将是VACUUM FULL(一次)或甚至CLUSTER候选人。

客户端程序vacuumdb-f--full)开关。

Much more information in the Postgres Wiki on vacuuming.