First easy SQL queries for analyze database stats
parent
b85768da1c
commit
42859fafa0
|
@ -0,0 +1,76 @@
|
||||||
|
## Show top 20 larger rooms by state events count
|
||||||
|
```
|
||||||
|
SELECT r.name, s.room_id, s.state_events
|
||||||
|
FROM room_stats s
|
||||||
|
LEFT JOIN room_names r USING (room_id)
|
||||||
|
ORDER BY ts DESC, state_events DESC
|
||||||
|
LIMIT 20;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Show top 20 larger tables by row count
|
||||||
|
```
|
||||||
|
SELECT relname, n_live_tup as rows
|
||||||
|
FROM pg_stat_user_tables
|
||||||
|
ORDER BY n_live_tup DESC
|
||||||
|
LIMIT 20;
|
||||||
|
```
|
||||||
|
### Result example:
|
||||||
|
```
|
||||||
|
state_groups_state - 161687170
|
||||||
|
event_auth - 8584785
|
||||||
|
event_edges - 6995633
|
||||||
|
event_json - 6585916
|
||||||
|
event_reference_hashes - 6580990
|
||||||
|
events - 6578879
|
||||||
|
received_transactions - 5713989
|
||||||
|
event_to_state_groups - 4873377
|
||||||
|
stream_ordering_to_exterm - 4136285
|
||||||
|
current_state_delta_stream - 3770972
|
||||||
|
event_search - 3670521
|
||||||
|
state_events - 2845082
|
||||||
|
room_memberships - 2785854
|
||||||
|
cache_invalidation_stream - 2448218
|
||||||
|
state_groups - 1255467
|
||||||
|
state_group_edges - 1229849
|
||||||
|
current_state_events - 1222905
|
||||||
|
users_in_public_rooms - 364059
|
||||||
|
device_lists_stream - 326903
|
||||||
|
user_directory_search - 316433
|
||||||
|
```
|
||||||
|
## Show top 20 larger tables by storage size
|
||||||
|
```
|
||||||
|
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;
|
||||||
|
```
|
||||||
|
### Result example:
|
||||||
|
```
|
||||||
|
public.state_groups_state - 27 GB
|
||||||
|
public.event_json - 9855 MB
|
||||||
|
public.events - 3675 MB
|
||||||
|
public.event_edges - 3404 MB
|
||||||
|
public.received_transactions - 2745 MB
|
||||||
|
public.event_reference_hashes - 1864 MB
|
||||||
|
public.event_auth - 1775 MB
|
||||||
|
public.stream_ordering_to_exterm - 1663 MB
|
||||||
|
public.event_search - 1370 MB
|
||||||
|
public.room_memberships - 1050 MB
|
||||||
|
public.event_to_state_groups - 948 MB
|
||||||
|
public.current_state_delta_stream - 711 MB
|
||||||
|
public.state_events - 611 MB
|
||||||
|
public.presence_stream - 530 MB
|
||||||
|
public.current_state_events - 525 MB
|
||||||
|
public.cache_invalidation_stream - 466 MB
|
||||||
|
public.receipts_linearized - 279 MB
|
||||||
|
public.state_groups - 160 MB
|
||||||
|
public.device_lists_remote_cache - 124 MB
|
||||||
|
public.state_group_edges - 122 MB
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue