问题
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