Synlogy Diskstation Delete Universal Search Database by krischik

View this thread on steempeak.com
· @krischik · (edited)
$0.09
Synlogy Diskstation Delete Universal Search Database
**Universal Search** is one of the most resource intensive jobs that will ever run on a Synlogy Diskstation. A full index can easily take several weeks to complete and can make a [Diskstation with only 1GB of memory unusable](https://steempeak.com/nas/@krischik/synlogy-diskstation-416play-performance-fixed).

As **Synlogy Drive Sync**, **Synlogy Drive** and **Calendar** all depend on **Universal Search** often deinstalling the troublesome service isn't an option.

# Delay Index

If a Diskstation only got 1GB of memory it's best to delay the index forever and keep it that way until you add a memory upgrade:

![image.png](https://files.steempeak.com/file/steempeak/krischik/Fd7MDebD-image.png)

# Reindex

In addition to being resource hungry the **Universal Search** index is also prune to corruption. You can check the database for errors:

![image.png](https://files.steempeak.com/file/steempeak/krischik/pUlVn99a-image.png)

And if errors are found use the reindex function to fix them:

![image.png](https://files.steempeak.com/file/steempeak/krischik/35gBILGE-image.png)

It's also advisable to index only the filenames and to deactivate scanning file content:

![image.png](https://files.steempeak.com/file/steempeak/krischik/VdNrTjiP-image.png)

# Delete the Index Database

Sometimes even a reindex won't help and and a database delete is needed. One way to do this is deinstall **Universal Search**. For this you have to deinstall all services depending on **Universal Search** first. Which is quite cumbersome.

The other way is to delete the database using `psql` and `ssh`.

<TABLE>
  <TR>
    <TD>
        <P><IMG SRC="https://files.steempeak.com/file/steempeak/krischik/degwtEP5-warning.png"></P>
    </TD>
    <TD>
	<p><b>WARNING:</b> From this point onwards you need advanced Linux skills. If you don't know how to use <code>ssh</code>, <code>sudo</code> or <code>su</code> you should stop reading. I will take no responsibility if you brick your Diskstation.</p>
    </TD>
  </TR> 
</TABLE>

This following script will delete the «mediaserver» database. For this two user changes are needed:

1. First the script elevates itself to **root** privileges to stop and later start the search service. 
2. Then the script demotes itself to **postgres** privileges to delete the database.

Needless to say that a lot can go wrong here. Since you have advanced Linux skills you probably decided not to trust me and to execute every command separately. Just to be sure. I would do the same.

```sh
#!/bin/bash

# get the real name of the currently running script
#
Script="$(readlink -f ${0})"

echo execute «${Script}» as «${USER}»

if test "${USER}" = "postgres"; then
	# stop any index process still running and then delete
	# the «mediaserver» database.
	#
	/bin/psql <<-EOF
		SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mediaserver';
		DROP DATABASE mediaserver;
		\q
	EOF
elif test "${USER}" = "root"; then
	# Function to stop a Synlogy service.
	#
	function Stop ()
	{
		local in_Package="${1}"

		synopkg stop		"${in_Package}"
		synoservice --stop	"pkgctl-${in_Package}"
	}
	# Function to start a Synlogy service.
	#
	function Start ()
	{
		local in_Package="${1}"

		synopkg start		 "${in_Package}"
		synoservice --start  "pkgctl-${in_Package}"
	}

	# Stop Quick Search (internally called SynoFinde). This
	# will also stop all services dependent on Quick Search
	#
	Stop SynoFinder

	# Call the current script as postgres user.
	#
	su --command "${Script}" - postgres

	# Start Quick Search (internally called SynoFinder).
	#
	Start SynoFinder
else
	# Call the current script as root user.
	#
	sudo ${Script}
fi
```

<center>![](https://www.synology.com/img/products/detail/DS416play/heading.png)</center>

-----
<center>![posts5060.png](https://files.steempeak.com/file/steempeak/krischik/JaSBtA1B-posts-50-60.png)![comments5870.png](https://files.steempeak.com/file/steempeak/krischik/3zh0hy1H-comments-58-70.png)![votes6680.png](https://files.steempeak.com/file/steempeak/krischik/VVR0lQ3T-votes-66-80.png)![level9090.png](https://files.steempeak.com/file/steempeak/krischik/K8PLgaRh-level-90-90.png)![payout6680.png](https://files.steempeak.com/file/steempeak/krischik/EKjrC9xN-payout-66-80.png)![commented5870.png](https://files.steempeak.com/file/steempeak/krischik/bMY0fJGX-commented-58-70.png)![voted5060.png](https://files.steempeak.com/file/steempeak/krischik/P5yFKQ8S-voted-50-60.png)</center>
👍  , , , , , , , , ,
properties (23)
post_id80,140,875
authorkrischik
permlinksynlogy-diskstation-delete-universal-search-database
categorynas
json_metadata{"app":"steempeak\/1.17.0","format":"markdown","tags":["nas","hardware","network","server","computer","palnet","neoxian","marlians","stem","postgres"],"users":["krischik"],"links":["\/nas\/@krischik\/synlogy-diskstation-416play-performance-fixed"],"image":["https:\/\/www.synology.com\/img\/products\/detail\/DS416play\/heading.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/Fd7MDebD-image.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/pUlVn99a-image.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/35gBILGE-image.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/VdNrTjiP-image.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/degwtEP5-warning.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/JaSBtA1B-posts-50-60.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/3zh0hy1H-comments-58-70.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/VVR0lQ3T-votes-66-80.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/K8PLgaRh-level-90-90.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/EKjrC9xN-payout-66-80.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/bMY0fJGX-commented-58-70.png","https:\/\/files.steempeak.com\/file\/steempeak\/krischik\/P5yFKQ8S-voted-50-60.png"]}
created2019-09-19 11:09:27
last_update2019-09-20 09:54:54
depth0
children1
net_rshares440,224,267,646
last_payout2019-09-26 11:09:27
cashout_time1969-12-31 23:59:59
total_payout_value0.044 SBD
curator_payout_value0.046 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4,457
author_reputation12,621,504,053,655
root_title"Synlogy Diskstation Delete Universal Search Database"
beneficiaries
0.
accountsteempeak
weight500
1.
accountsteemplus-pay
weight500
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (10)
@steem-plus ·
SteemPlus upvote
Hi, @krischik!

You just got a **7.55%** upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in [here](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
post_id80,154,462
authorsteem-plus
permlinksynlogy-diskstation-delete-universal-search-database---vote-steemplus
categorynas
json_metadata{}
created2019-09-19 20:50:51
last_update2019-09-19 20:50:51
depth1
children0
net_rshares0
last_payout2019-09-26 20:50:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length435
author_reputation247,995,867,762,997
root_title"Synlogy Diskstation Delete Universal Search Database"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000