PostgresSql 9.6 deletes suddenly became slow

こ雲淡風輕ζ 提交于 2021-01-29 08:45:55

问题


I have a database table where debug log entries are recorded. There are no foreign keys - it is a single standalone table.

I wrote a utility to delete a number of entries starting with the oldest.

There are 65 million entries so I deleted them 100,000 at a time to give some progress feedback to the user.

There is a primary key column called id

All was going fine until it got to about 5,000,000 million records remaining. Then it started taking over 1 minute to execute.

What is more, if I used PgAdmin and type the query in myself, but use an Id that I know is less than the minimum id, it still takes over one minute to execute!

I.e: delete from public.inettklog where id <= 56301001 And I know the min(id) is 56301002

Here is the result of an explain analyze


回答1:


Your stats are way out of date. It thinks it will find 30 million rows, but instead finds zero. ANALYZE the table.



来源:https://stackoverflow.com/questions/62925137/postgressql-9-6-deletes-suddenly-became-slow

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