Deleting records takes long time and unltimately servers hang
We have a simple query to delete huge records (Keeping only records from last two days) from database and it runs during night time. But it takes around 45 mins and by that time transactions just wait for data and servers utilization go high.
delete from table where date < sysdate-2;
Any suggestions or ulternatives how we can improve the time of this job?
Your help will be greatly appreciated!
Any suggestions or ulternatives how we can improve the time of this job?
Your help will be greatly appreciated!
Thanks in advance!!!
If the ratio is like 10:1(ie., i mean very high) or more between what gets deleted and what is left behind, a better approach would be to CTAS what you want to retain and drop/truncate the old table. Rename it to original, if dropped.
If you can't do this, there are lots of ways to improve it; at first, do as Davey said, trace. Analyze it. Diagnose. Tune it.
You can also do date range partitioning. Every day would be one partition, and every day you would drop the partition from two days ago. Just be aware that an on delete row level trigger would probably be expensive to maintain.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Bookmarks