Question
Armin Gayl · Aug 7, 2018

Database Freespace Compact in a Task

Hello,

I would like to schedule the Database Compact and Freespace methods as legacy tasks.

Has anyone implemented this yet?
Is this even possible? 

The request for this is due to the fact that we have 3 interfaces in a namespace whose messages are deleted after 7 days. All other messages in this namespace should be kept for one year.
This leads to a certain fragmentation. Furthermore, the messages to be deleted are relatively large (MDM^T02 > 32MB), which in turn leads to a fast growth of the database size. 

How would you solve this problem?

With kind regards

Armin Gayl

0
0 359
Discussion (1)3
Log in or sign up to continue

This is a late reply and the content my explain why.
There is a set of available classes and methods to fulfill your requirements.
Though you have to be careful as there are side conditions to be considered that require special attention.

You have to wrap these class methods in some routine or class and then plug it into the standard task manager.

From your question I understand 4 different tasks:

  • Compact globals in a database   (=force global to make better use of data blocks) ##Class(SYS.Database).Compact(..............)
  • Return unused space for a database (=truncate DB) ##class(SYS.Database).ReturnUnusedSpace(........)
  • Defragment a database (=make Blocks contiguous)  ##class(SYS.Database).Defragment(........) ##class(SYS.Database.BackgroundDefragment).Start(........)  ;;[not so useful for task manager]
  • Compact free space in a database (=really returns disk space) ##class(SYS.Database).FileCompact.(........) ##class(SYS.Database.BackgroundFileCompact).Start(........)  ;;[not so useful for task manager]

The official documetation also has some examples.
My personal favorite is routine DATABASE.int in namespace %SYS
It covers all these functions for interactive use and illustrates also all possible requirements and limits in detail.
The labels you should check are:
COMPACT()
DBTruncat()
DEFRAG()
FileCompact()

This might also explain why there is not just a method out of the box.