Maintain Zylinc databases
This information is primarily for administrators and/or people who manage Zylinc solutions
It's a very good idea to regularly maintain your Zylinc-related databases, ZyDB and ZyStatDB, to make sure that query times are always acceptable, that the databases don't grow unnecessarily large, etc.
To maintain the databases, you'll need SQL Server Management Studio and basic knowledge about how to run SQL commands and set up SQL Server Maintenance Plans.

Zylinc uses relational databases. Relational databases store data in tables. A table can contain one or more indexes. The purpose of indexes is to optimize query times; just like an index in a book makes it easier to find particular content in the book.
However, database indexes can get fragmented, so that they don't work as efficiently as before. The result is that database query times go up. Fortunately, you can view metadata about the indexes, and that can tell you when it's time to defragment your indexes.
A high fragmentation percentage for an index can severely affect query times, especially if the index is big and uses many database pages to store its data.
On the other hand, a small index can, because of the way SQL Server is designed, show a high fragmentation percentage without affecting query times. This is because up to eight different indexes may share the pages that SQL Server stores small indexes on. When you defragment small indexes that have low page count values, the fragmentation percentage may not be reduced.
You can typically ignore high fragmentation percentage values, if page count is a relatively small number, for example less than 1000.

If database indexes in your ZyDB or ZyStatDB, with a high number of pages, becomes more than 30% fragmented, many queries will begin to take noticeably longer. If you reach 80% fragmentation, you can no longer expect the databases to work on a busy day.
According to Microsoft recommendations, you need to reorganize indexes (ALTER INDEX REORGANIZE) when an index reaches a fragmentation level between 5% and 30%.
If fragmentation is above 30%, you need to rebuild indexes (ALTER INDEX REBUILD).
Therefore, defragment your Zylinc-related databases as soon as an index with a high number in page count becomes more than 10% fragmented.
When you update the databases, or delete large amounts of data from a database, they'll often get fragmented, so always check their fragmentation levels after updates or deletions.

If you run the following script, it'll display a list of indexes with fragmentation greater than 30% and page count greater than 1000 pages. You can change the values if want.
If you want to view all indexes, regardless of fragmentation percentage and page count, delete the last two lines from the script.
-
Start SQL Server Management Studio, and connect to the SQL Server.
-
Click New Query.
-
Copy/paste this SQL code into the query window, and replace the second word ZyDB with the name of the database that you want to view index fragmentation percentage and page count for.
Copyuse ZyDB
SELECT db_name(db_id()) as database_name, tables.name as table_name,indexes.name as index_name, stats.avg_fragmentation_in_percent ,stats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS stats
INNER JOIN sys.tables AS tables ON tables.object_id = stats.object_id
INNER JOIN sys.schemas AS schemas ON tables.schema_id = schemas.schema_id
INNER JOIN sys.indexes AS indexes ON indexes.object_id = stats.object_id AND stats.index_id = indexes.index_id
WHERE stats.database_id = DB_ID()
AND indexes.name IS NOT NULL
AND avg_fragmentation_in_percent>30
AND page_count >1000 -
Click Execute to run the script.
-
Remember to repeat the procedure for both your ZyDB and ZyStatDB databases.


You can rebuild indexes while a database is in use, but index rebuilding will be much faster if the database isn't in use.
-
Start SQL Server Management Studio, and connect to the SQL Server.
-
Click New Query.
-
Copy/paste this SQL code into the query window, and replace the second word ZyDB with the name of the database that you want to defragment the indexes in.
Copyuse ZyDB
exec admin_defragment_auto -
Click Execute to run the script.
-
Remember to repeat the procedure for both your ZyDB and ZyStatDB databases.

You can rebuild indexes while a database is in use, but index rebuilding will be much faster if the database isn't in use.
In the following, copy/paste the generated SQL commands to the query window in SQL Server Management Studio, and execute them.
This script will return another script that you can run to rebuild all indexes one table at a time:
--Make sure you copy/paste the output of this script to a new SQL Query and run it.
SELECT 'ALTER INDEX ALL ON ' + t.[TABLE_NAME] + ' REBUILD; '
FROM INFORMATION_SCHEMA.TABLES t
WHERE t.[TABLE_TYPE] = 'BASE TABLE'
ORDER BY t.[TABLE_NAME];
If the database has limited available memory, you can instead run this script, which will produce another script that rebuilds the indexes one index at a time:
--Make sure you copy/paste the output of this script to a new SQL Query and run it.
SELECT 'ALTER INDEX ' + i.name + ' ON ' + o.name + ' REBUILD; '
FROM sys.indexes i
INNER JOIN sys.objects o on i.object_id = o.object_id
WHERE o.[type] = 'U' AND i.name IS NOT NULL
order by o.[name], i.[name]
Alternatively, you can go through the tables, right click Indexes, and select Rebuild All.

As opposed to ZyDB, the statistics database ZyStatDB is likely to contain more and more historical data over time. That's why it can be a good idea to use SQL Server Management Studio to delete any unwanted old data in ZyStatDB, so it doesn't grow unnecessarily large.
Always create a backup of the database before you delete old data, because there's no way to restore the old data once you've deleted it. It's also a good idea to create a backup before you execute any SQL statements.
The actual name of ZyStatDB is defined during the installation of each Zylinc solution, so bear in mind that it can be different from installation to installation.
You can delete rows older than a certain date from the channel table. All related records, like channel_events, queue_channels, etc., will be deleted due to the foreign key constraints.
So, if you want to delete all calls prior to 1st of January 2017, run a command like this:
DELETE FROM channel WHERE StartTime < '2017-01-01'
You'll then still have old data stored in the user state tables:
-
user_connected
-
user_state
-
user_workstate
-
user_chatstate
-
user_mailstate
-
user_aggrstate
You can remove that old data too, if you run a command like this:
DECLARE @oldDate DATETIME = '2017-01-01';
DELETE FROM user_connected WHERE TimeStart < @oldDate;
DELETE FROM user_state WHERE Time < @oldDate;
DELETE FROM user_workstate WHERE Time < @oldDate;
DELETE FROM user_chatstate WHERE Time < @oldDate;
DELETE FROM user_mailstate WHERE Time < @oldDate;
DELETE FROM user_aggrstate WHERE Time < @oldDate;
When you delete large amounts of data from a database, the database can easily become fragmented, so it's a good idea to subsequently rebuild all indexes for all the tables in the database (see the previous).
This is help for Zylinc version 6.5. To view Zylinc unified help for other versions, go here.
© 2021 Zylinc A/S • Disclaimer
Zylinc unified help is a UK Technical Communication Awards winner
Help version: 24 February 2021 14:16:14
Share this topic: