element-hq / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://element-hq.github.io/synapse
GNU Affero General Public License v3.0
1.45k stars 172 forks source link

The `cache_invalidation_stream_by_instance` table is filled even when workers are not in use #15869

Open matrixbot opened 10 months ago

matrixbot commented 10 months ago

This issue has been migrated from #15869.


The only precondition to having this table filled with cache invalidations is that the database engine is Postgres.

If we were interested, we could cut this down so this table is not populated when you're not using workers. (I'm not sure if we have such a flag available to be honest, but we can consider it if this is important to us!)

The benefit would be a small reduction in database I/O and CPU use for Postgres monoliths.

Related: #15868 which cleans up old rows in this table.

pjhfggij commented 6 months ago

is it safe to delete everything in this table to reclaim disk space?

psql -d synapse -c 'DELETE FROM cache_invalidation_stream_by_instance'
psql -d synapse -c 'VACUUM cache_invalidation_stream_by_instance;'

I've just done it, but the server appears to be losing connection after a few minutes. CPU goes to 100%.

After a few hours the servers has gone back to normal - I assume that matrix-synapse just had to rebuild this cache. I've managed to reclaim disk space this way and the table size in the end changed from 4GB to 1GB. So I guess this works?

Any other ideas how to reclaim space from the database would be very appreciated.