Skip to content

Instantly share code, notes, and snippets.

@dkeightley
Last active October 29, 2020 00:09
Show Gist options
  • Save dkeightley/bf350461ea3911a085566b850097d04d to your computer and use it in GitHub Desktop.
Save dkeightley/bf350461ea3911a085566b850097d04d to your computer and use it in GitHub Desktop.
k3s db compaction
#!/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