3

以下是对 heroku 管理的 postgresql 9.2 数据库中的所有表运行手动清理操作之前和之后最臃肿的表。如您所见,变化不大,甚至增加了一些浪费……
可能是什么原因?这是正常行为吗?

前:

 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
4

2 回答 2

3

If you need to pack your tables to minimum size, run VACUUM FULL. VACUUM does not try to compact data pages or free disk space, except from the end of a table (which is a cheap operation).

Normally, plain VACUUM is the much preferable approach. The space occupied by dead tuples can be reused by later updates, and updated row versions can be written to the same data page this way. If you pack everything tightly, new row versions always have to be appended to the end of the table. Some slack generally improves write performance - except for read-only tables, which would be candidates for VACUUM FULL (once) or even CLUSTER.

The client program vacuumdb has the -f (--full) switch.

Much more information in the Postgres Wiki on vacuuming.

于 2013-10-02T15:58:56.653 回答
2

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

当行被更新或删除时,mvcc 从 txid 开始将旧行标记为死;从该 txid 开始插入一个新的用于插入和更新。

自动真空有时会启动,对于正常的数据库操作来说很好。

真空强制执行自动真空通常定期和局部执行的操作。例如,您将在大更新或删除后运行它。

基本上,清理的作用是从磁盘页面中删除死行。而且,除非我弄错了,否则通过拆分太满的磁盘页面(如离表的填充因子太远)为未来的新行创建一些新空间,或者通过合并太空的磁盘页面来删除不必要的空间(对于同理)。

于 2013-10-02T15:37:40.180 回答