Pregunta

I have database with one of the tables that got over populated ( 465025579 records ), what is the best way to delete the records and keep only 3 months of the records, without the device to hang?

¿Fue útil?

Solución

Delete them in batches based on date earliest first. Sure it'll take some time, but it's safer (as you are defining which to delete) and not so resource intensive. It also means you can shrink the database in batches too, instead of one big hit (which is quite resource intensive).

Yeah, it might fragment the database a little, but until you've got the actual data down to a manageable level, there isn't that much you can do.

To be fair, 200G of data isn't that much on a decent machine these days.

All this said, I'm presuming you want the database to remain 'online'

Otros consejos

If you don't need the database to be available whilst you're doing this, the easiest thing to do is usually to select the rows that you want to keep into a different table, run a TRUNCATE on this table, and then copy the saved rows back in.

From TRUNCATE:

TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top