MDS taking up a ton of CPU time on OS X

After installing Snow Leopard I noticed that a process called mds was taking up a lot of processor time on my machine. A quick investigation revealed that this is the metadata server that Spotlight uses. Apparently the upgrade to 10.6 made this process go a lil’ wonky and it seemed like it was just constantly reindexing stuff.

Here’s the command that fixed this:

sudo mdutil -Eav

mdutil manages the metadata stores used by Spotlight. Here’s what the arguments mean:

-E  This flag will cause each local store for the volumes indicated to be erased.  The stores will be rebuilt if appropriate.

-a  Apply command to all volumes.

-v  Print verbose information when available.

So sudo mdutil -Eav will erase the current metadata for all drives, reindex them and tell you what it’s doing. Note that during the reindexing period the processor usage for mds can still be somewhat high but after it’s done you’ll be good to go.