Clean up the historical data of Table 8 group nodes, each node in the average table has 150 million records, need to clean up the field date_created 8000W data record, this field is not indexed.

 

Clean up the historical data of Table 8 group nodes, each node in the average table has 150 million records, need to clean up the field date_created 8000W data record, this field is not indexed.

 

 

 

Environment Introduction 
insufficient line of disk space, truncate the many dynamic table, disk space is occupied 87% of our nagios alarm threshold is 80%. So we continue to also receive email and SMS alarm. Date_created according to the time required to clean up the field, but in the beginning of the design because the original developers consider it insufficient date_created field is not indexed. In addition, these data can not back up directly deleted.

 

 

 

The question is, such a large amount of table records, delete records according to date_created field, but also there is no index, the difficulty must be very large. enl.ibd file size 29G size, disk space 32G, with the difference is relatively small.

 

 

 

[mysql@xxxx-xxx ide]$ ll -h enl.ibd
-rw-rw---- 1 mysql mysql 29G Aug 30 07:21 enl.ibd

 

Program planning, the preparation is probably using shell commands.

Although date_created no index, but we did experiments

mysql> select * from enl where date_created < "2013-01-01 00:00:00" limit 1000;

......

1000 rows in set (0.00 sec)

It seems the implementation of the results were good, then try the next delete effect

mysql> delete from enl where date_created < "2013-01-01 00:00:00" limit 1000;

Query OK, 1000 row affected (2.00 sec)

 

Can look each deletion 1000, to write the script delete it

for ((i=0;i<1000000;i++));do mysql -uroot -e 'use iden;delete  from enl where date_created < "2013-01-01 00:00:00" limit 1000;';done

 

Etc. After the delete operation is completed, look for low peak business perform alter table enl engine = innodb; to free up disk space.

Guess you like

Origin blog.csdn.net/csdnhsh/article/details/91410789