0
I have a table with a large amount of data (380 million). I need to erase the old data that is no longer useful in the system. I am generating backup for precaution.
What’s the best way to erase?
- Delete with a restricting delete from which date ?
- Delete little by little 50k in 50k ?
- Delete bit by bit 1k in 1k ?
- Or some other way ?
I’m doing 50k to 50k but it’s pretty time-consuming. What is the best solution for agility?
If you’re going to clear the table, I believe the best option would be a
DROP
, then recreate it. But let’s see the teachers' opinion! rs +1– rbz
Actually I’m not gonna clean up, just erase old records
– Pedro Augusto
In your table you have the data field ? post the photo here of the fields
– Building the Future
Excluding large volumes of data
– rbz
I would use the first option
– Roberto de Campos
@Exactly what I am doing, but somehow the delay is significant. I would like it to be more agile
– Pedro Augusto
@Pedroaugusto Here it goes from your scenario. Example: Let’s assume that "copy" the record is 1.5x of the "delete" time. So if of the 380 million records you need to delete "half", then it really compensates the script with the loop. Assuming, you need to delete 90%, then you could create an equal table, migrate the 10% of records you want to keep, drop this table, and change the name of the copied.
– rbz
Maybe it’s faster to create a temporary table with the data you want to keep. Drop the old table, recreate it and re-insert the data from the time table,
– Reginaldo Rigo
@Reginaldorigo Basically what I said, but without wasting time getting back the data. But of course, it depends on the proportion that it needs to maintain/delete...
– rbz
Opened my head that commented. I will apply. Obg
– Pedro Augusto
If you use the option to save the data in a time table you do not need to drop and recreate, you can truncate the table that in thesis is the same thing.
– Reginaldo Rigo
I recommend to delete per day, and be careful not to fill the transaction log
– Claudio Lopes