Written by

Sales Engineer at InterSystems
Article Sylvain Guilbaud · Oct 6, 2016 3m read

How to dismount/mount a database programmatically

to dismount/mount a database, use Dismount() and Mount() methods in SYS.Database class available in %SYS namespace.
NB: the database ID is its Directory

You'll find  some examples of how to dismount/mount and check if a database is mounted (Mounted=1) or not (Mounted=0), and quickly see all the attributes of a database (via zwrite)


%SYS>set db="/opt/irisapp/data" 

%SYS>w ##class(SYS.Database).%OpenId(db).Mounted                     
1
%SYS>w ##class(SYS.Database).%OpenId(db).Dismount()
1
%SYS>w ##class(SYS.Database).%OpenId(db).Mounted   
0
%SYS>w ##class(SYS.Database).%OpenId(db).Mount()   
1
%SYS>w ##class(SYS.Database).%OpenId(db).Mounted
1
%SYS>zw ##class(SYS.Database).%OpenId(db)
+----------------- general information ---------------
|      oref value: 3
|      class name: SYS.Database
|           %%OID: $lb("/opt/irisapp/data","SYS.Database")
| reference count: 2
+----------------- attribute values ------------------
|       %Concurrency = 0  <Set>
|        BlockFormat = 2
|          BlockSize = 8192  <Set>
|             Blocks = 780288
|       BlocksPerMap = 62464
|   ClusterMountMode = 0  <Set>
|     ClusterMounted = 0  <Set>
|        CurrentMaps = 13
|          Directory = "/opt/irisapp/data/"  <Set>
|     DirectoryBlock = 3
|        EncryptedDB = 0  <Set>
|    EncryptionKeyID = ""
|          Expanding = 0
|      ExpansionSize = 0  <Set>
|               Full = 0
| GlobalJournalState = 3  <Get,Set>
|     InActiveMirror = 0
|  LastExpansionTime = "09/06/2023 20:00:01"
|            MaxSize = 0  <Set>
|MirrorActivationRequired = 0
|    MirrorDBCatchup = 0
| MirrorDBCreatedNew = 0
|       MirrorDBName = ""
|     MirrorDBPaused = 0
|   MirrorFailoverDB = 0
|      MirrorNoWrite = 0
|     MirrorObsolete = 0
|      MirrorSetName = ""
|           Mirrored = 0
|            Mounted = 1
| NewGlobalCollation = 5  <Set>
|NewGlobalGrowthBlock = 50  <Set>
|    NewGlobalIsKeep = 0  <Set>
|NewGlobalPointerBlock = 16  <Set>
|   NumberOfConfigDB = 0
|       ROReasonCode = 0
|       ROReasonText = ""
|           ReCreate = 0
|           ReadOnly = 0  <Set>
|    ReadOnlyMounted = 0
|       Reinitialize = 0
|        RequestSize = 0
|       ResourceName = "%DB_IRISAPP-DATA"
|RunCatchupDBOnCreate = 1
|                SFN = 6
|               Size = 6096  <Set>
|           Skeleton = 0
|           SparseDB = 0
+----------------------------------------------------- 
%SYS>

Comments

Aleksandar Kovacevic · Dec 25, 2021

Thanks very much for this message. Do you know what can I do if I get error: "ERROR #345: Cannot dismount manager's database" when trying to dismount IRISLIB. Is there a way to dismount it programmatically, without using Management Portal?
Edit: ah, I just need to do %Save, and it is done without needing to dismount and mount again.

0
Robert Cemper  Dec 25, 2021 to Aleksandar Kovacevic

Oh, dear!  Dismounting IRISLIB is probably the worst you can do to destroy the whole system.
It's like removing the heart from your body. You shouldn't even think of it

0