Repair and Maintain Dovecot FTS Indexes with doveadm fts
Search in webmail has gone quiet, and doveadm fts is the command that tells your Dovecot full text index to tidy itself or start again. You will optimise an index, rescan it against the mailboxes, and run consistency checks where your build supports them.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes, a little longer for a large mailbox set. The examples match Dovecot Core 1:2.3.21+dfsg1-2ubuntu6.5 and its installed doveadm-fts(1) manual page.
- What you need: shell access to the Dovecot host, a working Dovecot configuration and an FTS backend that is already set up.
- Privileges: read-only inspection is ordinary user work. Index maintenance normally needs the Dovecot administration account or
sudo, depending on how the service is configured. - Consistency checks: these need the Dovecot Pro command set, so they may not exist on your host.
1. Check the installed command and feature set
Start with the local help page. This does not alter mail, indexes or service state:
$ doveadm help fts
DOVEADM-FTS(1) Dovecot DOVEADM-FTS(1)
NAME
doveadm-fts - Manipulate the Full Text Search (FTS) index
COMMANDS
fts optimize
fts rescan
fts check fast
fts check full
That output is shortened to show the command family. The installed help also describes the global options, targets and exit codes. Confirm the package version separately:
$ dpkg-query -W -f='${Package} ${Version}\n' dovecot-core
dovecot-core 1:2.3.21+dfsg1-2ubuntu6.5
Tip
Do not use an option list remembered from another Dovecot release. The manual page on this host is labelled Dovecot v2.3 and documents this syntax.
2. Pick the narrowest user target
Every maintenance command can take a namespace, but the user scope comes from one of -u, -A or -F. If you supply none, doveadm uses the environment of the currently logged-in user. That default is easy to miss, so make the target explicit for an administrative run:
# sudo doveadm fts optimize -u '[email protected]'
Replace the address with a real user from your user database. The quotes stop the shell interpreting characters in a more complicated username or mask. Wildcards such as *@example.org work with -u, but a broad mask still hits many accounts.
For a controlled batch, put one username per line in a file only the administrator can read, then pass it with -F:
# sudo doveadm fts optimize -F /root/fts-users.txt
Warning
-A gets all users by iterating the user database. The manual warns against it with the system passwd driver, because it can include system users below first_valid_uid. SQL and LDAP deployments also need working iteration settings. Check that scope before using -A.
Checkpoint
Write down the exact user or file you intend to target. Do not jump to -A just because it is shorter to type.
3. Optimise an existing FTS index
Use optimize to force index optimisation:
# sudo doveadm fts optimize -u '[email protected]'
The FTS engines optimise automatically, so this command is an enforcement point, not a routine requirement. It does not rebuild missing messages. Add a namespace only when you deliberately want one other than the user's private namespace:
# sudo doveadm fts optimize -u '[email protected]' shared
A successful command normally returns straight to the prompt. For progress or diagnostics, add -v (progress and verbosity) or -D (debug messages):
# sudo doveadm -v fts optimize -u '[email protected]'
# printf 'exit status: %s\n' "$?"
exit status: 0
Checkpoint
The status belongs to the command immediately before printf. Zero means this invocation completed. It does not prove that every mailbox is searchable.
4. Rescan after index and mailbox drift
Use rescan when the index may no longer match the mailboxes. It compares indexed mail with what exists, removes entries for already-expunged messages, and lets the next doveadm index pick up missing mail:
# sudo doveadm fts rescan -u '[email protected]'
Warning
This changes FTS index state and may be expensive. The installed manual says most FTS backends do not yet implement the comparison fully and instead delete all FTS indexes. A rescan can therefore mean later indexing work and a period of reduced search coverage. Schedule it away from busy periods, and confirm the mailbox data itself is intact first.
Recovery
There is no general undo for a rescan. Let the configured backend rebuild its index, usually by running the normal indexing workflow after checking the backend documentation:
# sudo doveadm index -u '[email protected]' INBOX
That last command is a separate doveadm-index(1) operation, not part of doveadm fts. Substitute the mailbox or indexing scope that suits your deployment. Do not call it recovered until a search client or your FTS monitoring confirms messages are searchable again.
5. Run consistency checks if your build has them
fts check fast and fts check full exist only when the fts_dovecot plugin from Dovecot Pro FTS is loaded. Standard Dovecot Core installs do not have them. On a Core-only host, an unknown-command or plugin-related error tells you about capability, not about a failed index.
The fast check uses local cache information. Its statuses:
0means the mailbox is fully consistent.2means the mailbox is not fully consistent.68means local metacache information is insufficient. Retry with--refresh, or use the full check.
# sudo doveadm fts check fast -u '[email protected]' --print-mismatches-only
# printf 'exit status: %s\n' "$?"
exit status: 0
--print-mismatches-only trims the output to affected mailboxes. If status 68 comes back, the documented retry is:
# sudo doveadm fts check fast -u '[email protected]' --refresh
The full check gives more detail and can print IMAP UID numbers and FTS triplet names:
# sudo doveadm fts check full -u '[email protected]' --print-details
Full-check status 0 means consistent and status 2 means inconsistent. Treat any other failure as an operational error.
Warning
Do not use --refresh, optimise or rescan as a blind repair. Record the result and identify the affected user or namespace first.
6. Handle remote administration deliberately
The -S option selects a local UNIX socket by absolute path, or a remote TCP endpoint written as hostname:port:
# sudo doveadm -S /run/dovecot/admin fts optimize -u '[email protected]'
Replace the socket path with one that exists in your deployment. Check the socket's ownership, authentication and transport security first.
Security warning
A TCP socket exposes an administration interface. Do not send credentials or mailbox-control traffic over an untrusted network.
Done means
- Command checked. You confirmed the installed Dovecot package and the supported
doveadm ftscommands locally. - Scope chosen. The user, wildcard, file or all-user target was a deliberate decision.
- Optimise understood.
optimizeforced optimisation and was not treated as a promise to rebuild missing mail. - Rescan respected. You treated
rescanas a state-changing operation that may delete backend indexes. - Exit codes recorded. You noted check results, and did not assume Pro-only commands exist.
- Rebuild verified. Any rebuild after a rescan was confirmed with your normal indexing and search checks.