Question David McPfimeloronti · Dec 18, 2023

Compact and Truncate Database

in Management Portal on Freespace screen there are links to compact and truncate a database.

Can these tasks be done programmatically?  I have looked through documentation and dont see anything but I hope I just missed it.

Thanks,

David

Product version: Caché 2017.1

Comments

Robert Cemper · Dec 18, 2023
there are command line utilities i Namespace %SYS down from ^DATABASE
%SYS>d ^DATABASE
 
 1) Create a database
 2) Edit a database
 3) List databases
 4) Delete a database
 5) Mount a database
 6) Dismount a database
 7) Compact globals in a database
 8) Show free space for a database
 9) Show details for a database
10) Recreate a database
11) Manage database encryption
12) Return unused space for a database
13) Compact free space in a database
14) Defragment globals in a database
 
Option?

in addition  Class SYS.Database  holds a long list of utility methods 
you have to dig into Class docu

0
Erik Hemdal  Dec 26, 2023 to Alexander Pettitt

I strongly agree with @Alexander.Pettitton this one.  Request help from the WRC to make sure you have a version containing necessary corrections.  The WRC engineers can advise you about whether your specific version is affected and how best to upgrade.

0
Pierre LaFay · Dec 26, 2023

You can :

Create an abstract class with a method that successively calls:
FileCompact() and ReturnUnusedSpace() from the class SYS.Database

Then you can add in the task manager a new task (type RunLegacyTask) which calls your method

Before doing this, I advise you to make a backup of your database or a snapshot of your machine if it is a VM

0
David.Satorres6134 · Jan 6, 2024

Hi,

You can use this set of instructions to compact and truncate any database:

s $namespace="%SYS", Percentage=100, Databasedir="d:\whatever"
d ##class(SYS.Database).CompactDatabase(Databasedir,Percentage)
d ##class(SYS.Database).GetDatabaseFreeSpace(Databasedir, .FreeSpace)
d ##class(SYS.Database).FileCompact(Databasedir, FreeSpace, .ActualFree)
d ##class(SYS.Database).ReturnUnusedSpace(Databasedir,0,.newsize)

0