Repository navigation
Add flag to recover disk space rebuilding the table #1482
Unanswered
AlejandroMuralles
asked this question in
Ideas
Replies: 1 comment
|
I would change the proposed implementation before using it on a live activity log: the shown
References: implicit commits, I would keep pruning and physical reclamation as separate operator actions, with the latter requiring |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello!
I woudl be great to add an optional --rebuild flag to the activitylog:clean Artisan command.
When pruning thousands of logs, MySQL/InnoDB marks the freed pages internally but retains the physical file size (.ibd) on disk, leading to persistent high disk space utilization. Passing --rebuild automatically recreates the underlying table structure right after cleaning, returning the freed storage back to the host operating system.
Changes Included
Added a --rebuild option to the CleanCommand class (activitylog:clean).
Implemented table desfragmentation logic using a temporary table swap (CREATE TABLE LIKE, INSERT SELECT, DROP, RENAME) to ensure 100% contiguity without data loss.
Added console feedback messages detailing whether the table was rebuilt.
Added tests covering the clean command execution with and without the --rebuild option.
Motivation & Use Case
In high-volume applications or production servers running on tight storage constraints (e.g., cloud VMs/Droplets), running activitylog:clean removes millions of old records, but OPTIMIZE TABLE often fails or aborts due to lack of temporary space or active table locks. Rebuilding via a clean temporary table swap physically shrinks the .ibd file on disk from gigabytes to megabytes in a single atomic step.
Usage Example
php artisan activitylog:clean --force --rebuildIt could be a differente command
php artisan activitylog:rebuildI think it could be something like this code
All reactions