Merge branch 'develop' into feature/admin-api-list-statuses-for-a-given-instance
[akkoma] / docs / administration / CLI_tasks / database.md
1 # Database maintenance tasks
2
3 Every command should be ran with a prefix, in case of OTP releases it is `./bin/pleroma_ctl database` and in case of source installs it's `mix pleroma.database`.
4
5 !!! danger
6 These mix tasks can take a long time to complete. Many of them were written to address specific database issues that happened because of bugs in migrations or other specific scenarios. Do not run these tasks "just in case" if everything is fine your instance.
7
8 ## Replace embedded objects with their references
9
10 Replaces embedded objects with references to them in the `objects` table. Only needs to be ran once if the instance was created before Pleroma 1.0.5. The reason why this is not a migration is because it could significantly increase the database size after being ran, however after this `VACUUM FULL` will be able to reclaim about 20% (really depends on what is in the database, your mileage may vary) of the db size before the migration.
11
12 ```sh
13 $PREFIX remove_embedded_objects [<options>]
14 ```
15
16 ### Options
17 - `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references
18
19 ## Prune old remote posts from the database
20
21 This will prune remote posts older than 90 days (configurable with [`config :pleroma, :instance, remote_post_retention_days`](../../configuration/cheatsheet.md#instance)) from the database, they will be refetched from source when accessed.
22
23 !!! note
24 The disk space will only be reclaimed after `VACUUM FULL`
25
26 ```sh
27 $PREFIX pleroma.database prune_objects [<options>]
28 ```
29
30 ### Options
31 - `--vacuum` - run `VACUUM FULL` after the objects are pruned
32
33 ## Create a conversation for all existing DMs
34
35 Can be safely re-run
36
37 ```sh
38 $PREFIX bump_all_conversations
39 ```
40
41 ## Remove duplicated items from following and update followers count for all users
42
43 ```sh
44 $PREFIX update_users_following_followers_counts
45 ```
46
47 ## Fix the pre-existing "likes" collections for all objects
48
49 ```sh
50 $PREFIX fix_likes_collections
51 ```