Last active
October 29, 2020 00:09
-
-
Save dkeightley/bf350461ea3911a085566b850097d04d to your computer and use it in GitHub Desktop.
k3s db compaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MYSQL_PASS= | |
MYSQL_USER=master | |
LIMIT=100000 | |
SELECT_STMT="select max(id) m, count(*) c, name from kine group by name order by c desc limit 100;" | |
# start compaction | |
mysql -u$MYSQL_USER -p$MYSQL_PASS -e "$SELECT_STMT" | while read m c name; do | |
mysql -u$MYSQL_USER -p$MYSQL_PASS -e "delete from kine where name = $name and id < $m limit $LIMIT" | |
mysql -u$MYSQL_USER -p$MYSQL_PASS -e "update kine set prev_revision = $m where name = "compact_rev_key"" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment