· 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.




Product version: Caché 2017.1
Discussion (6)3
Log in or sign up to continue
there are command line utilities i Namespace %SYS down from ^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

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


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)