c53c4992118796d5dd696ae4c805303e5c4be769
[anni] / 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 ## Vacuum the database
95
96 ### Analyze
97
98 Running an `analyze` vacuum job can improve performance by updating statistics used by the query planner. **It is safe to cancel this.**
99
100 === "OTP"
101
102     ```sh
103     ./bin/pleroma_ctl database vacuum analyze
104     ```
105
106 === "From Source"
107
108     ```sh
109     mix pleroma.database vacuum analyze
110     ```
111
112 ### Full
113
114 Running a `full` vacuum job rebuilds your entire database by reading all of the data and rewriting it into smaller
115 and more compact files with an optimized layout. This process will take a long time and use additional disk space as
116 it builds the files side-by-side the existing database files. It can make your database faster and use less disk space,
117 but should only be run if necessary. **It is safe to cancel this.**
118
119 === "OTP"
120
121     ```sh
122     ./bin/pleroma_ctl database vacuum full
123     ```
124
125 === "From Source"
126
127     ```sh
128     mix pleroma.database vacuum full
129     ```
130
131 ## Add expiration to all local statuses
132
133 === "OTP"
134
135     ```sh
136     ./bin/pleroma_ctl database ensure_expiration
137     ```
138
139 === "From Source"
140
141     ```sh
142     mix pleroma.database ensure_expiration
143     ```
144
145 ## Change Text Search Configuration
146
147 Change `default_text_search_config` for database and (if necessary) text_search_config used in index, then rebuild index (it may take time). 
148
149 === "OTP"
150
151     ```sh
152     ./bin/pleroma_ctl database set_text_search_config english
153     ```
154
155 === "From Source"
156
157     ```sh
158     mix pleroma.database set_text_search_config english
159     ```
160
161 See [PostgreSQL documentation](https://www.postgresql.org/docs/current/textsearch-configuration.html) and `docs/configuration/howto_search_cjk.md` for more detail.