From fa065cd52b933a1a8b07e9e41e995adeae52ea33 Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 27 Aug 2022 11:36:50 +0200 Subject: [PATCH] add reseting of synapse_state_compressor to purge script --- purge/matrixpurge.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/purge/matrixpurge.sh b/purge/matrixpurge.sh index d8915c9..d99b8c3 100755 --- a/purge/matrixpurge.sh +++ b/purge/matrixpurge.sh @@ -1,6 +1,7 @@ #!/bin/sh # Do various clean-up tasks in matrix postgresql database # run as cron job all 6h or so +# run with argument reset every month or every week # URL to connect to matrix MATRIXURL="http://localhost:8008" @@ -34,6 +35,25 @@ then psql -t postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -c "insert into access_tokens(id, user_id, token, device_id, last_validated, used) values (${TOKENID}, '${ADMINID}', '${TOKEN}', 'SQLCLEANER', 1656788062940, 'f')" fi +[ "${1}" = "reset" ] && { + # reset state_auto_compressor + echo "-- Reset rust-synapse-compress-state" + psql -t postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -c "drop table state_compressor_state; drop table state_compressor_progress; drop table state_compressor_total_progress;" +} + +# purge events in a room - just for reference - ignore this block +# TODO provide a function that purges a room and also its state_groups +#ROOM="scTbMproDsaihhGesQ:pixelplanet.fun" +#DELURL="${MATRIXURL}/_synapse/admin/v1/purge_history/!${ROOM}" +#curl --insecure -XPOST -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" -d "{\"delete_local_events\": true, \"purge_up_to_ts\": 1660340843343}" ${DELURL} +# and its status check +#DELURL="${MATRIXURL}/_synapse/admin/v1/purge_history_status/MtGGeIGbsYTqdCUF" +#curl --insecure -XGET -H "Authorization: Bearer ${TOKEN}" ${DELURL} +# Remember that if you delete a room, it's state groups are still around +# https://github.com/erikjohnston/synapse-find-unreferenced-state-groups +#exit +# ----------------------------------------------------------------- + # Disable ratelimit echo "--Disabling ratelimit for admin user ${ADMINID}..." RATEURL="${MATRIXURL}/_synapse/admin/v1/users/${ADMINID}/override_ratelimit" @@ -90,3 +110,5 @@ time psql -t postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -c "SELECT [ -n "${BASH_VERSION}" ] && set +H psql postgresql://${SQLUSER}:${SQLPASSWD}@localhost/${SQLDB} -c "SELECT nspname || '.' || relname AS \"relation\", pg_size_pretty(pg_total_relation_size(c.oid)) AS \"total_size\" FROM pg_class c LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND c.relkind <> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size(c.oid) DESC LIMIT 20;" + +