pleroma.database fill_old_hashtags: Add month_limit argument
[akkoma] / docs / administration / CLI_tasks / database.md
1 # Database maintenance tasks
2
3 {! backend/administration/CLI_tasks/general_cli_task_info.include !}
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 === "OTP"
13
14 ```sh
15 ./bin/pleroma_ctl database remove_embedded_objects [option ...]
16 ```
17
18 === "From Source"
19
20 ```sh
21 mix pleroma.database remove_embedded_objects [option ...]
22 ```
23
24
25 ### Options
26 - `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references
27
28 ## Prune old remote posts from the database
29
30 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.
31
32 !!! danger
33 The disk space will only be reclaimed after `VACUUM FULL`. You may run out of disk space during the execution of the task or vacuuming if you don't have about 1/3rds of the database size free.
34
35 === "OTP"
36
37 ```sh
38 ./bin/pleroma_ctl database prune_objects [option ...]
39 ```
40
41 === "From Source"
42
43 ```sh
44 mix pleroma.database prune_objects [option ...]
45 ```
46
47 ### Options
48 - `--vacuum` - run `VACUUM FULL` after the objects are pruned
49
50 ## Create a conversation for all existing DMs
51
52 Can be safely re-run
53
54 === "OTP"
55
56 ```sh
57 ./bin/pleroma_ctl database bump_all_conversations
58 ```
59
60 === "From Source"
61
62 ```sh
63 mix pleroma.database bump_all_conversations
64 ```
65
66 ## Remove duplicated items from following and update followers count for all users
67
68 === "OTP"
69
70 ```sh
71 ./bin/pleroma_ctl database update_users_following_followers_counts
72 ```
73
74 === "From Source"
75
76 ```sh
77 mix pleroma.database update_users_following_followers_counts
78 ```
79
80 ## Fix the pre-existing "likes" collections for all objects
81
82 === "OTP"
83
84 ```sh
85 ./bin/pleroma_ctl database fix_likes_collections
86 ```
87
88 === "From Source"
89
90 ```sh
91 mix pleroma.database fix_likes_collections
92 ```
93
94 ## Fill hashtags for old objects
95
96 Migrate hashags fields for old objects, from now to `months_limit` months.
97
98 ```sh tab="OTP"
99 ./bin/pleroma_ctl database fill_old_hashtags <months_limit>
100 ```
101
102 ```sh tab="From Source"
103 mix pleroma.database fill_old_hashtags <months_limit>
104 ```
105
106 ## Vacuum the database
107
108 ### Analyze
109
110 Running an `analyze` vacuum job can improve performance by updating statistics used by the query planner. **It is safe to cancel this.**
111
112 === "OTP"
113
114 ```sh
115 ./bin/pleroma_ctl database vacuum analyze
116 ```
117
118 === "From Source"
119
120 ```sh
121 mix pleroma.database vacuum analyze
122 ```
123
124 ### Full
125
126 Running a `full` vacuum job rebuilds your entire database by reading all of the data and rewriting it into smaller
127 and more compact files with an optimized layout. This process will take a long time and use additional disk space as
128 it builds the files side-by-side the existing database files. It can make your database faster and use less disk space,
129 but should only be run if necessary. **It is safe to cancel this.**
130
131 === "OTP"
132
133 ```sh
134 ./bin/pleroma_ctl database vacuum full
135 ```
136
137 === "From Source"
138
139 ```sh
140 mix pleroma.database vacuum full
141 ```
142
143 ## Add expiration to all local statuses
144
145 === "OTP"
146
147 ```sh
148 ./bin/pleroma_ctl database ensure_expiration
149 ```
150
151 === "From Source"
152
153 ```sh
154 mix pleroma.database ensure_expiration
155 ```