element-hq / element-hq/synapse
Allow using `pg_repack` on `state_groups_state` by adding a primary key or UNIQUE constraint
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#10308](https://github.com/matrix-org/synapse/issues/10308).
---
**Description:**
It would be nice if `pg_repack` could be used on the `state_groups_state` table, which often has quite a lot of bloat after purging rooms / history. `pg_repack` is similar to `VACUUM FULL` but it can be run online without taking an exclusive lock on the tables.
`pg_repack` has the following requirement on the table it is run against:
> Target table must have a PRIMARY KEY, or at least a UNIQUE total index on a NOT NULL column.
Currently the `state_groups_state` table does not have a primary key or UNIQUE NOT NULL keys. `event_id` seems like a great candidate for this, though I'm not sure if setting a TEXT value as primary key would have any performance implications.
EDIT: it seems that none of the columns in the table is actually unique. To allow the table to be used by pg_repack, we might need to add an auto-incrementing separate primary key.
Contributor guide
Assessment
This issue has not been assessed yet.