17

Config: Late-2013 rMBP running 10.12 (16A323)

Issue: Spotlight appears to be mostly non-functional since upgrading to Sierra. I originally noticed it when searches failed to bring up anything in Mail, and Spotlight itself will only surface results from Dictionary.

What I've Tried:

  1. Add my primary HDD to the Privacy exclusion list in Spotlight preferences (this resulted in a weird (null) error). The idea is adding, then removing will force a reindex.
  2. Run mdutil -sv / to find out what's up, resulting in "Error: unexpected indexing state. kMDConfigSearchLevelTransitioning".
  3. Run sudo mdutil -E / to delete and rebuild the index, resulting in "Error: Index is already changing state. Please try again in a moment."
  4. Run
    sudo su
    launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
    rm -R ./Spotlight-V100/
    launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
    mdutil -E /
    this all works, and I get a brief pause after the last command before it spits out "Indexing enabled." Subsequent attempts at running mdutil -sv / spits out the aforementioned error as cited in #2 above.

Activity Monitor is showing that mds and several mdworker processes are churning most of the CPU cycles (and the fan is fairly vocal), which would imply that it's in the process of reindexing - yet the two ways I'm aware of confirming indexing behavior is not indicating that's the case:

  1. mdutil -sv / is returning that error.
  2. Doing a Spotlight search for anything (or "indexing" specifically) does not show any indexing progress bar.

So… is Spotlight either:

A. Actually indexing, despite both known ways of confirmation indicating it isn't? And, if so, citation(s) on that being the case / when can I expect it to be showing that it is indexing?

B. Actually borked? And, if so, any other ways I can try to resolve absent nuking the partition, doing a fresh install, and restoring from Time Machine?

Thanks in advance!

Tetsujin
  • 115,663
Brian M.
  • 503

2 Answers2

10

Did you reboot after #4 above? I think that should work... If not this may help:

sudo touch /.metadata-never-index

Reboot...

sudo rm /.Spotlight-V100/VolumeConfiguration.plist
sudo rm /.metadata-never-index

And reboot again. You can try this for every volume.

See also: http://www.filetypehelp.com/purpose-files-metadataneverindex-file-extension/

MacManager
  • 1,704
  • I was ~89% sure I had rebooted after doing #4 at least once, so I did it again and no change. Tried your alternative, but still getting the “unexpected indexing state” error when running sudo mdutil -sv / after the second reboot. – Brian M. Sep 22 '16 at 23:29
  • 2
    Drat... What if you try sudo pkill -9 mds – MacManager Sep 22 '16 at 23:44
  • Running the pkill then checking the status using mdutil results once again with “Indexing enabled.” Spotlight search for “a” does yield a couple things in addition to the Dictionary meaning, but absolutely nothing comes up when searching in Mail. Running mdutil -sv / a second time brings back the error - and subsequent Spotlight searches goes back to only yielding Dictionary results. So it does appear that when mds is active is causing this “unexpected indexing state” and preventing any results outside of Dictionary entries. – Brian M. Sep 22 '16 at 23:57
  • Hmmm... Other than killing it again and letting it index for a while (overnight?) I'm not sure what to try next. Sorry. – MacManager Sep 23 '16 at 00:13
  • Well, I’m not sure what good killing it again will do, as it auto-restarts. Since I’ve just recently done #4 complete with reboot, leaving it overnight and seeing if this is the new “this is how you know indexing is happening on Sierra” method might be the only option. Hopefully that’s it or someone else has the silver bullet as I really don’t want to clean install and restore from Time Machine… Thanks for the help @MacManager! – Brian M. Sep 23 '16 at 00:29
  • Following up: Left it alone overnight and Spotlight is still basically non-functional. The mds process is active, but consuming no CPU cycles and mdutil -sv / is still reporting an “unexpected indexing state”. So unless there are any other ideas out there, it looks like I’ve got some exciting weekend plans involving a clean install and restore (I know you’re all jealous!). – Brian M. Sep 23 '16 at 15:10
  • Since upgrading to Sierra i too have had mds and mds_stores taking up 100%+ CPU for almost a week now. I imagine Spotlight is working its way into my iCloud Photos and trying to index them and meta-data as well, but cannot confirm. I've tried most of the above mentioned suggestions, but mds/mds_stores always comes back (auto-restart). photolibraryd is also at the top of the cpu usage list, as well. mds and it swap places throughout the day. – Carl Sep 23 '16 at 22:54
  • Thanks for the data point @Carl; I don't really have anything of significance on iCloud, so I don't think that's the issue for me (unless mds is getting hung up on what little data is on there). Are you having any issues with Spotlight searches at all? – Brian M. Sep 24 '16 at 11:45
  • I don't usually use Spotlight search (I use Alfred), but it seems to be working once I enabled Spotlight to index a few items in system preference. I had unchecked all items previously, but adding a few back in (apps, docs, etc) allowed it to work when I opened up a Spotlight search. At this moment, photolibraryd is 93% CPU and mds* is < 1%, fyi. – Carl Sep 24 '16 at 16:33
  • I should also note that I have 40,000+ photos in iCloud and I recently (as of 2-3weeks ago) turned iCloud photos back on after using Google Photos for almost a year. So there could be some "catching-up" that iCloud+Photos are doing, but I don't think that means this situation (100-200% CPU) is "fine". It's hard to get work done when the machine is unresponsive most of the day, for days on end. I may end up backing up and starting over with a clean install of Sierra. – Carl Sep 24 '16 at 16:41
  • 4
    sudo pkill -9 mds solved it for me! You should add it to your answer. – Brian McCutchon Sep 19 '17 at 05:40
  • sudo pkill -9 mds also worked for me! At least it allowed me to run sudo mdutil -E / to reindex spotlight without getting error. – AnthoPak Jul 03 '19 at 09:14
  • sudo pkill -9 mds also worked for me, turning mdutil on and off again brought search in Mail back to life. No idea why that happened to me, since I have been running Mojave ever since I bought my MBA in late 2019, but I guess, shot happens... – yogibimbi Feb 27 '21 at 23:48
2

After leaving my Mac alone for the weekend, my fears were confirmed and there was never any change to this Spotlight issue. Given the other threads here and elsewhere, it appears that Sierra has some challenges when doing an in-place upgrade.

Resolution:

  1. Confirm you are fully backed up (multiple backups preferred). THIS IS THE MOST IMPORTANT STEP!
  2. Reboot into Recovery Mode (hold down Command-R while Mac begins to boot).
  3. Open "Disk Utility" and erase the macOS partition (You did confirm those backup(s), right?).
  4. Once HD is erased, exit out of "Disk Utility", open "Install macOS Sierra" and install Sierra from scratch.
  5. After install completes, restore from backup.
  6. Get back to your life. ;-)
Brian M.
  • 503
  • Did reinstalling and restoring from backup fix your spotlight search issues? – muhan Nov 21 '16 at 06:48
  • When you say restore from backup, do you mean a time machine backup? Wouldn't that kind of restore also bring back the spotlight problems? – muhan Nov 21 '16 at 06:58
  • @muhan As noted in this answer that I accepted, restoring from back up did resolve the issue. And to clarify, yes, it was a Time Machine backup that I used. – Brian M. Nov 21 '16 at 14:40
  • Did you try installing Sierra without erasing the partition first? – Adam Rice Jan 18 '17 at 19:56
  • @AdamRice No, I did not. This was my main machine and I didn't have the further patience to do that. There's obviously no way now to know, but I'm not inclined to think that just doing the install over again the corrupted instance would've made a difference. – Brian M. Jan 18 '17 at 20:39
  • What worked for me was: sudo mdutil -i off /;sudo mdutil -i on /; sudo mdutil -E / – Jacob White Nov 18 '17 at 23:45
  • Seems a bit drastic to reformat. Deleted the index files will surely solve this. – eWhizz Sep 08 '21 at 00:53
  • @eWhizz, I would completely agree with you – but as noted in the original question (and subsequent comments), I couldn't delete the index as every time I tried killing the process to do so it would immediately restart. Others had luck in killing the process, but whatever possessed my old laptop was not letting go. Hence nuking it from orbit and restoring from backup. Of all the commentary since originally solving it that I didn't try was Jacob White's 3-step sudo mdutil process. Maybe that would've worked? – Brian M. Sep 09 '21 at 03:42
  • Deleting the index files and then letting it complete the process to rebuild them would have worked. Starting up in Single-User mode (or another drive, or the Recovery environment) to delete the index files may have been necessary. – eWhizz Jun 11 '22 at 01:45