Euuh Houston, on a un problème. Ça vient de finir et la db fait exactement la même taille qu’avant.
synapse=# select pg_size_pretty(pg_database_size('synapse'));
pg_size_pretty
----------------
131 GB
(1 row)
synapse=# select schemaname as table_schema,
relname as table_name,
pg_size_pretty(pg_total_relation_size(relid)) as total_size,
pg_size_pretty(pg_relation_size(relid)) as data_size,
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid))
as external_size
from pg_catalog.pg_statio_user_tables
order by pg_total_relation_size(relid) desc,
pg_relation_size(relid) desc
limit 15;
table_schema | table_name | total_size | data_size | external_size
--------------+---------------------------------------+------------+-----------+---------------
public | state_groups_state | 99 GB | 59 GB | 40 GB
public | event_json | 8321 MB | 7086 MB | 1235 MB
public | events | 3517 MB | 1472 MB | 2046 MB
public | cache_invalidation_stream_by_instance | 2502 MB | 1790 MB | 712 MB
public | device_lists_changes_in_room | 2439 MB | 1139 MB | 1300 MB
public | event_edges | 2309 MB | 888 MB | 1421 MB
public | received_transactions | 1930 MB | 995 MB | 935 MB
public | event_auth | 1819 MB | 1222 MB | 597 MB
public | room_memberships | 1624 MB | 581 MB | 1044 MB
public | event_search | 1460 MB | 813 MB | 648 MB
public | event_to_state_groups | 847 MB | 396 MB | 451 MB
public | event_auth_chain_links | 745 MB | 443 MB | 302 MB
public | device_inbox | 707 MB | 607 MB | 100 MB
public | event_auth_chains | 684 MB | 287 MB | 397 MB
public | current_state_delta_stream | 624 MB | 551 MB | 74 MB
(15 rows)
synapse=# select count(*) from state_groups sg
left join event_to_state_groups esg on esg.state_group=sg.id
left join state_group_edges e on e.prev_state_group=sg.id
where esg.state_group is null and e.prev_state_group is null;
count
-------
37015
(1 row)
synapse=# SELECT
DISTINCT(state_groups.room_id) AS room_id_gone, COUNT(*) as count
FROM
state_groups
LEFT JOIN events USING(room_id)
WHERE
events.room_id IS NULL
GROUP BY
room_id_gone;
room_id_gone | count
---------------------------------+-------
!AGeUOyHpLMMrLYAkXW:matrix.org | 36
!CsFQYUPDhnAJICoKnh:matrix.org | 349
!HuhMGSUaJyvtuoVzTr:libera.chat | 2
!OGEhHVWSdvArJzumhm:matrix.org | 132
!PvQGNjiCNulFZsMPud:matrix.org | 56
!SayHlEYXdrpSerhLMC:matrix.org | 92
!hbPGQxyHEvFEncGQxE:f-droid.org | 2
!iuyQXswfjgxQMZGrfQ:matrix.org | 16
!kacSMbuIPxzQgVfRrc:libera.chat | 1
!wOlkWNmgkAZFxbTaqj:matrix.org | 8
!wZBTEAQUretzLfLJEN:matrix.org | 7
!yhqiEdqNjyPbxtUjzm:matrix.org | 3
(12 rows)
Total state groups: 529469
Found 55030 unreferenced groups
$ sudo psql synapse < delete-sgs.sql
[sudo] password for nicolas:
CREATE TABLE
COPY 55030
DELETE 253327253
DELETE 21503
DELETE 43490
select pg_size_pretty(pg_database_size('synapse'));
pg_size_pretty
----------------
131 GB
(1 row)
synapse=# select schemaname as table_schema,
relname as table_name,
pg_size_pretty(pg_total_relation_size(relid)) as total_size,
pg_size_pretty(pg_relation_size(relid)) as data_size,
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid))
as external_size
from pg_catalog.pg_statio_user_tables
order by pg_total_relation_size(relid) desc,
pg_relation_size(relid) desc
limit 15;
table_schema | table_name | total_size | data_size | external_size
--------------+---------------------------------------+------------+-----------+---------------
public | state_groups_state | 99 GB | 59 GB | 40 GB
public | event_json | 8321 MB | 7086 MB | 1235 MB
public | events | 3517 MB | 1472 MB | 2046 MB
public | cache_invalidation_stream_by_instance | 2502 MB | 1790 MB | 712 MB
public | device_lists_changes_in_room | 2439 MB | 1139 MB | 1300 MB
public | event_edges | 2309 MB | 888 MB | 1421 MB
public | received_transactions | 1930 MB | 995 MB | 935 MB
public | event_auth | 1819 MB | 1222 MB | 597 MB
public | room_memberships | 1624 MB | 581 MB | 1044 MB
public | event_search | 1460 MB | 813 MB | 648 MB
public | event_to_state_groups | 847 MB | 396 MB | 451 MB
public | event_auth_chain_links | 745 MB | 443 MB | 302 MB
public | device_inbox | 707 MB | 607 MB | 100 MB
public | event_auth_chains | 684 MB | 287 MB | 397 MB
public | current_state_delta_stream | 624 MB | 551 MB | 74 MB
(15 rows)
synapse=# select count(*) from state_groups sg
left join event_to_state_groups esg on esg.state_group=sg.id
left join state_group_edges e on e.prev_state_group=sg.id
where esg.state_group is null and e.prev_state_group is null;
count
-------
0
(1 row)
synapse=# SELECT
DISTINCT(state_groups.room_id) AS room_id_gone, COUNT(*) as count
FROM
state_groups
LEFT JOIN events USING(room_id)
WHERE
events.room_id IS NULL
GROUP BY
room_id_gone;
room_id_gone | count
--------------+-------
(0 rows)
Bon c’est peut-être parce qu’il est encore en train de autovacuum, attendons…