Problem in Deleting old data

simplementese5 years ago

Dear, good morning.

I have a database of approximately 50GB (information all this year) on ssd mirrored disks.
which is a bit slow for consultations so I decided to delete and leave live the last 3 months.

Searching in the forum I decided to delete it from the sql and use these two syntaxes.

The problem is that in both of them the connection with the sql exhausts me, probe in more distant periods and go down, but the same thing happens.

delete from tc_positions where servertime <DATE(NOW()-INTERVAL 90 day)


SET foreign_key_checks = 0;
DELETE FROM tc_positions WHERE serverTime <DATE_ADD(NOW(), INTERVAL -8 MONTH);
UPDATE devices SET positionId = NULL WHERE positionId NOT IN (SELECT id FROM positions);
SET foreign_key_checks = 1;

thx!!

Mariusz5 years ago

I had error becouse i wanted to delete too much data. Try do it like this:

DELETE FROM [TracCar].[dbo].[tc_positions]
      WHERE id=(select MIN(id) from [TracCar].[dbo].[tc_positions])
GO 100000

it deletes last 100000 records

simplementese5 years ago

Anton, any help or solution to clean my base?

Ernesto Vallejo5 years ago

try your delete command based on ids. I use it and easily deletes up to 10M records at once.

simplementese5 years ago

Could you provide me with the query you use to erase that amount?

Rock4 years ago

HI!!! Is a way to do this automatic????