From eb0f634040bc8e9419cbe2b83a564e81cbc07175 Mon Sep 17 00:00:00 2001 From: skylar Date: Thu, 20 Jun 2024 20:37:56 -0500 Subject: [PATCH] add delete info --- deletes.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 deletes.md diff --git a/deletes.md b/deletes.md new file mode 100644 index 0000000..6001589 --- /dev/null +++ b/deletes.md @@ -0,0 +1,54 @@ +Deletes are the danger zone, deleting activities from the table can and will introduce weird problems. For example, when a new activity federates in referencing a deleted activity, it'll cause notifications to temporarily break for the affected user(s). Pleroma will look in the table for the activity it's referencing, that'll time out, and the request to load notifications into pleroma-fe will 502 and they'll just be blank. + +But if it's a choice between killing the instance entirely due to storage constraints or deleting activities and accepting the risk of errors, we can delete them. Before you delete anything, take a look at how to clean up pg_repack remnants [here](https://git.yandere.love/skylar/pleromer-stuff/src/branch/main/repack.md). + +You can check the size of each table and get an idea of your worst offenders with this pgsql command: + +``` +SELECT + relname as table_name, + pg_size_pretty(pg_total_relation_size(relid)) As "Total Size", + pg_size_pretty(pg_indexes_size(relid)) as "Index Size", + pg_size_pretty(pg_relation_size(relid)) as "Actual Size" + FROM pg_catalog.pg_statio_user_tables +ORDER BY pg_total_relation_size(relid) DESC; +``` + +Since there's a LOT of stuff to delete, we don't want to do it all at once and piss off pgsql. Here's an example pgsql script to delete all activities, both local and remote, older than 2024-01-01: + +``` +do $$ +declare +counter integer := 0; +begin +while counter < 1000000 loop +DELETE FROM activities WHERE id = any (array(SELECT id FROM activities WHERE inserted_at < '2024-01-01' LIMIT 100)); +COMMIT; +PERFORM pg_sleep(2); +counter := counter + 1; +end loop; +end$$; +``` + +It will occasionally fail when something weird happens, but you can just run it again until you get no results from: + +``` +SELECT count(*) FROM activities WHERE inserted_at < '2024-01-01'; +``` + +The objects table is a little different and requires coordination with the deliveries table. + +``` +do $$ +declare +counter integer := 0; +begin +while counter < 1000000 loop +DELETE FROM deliveries WHERE object_id = any (array(SELECT id FROM objects WHERE inserted_at < '2024-01-01' LIMIT 1)); +DELETE FROM objects WHERE id = any (array(SELECT id FROM objects WHERE inserted_at < '2024-01-01' LIMIT 1)); +COMMIT; +PERFORM pg_sleep(2); +counter := counter + 1; +end loop; +end$$; +```