Ajout scripts pour voir et réduire la taille des tables hydra

This commit is contained in:
Laurent Gourvenec 2023-07-26 17:05:42 +02:00
parent 52eadb6bf1
commit 0ab65611b0
2 changed files with 74 additions and 0 deletions

25
scripts/get_tables_sizes.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
(
mysql --defaults-file=/etc/mysql/debian.cnf hydra <<EOF
SELECT
TABLE_NAME AS \`Table\`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS \`Size\`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "hydra"
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
EOF
) | while read table size; do
if [ "${table}" != Table ]; then
real_size=$(ls -lh /var/lib/mysql/hydra/${table}.ibd | cut -d' ' -f 5)
else
real_size="Taille réelle"
fi
echo -e ${table}\\t${size}M\\t${real_size}
done
echo $a

49
scripts/optimize_hydra Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
# Optimize sur les tables d'Hydra
echo "Begin date: $(date)"
part=$1
if [ -z "$part" ]; then
echo 'Bad empty part. Please give a number between 1 and 7'
exit 1
fi
case $part in
1)
tables='hydra_oauth2_access'
;;
2)
tables='hydra_oauth2_oidc'
;;
3)
tables='hydra_oauth2_code'
;;
4)
tables='hydra_oauth2_authentication_request'
;;
5)
tables='hydra_oauth2_consent_request'
;;
6)
tables='hydra_oauth2_logout_request, hydra_oauth2_consent_request_handled'
;;
7)
tables='hydra_oauth2_authentication_session, hydra_oauth2_authentication_request_handled, hydra_oauth2_pkce'
;;
*)
echo "Unexpected error. Part: $part"
exit 1
esac
mysql --defaults-file=/etc/mysql/debian.cnf hydra <<EOF
OPTIMIZE TABLE $tables;
EOF
exit_val=$?
echo "End date: $(date)"
exit $exit_val