mirror of
https://git.yandere.love/skylar/pleromer-stuff.git
synced 2025-08-07 21:29:20 +00:00
add database prune sql script
This commit is contained in:
39
database_prune.sql
Normal file
39
database_prune.sql
Normal file
@ -0,0 +1,39 @@
|
||||
\c pleroma
|
||||
do $$
|
||||
declare
|
||||
maxA integer := (SELECT count(*) from activities WHERE inserted_at < now() - interval '4 months');
|
||||
maxO integer := (SELECT count(*) from objects WHERE inserted_at < now() - interval '4 months');
|
||||
maxN integer := (SELECT count(*) from notifications WHERE inserted_at < now() - interval '4 months');
|
||||
counter integer := 0;
|
||||
begin
|
||||
RAISE NOTICE 'Marked for deletion: % activities', maxA;
|
||||
while counter < maxA loop
|
||||
DELETE FROM activities WHERE id = any (array(SELECT id FROM activities WHERE inserted_at < now() - interval '4 months' LIMIT 1000));
|
||||
COMMIT;
|
||||
PERFORM pg_sleep(3);
|
||||
counter := counter + 1000;
|
||||
end loop;
|
||||
RAISE NOTICE 'Marked for deletion: % objects', maxO;
|
||||
counter := 0;
|
||||
while counter < maxO loop
|
||||
DELETE FROM deliveries WHERE object_id = any (array(SELECT id FROM objects WHERE inserted_at < now() - interval '4 months' LIMIT 10000));
|
||||
COMMIT;
|
||||
PERFORM pg_sleep(3);
|
||||
counter := counter + 1000;
|
||||
end loop;
|
||||
counter := 0;
|
||||
while counter < maxO loop
|
||||
DELETE FROM objects WHERE id = any (array(SELECT id FROM objects WHERE inserted_at < now() - interval '4 months' LIMIT 1000));
|
||||
COMMIT;
|
||||
PERFORM pg_sleep(3);
|
||||
counter := counter + 1000;
|
||||
end loop;
|
||||
RAISE NOTICE 'Marked for deletion: % notifications', maxN;
|
||||
counter := 0;
|
||||
while counter < maxO loop
|
||||
DELETE FROM notifications WHERE id = any (array(SELECT id FROM notifications WHERE inserted_at < now() - interval '4 months' LIMIT 1000));
|
||||
COMMIT;
|
||||
PERFORM pg_sleep(3);
|
||||
counter := counter + 1000;
|
||||
end loop;
|
||||
end$$;
|
Reference in New Issue
Block a user