Home / Alt manpages / doveadm-index(1)

  • doveadm-index(1)
  • User command
  • linux

Index Dovecot Mailboxes Safely with doveadm index

Search in a Dovecot mailbox is missing recent mail, and doveadm index is how you make the index catch up. You will index one mailbox, optionally feed the full-text search data, and choose between immediate and queued work. Allow about fifteen minutes for one mailbox, longer for a busy or large account.

The examples match the installed dovecot-core package, version 2.3.21+dfsg1-2ubuntu6.5, and its Dovecot v2.3 manpage.

  • What you need: shell access to the Dovecot host and a mailbox that already exists.
  • Privileges: most examples need an administrator account, because they inspect another user's mail.

Warning

Do not run a broad indexing command during a maintenance-sensitive period. Indexing consumes storage and I/O, and it can make full-text search backends busy.

1. Check the installed command

Read the local command help before copying an example. This is an ordinary, read-only check:

$ doveadm help index
DOVEADM-INDEX(1)                    Dovecot                   DOVEADM-INDEX(1)

NAME
       doveadm-index - Index mailboxes

SYNOPSIS
       doveadm [-Dv] index [-S socket_path] [-q] [-n max_recent] mailbox

Record the package and version separately:

$ dpkg-query -W -f='${Package} ${Version}\n' dovecot-core
dovecot-core 1:2.3.21+dfsg1-2ubuntu6.5

Checkpoint

The local synopsis should include the option you plan to use. This guide follows the installed v2.3 command. A newer Dovecot release can add options, so do not copy a current online synopsis over the local one without checking the host.

2. Index one user's mailbox

The safest useful start is one named user and one mailbox. Replace both placeholders with real values:

$ sudo doveadm index -u '[email protected]' INBOX

-u selects the user and the final argument is the mailbox name. The command adds unindexed messages to the mailbox's index and cache files. If full-text search is enabled, it also adds the missing messages to the FTS database.

A successful run normally has no friendly summary to print. Check the exit status straight away if you need a machine-readable result:

$ sudo doveadm index -u '[email protected]' INBOX
$ printf 'exit status: %s\n' "$?"
exit status: 0

Tip

Exit status 0 means doveadm completed the request, not that every message now has every possible cached field. Dovecot only caches fields already in the mailbox's caching decisions, so a mailbox no client has accessed may gain less cache data than you expect.

3. Queue production work

Use -q when you want the indexer process to do the work instead of the current doveadm process:

$ sudo doveadm index -u '[email protected]' -q INBOX
$ printf 'exit status: %s\n' "$?"
exit status: 0

Queued work can return before the mailbox has finished indexing. Status 0 confirms the request was accepted, not that the queue has drained. The v2.3 manpage says -q should usually be used on production, because some backends, including fts-lucene, cannot safely handle multiple processes updating indexes at once.

  • One-off test on a quiet mailbox: omit -q so the command runs directly.
  • Production repair or large mailbox: schedule the queued operation and watch the host's normal Dovecot indexer and service logs.
  • No progress printed: do not add a second parallel indexing job just because the first command was quiet.

4. Limit work for mailboxes with many recent messages

-n max_recent is a skip threshold, not a batch size. If a mailbox holds more than that number of messages with the IMAP \Recent flag, Dovecot does not index it:

$ sudo doveadm index -u '[email protected]' -n 100 INBOX

That can save time on a large mailbox nobody has opened yet. It also means a successful command does not prove indexing happened: the mailbox may have exceeded the threshold and been left alone. Leave out -n when you need the mailbox indexed whatever its recent-message count.

Checkpoint

If you use -n, write the threshold into the maintenance record. Otherwise a later operator may mistake an intentional skip for a broken indexer.

5. Target several users carefully

Use -F with a file holding one username per line when you have an explicit, reviewed target list:

$ sudo install -m 600 /dev/null /tmp/dovecot-users.txt
$ sudo sh -c 'printf "%s\n" "[email protected]" "[email protected]" > /tmp/dovecot-users.txt
$ sudo doveadm index -F /tmp/dovecot-users.txt -q INBOX

The file is read as usernames, not mailbox names. Review it before running the command. Remove it after the maintenance window, because it contains account identifiers:

$ sudo sed -n '1,20p' /tmp/dovecot-users.txt
$ sudo rm -- /tmp/dovecot-users.txt

Recovery

There is no undo command for indexing, and removing an index file by hand is not a recovery procedure. It can cause extra work, lose useful cache state, or make a busy service less stable. If the wrong users were selected, stop issuing new jobs, keep the mail data intact, and let the queued work finish or ask the Dovecot administrator to cancel it through the site's normal operational procedure.

Warning

-A takes the users from the user database and indexes the named mailbox for all of them, so treat it as a high-impact operation. With a passwd user database it can include system users below Dovecot's first_valid_uid. With SQL or LDAP, the iteration settings must match the database or directory schema. Prefer a reviewed -F file when the target set is not truly every user.

6. Understand FTS and cache limits

doveadm index does not turn on full-text search. It only feeds unindexed messages into an FTS database when an FTS plugin is configured. For automatic indexing during delivery and other message additions, the local manpage documents this setting in /etc/dovecot/conf.d/90-plugin.conf:

plugin {
  fts_autoindex = yes
}

Warning

Changing that configuration is a separate, service-affecting task. Back up the current configuration, follow the host's normal validation and reload process, and make a rollback plan before enabling it. This guide only runs the existing index command.

Tip

To find out why a mailbox did not gain the cached fields you expected, inspect its current caching decisions with doveadm dump. That is diagnostic work, so do not edit the generated index or cache files by hand.

7. Diagnose a failed request

Start with the narrowest command and add verbosity only when needed:

$ sudo doveadm -v index -u '[email protected]' -q INBOX
$ printf 'exit status: %s\n' "$?"
exit status: 0
  • -v and -D. -v enables verbosity and a progress counter. -D adds debug messages.
  • User or mailbox not found. Check the spelling, user database, namespace and mailbox name before trying a wider target.
  • Remote doveadm service. -S can select an absolute UNIX socket or a hostname:port endpoint. Use the endpoint the Dovecot administrator has documented, and treat remote access as security-sensitive.

Warning

If you omit -u, -A and -F, the command runs with the environment of the currently logged-in user. A command that looks like it targets the administrator's account may actually operate on the shell user's mailbox. Make the user selection explicit in scripts and maintenance notes.

Done means

  • Command checked. You confirmed the installed Dovecot package version and the local doveadm index syntax.
  • Small first. You picked one known user and mailbox before considering a wider scope.
  • Mode chosen. You picked direct or queued execution deliberately and recorded the exit status.
  • -n understood. It can skip a mailbox and is not a batch-size limit.
  • User list handled. Any -F file was reviewed, protected temporarily and removed afterwards.
  • Hands off. You did not edit index files, change FTS configuration or assume indexing has an undo.