Deleting and purging an index on a Synology DiskStation NAS

I was trying to set up my Synology DiskStation (DSM 6.2.3 as of writing) as a media player. I was happy to discover that there is a built in application for the DiskStation you can load up from the Package Centre called “Audio Station”, with matching apps on the Android and iPhone. I installed it, created a new account with read-only file access to my music files in a particular directory, and only application access to the Audio Station applicaiton.

All looked great until the Indexer started trawling the entire disk volume. This means that all sorts of things that were just audio files were now listed as music tracks, and if you have the same track in multiple formats, suddenly you have 2 copies of the same track in the app. As you can imagine, this makes playlists and shuffles really annoying to say the least.

So I went in to the “Indexing Service” on the control panel, and after trying multiple combinations of renaming, changing settings, deleting directories from the index and selecting where I wanted indexed, it became clear that the NAS doesn’t like removing things from the index, at least not with the amount of time I was willing to wait. I will also note at this point that searching for help on removing references from the index is problematic at best- there are a few articles on the index retaining deleted files or moved files at both locations.

At this point I left the indexer settings at my desired result – one specific directory tree on one volume for audio files only.

Next step? Dropping the old database seemed the way to go. This wasn’t easy, and I’m writing this to remind myself of what I had to do, in case I need to do similar for the file or photo applications, or simply need to reset the index again.

Note that each version of the DSM is different in how to achieve the outcome, so these are the next steps I followed.

First you need to stop applications using the index database. I stopped the “Audio Station” application by going into the “Package Centre” and selecting the application, then chosing “Stop” from the dropdown.

Next challenge was stopping the Indexe, which I did from a secure shell promptr:

super@DSM:/$ sudo synoservice -stop synoindexd
some service depend on service [synoindexd] is still running, use --hard-stop to stop all releated service
super@DSM:/$ sudo synoservice --hard-stop synoindexd
warn: The runkey of service [synoindexd] and its dependency services have been set to "No"

Then I needed to drop the database. The synoindex tool has a lot of features, but they seem to resemble what’s in the web GUI except there’s no help listing which directories have been indexed, so you can’t work out what to delete.

ssh super@DSM
super@DSM's password:
Could not chdir to home directory /var/services/homes/super: No such file or directory
super@DSM:/$ synoindex
synoindex [OPTIONS]
Index Options:
-h, --help
this help text
-A dirpath
add a dir
-a filepath
add a file
-D dirpath
delete a dir
-d filepath
delete a file
-N new_dirpath old_dirpath
rename a dir
-n new_filepath old_filepath
rename a file
-R [all|media|photo|music|video|thumb|dirpath]
all: reindex all dirpath that registered in each package
media: reindex dirpath that registered in MediaIndex package
photo: reindex photo dirpath
music: reindex music dirpath
video: reindex video dirpath
thumb: check converted video of each video file
dirpath: reindex this specific dirpath
-R user:{user_name}
reindex personal photo dirpath
-R share:{share_name}
reindex share dirpath
-R [type_music|type_video|type_photo]
reindex dirpath that registered with specific type in MediaIndex
Package Index Options:
-P [MediaIndex|{package_name}] {index_option}
index operation only apply on this package
-p [MediaIndex|{package_name}] {index_option}
index operation apply all packages except for this package
File Index Options:
-f {index_option}
index operation apply on file index
-U photo
update photo images

So I tried to login as the database as the database user: postgres. Unfortunately I didn’t have a password for that account, and I couldn’t su postgres without the password. So I did the following workaround:

super@DSM:/$ sudo /bin/bash
bash-4.3# su -s /bin/bash postgres
bash-4.3$ whoami

If you fail to stop the indexer first, trying to drop the database results in the following:

bash-4.3$ dropdb mediaserver
dropdb: database removal failed: ERROR: database "mediaserver" is being accessed by other users
DETAIL: There is 1 other session using the database.

It does work perfectly though if the indexer is stopped. For reference, at some point I also did this, but it didn’t help:

super@DSM:/$ sudo synoservice -start synoindexd
super@DSM:/$ synoindex -R all

What was the last step? Rebooting the DSM. It took a while, but eventually the indexer recreated the database, the database started rebuilding and even though the Audio Station failed the first few times, suggesting the DSM was having issues, however with enough time the Audio Station behaved perfectly as expected. The correct directory became indexed, the information on the “Indexing Service” now referred to the correct application having access to the index, and the status was also updated correctly. It also took a bit longer for the Android app to work as expected, but eventually it allowed me to use the music from anywhere.

Leave a Reply

Your email address will not be published.