postgres数据库中表的大小异常增长

时间:2018-08-26 03:37:25

标签: postgresql postgresql-9.2

我们的数据库大小之一是50gb。其中一张表有149444622条记录。该表的大小为14GB,其索引大小为16GB。 该表及其索引的总大小为30GB。我已经在该表上执行了以下步骤。

reindex table table_name;

vacuum full verbose analyze on table_name;

但是表的大小及其索引大小仍然没有减少。请引导我。如何进一步进行。

下表的结构。

enter image description here

1 个答案:

答案 0 :(得分:4)

14 GB的数据不是异常。算一下吧。

只需将列的大小相加即可得到每列68个字节。

2 bigints @ 8 bytes each    16 bytes
4 integers @ 4 bytes each   16 bytes
4 doubles @ 8 bytes each    32 bytes
1 date @ 4 bytes             4 bytes
                            --------
                            68 bytes

149,444,622(每个68个字节)约为9.7 GB。如果没有数据库开销,这是数据的绝对最小大小。 But there is overheadThis answer reckons its about 28 bytes per row。 68 + 28是每行96个字节。这使我们达到了14.3 GB。就是你所拥有的。


我怀疑您可以减小大小而无需更改架构,删除索引或删除数据。如果您提供有关架构的更多详细信息,我们可以提出建议,但我建议您将其作为一个新问题。

最后,考虑50 GB是一个很小的数据库。例如,the smallest paid database offered by Heroku是64 GB,每月只需$ 50。在这种情况下,只使用更大的磁盘就可以了。

相关问题