How to reclaim database space from synapse

So, synapse is a neat tool, but it sucks at managing storage space. The built-in automatic room history purges works, but it doesn't delete the state data. If a matrix room gets spammed or just too large, you can't remove the state data without kicking all the users out of the room, deleting the data, then letting them rejoin. This can be mitigated with the rust compressor tool for synapse, which apparently has amazing squishing power, but I went a different route. Here are my notes from the process.

This is mostly based on forest's notes and this script.

Purge Remote Media

Purge Big Rooms

Purge Rooms from Database

Purge State Group IDs

Cleanup

Remove table and index bloat

DONE!