Database table size did not decrease proportionately

穿精又带淫゛_ 提交于 2019-12-06 20:22:34

问题


I am working with a PostgreSQL 8.4.13 database.
Recently I had around around 86.5 million records in a table. I deleted almost all of them - only 5000 records are left. I ran

reindex

and

vacuum analyze

after deleting the rows. But I still see that the table is occupying a large disk space:

jbossql=> SELECT pg_size_pretty(pg_total_relation_size('my_table'));
pg_size_pretty 
----------------
7673 MB

Also, the index value of the remaining rows are pretty high still - like in the million range. I thought after vacuuming and re-indexing, the index of the remaining rows would start from 1.

I read the documentation and it's pretty clear that my understanding of re-indexing was skewed.

But nonetheless, my intention is to reduce the table size after delete operation and bring down the index values so that the read operations (SELECT) from the table does not take that long - currently it's taking me around 40 seconds to retrieve just one record from my table.

Update

Thanks Erwin. I have corrected the pg version number.

vacuum full

worked for me. I have one follow up question here:
Restart primary key numbers of existing rows after deleting most of a big table


回答1:


To actually return disk space to the OS, run VACUUM FULL.

A lot more details in this closely related recent answer on dba.SE.



来源:https://stackoverflow.com/questions/15515498/database-table-size-did-not-decrease-proportionately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!