principlesqlModerate
Best Practice to Archive Old Data in MySQL
Viewed 0 times
bestpracticedatamysqloldarchive
Problem
I'm using a MySQL database to store logs from multiple servers. The database's growth on average is 50 GB per day. Its total size is now 1.7 TB.
It has
I want to move data older than one week to another database on the same server.
What are the steps needed for this?
As of now I do this:
I want to implement this with the following conditions:
...Or if you know of any best practice then let me know.
It has
ID and datetime columns.I want to move data older than one week to another database on the same server.
What are the steps needed for this?
As of now I do this:
- Create the Archive Database and table.
Insert into ArchiveDB.table select * from old_tbl where datetime
- Then DELETE FROM old_tbl WHERE datetime
I want to implement this with the following conditions:
- Insert and delete via batches.
- Reclaim the space after deleting from the old database.
- Update stats without downtime.
...Or if you know of any best practice then let me know.
Solution
With InnoDB and
One drawback: InnoDB's disk footprint is a lot more than Archive's.
What kinds of queries do you apply to the logs?
Blogs:
partitioning
and
chunking lengthy deletes
PARTITIONs, you could set up daily PARTITION BY RANGE(TO_DAY(...)) and use "Transportable tablespaces" to disassociate a day from the table and move it separately. This will be a lot faster than the queries it would take to do the INSERT...SELECT and DELETE. Once detached, the partition (now a table in its own right) can be moved to another database or server without impacting the ingestion of more data.One drawback: InnoDB's disk footprint is a lot more than Archive's.
What kinds of queries do you apply to the logs?
Blogs:
partitioning
and
chunking lengthy deletes
Context
StackExchange Database Administrators Q#179483, answer score: 11
Revisions (0)
No revisions yet.