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="/intersystems/ensemble/mgr/samples" 

%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)
<OBJECT REFERENCE>[1@SYS.Database]
+----------------- general information ---------------
|      oref value: 1
|      class name: SYS.Database
|           %%OID: $lb("/is/ensemble/mgr/samples","SYS.Database")
| reference count: 2
+----------------- attribute values ------------------
|       %Concurrency = 0  <Set>
|        BlockFormat = "Cache"
|          BlockSize = 8192  <Set>
|             Blocks = 16384
|       BlocksPerMap = 62464
|   ClusterMountMode = 0  <Set>
|     ClusterMounted = 0  <Set>
|        CurrentMaps = 1
|          Directory = "/is/ensemble/mgr/samples/"  <Set>
|     DirectoryBlock = 3
|        EncryptedDB = 0  <Set>
|    EncryptionKeyID = ""
|          Expanding = 0
|      ExpansionSize = 0  <Set>
|               Full = 0
| GlobalJournalState = 2  <Get,Set>
|     InActiveMirror = 0
|  LastExpansionTime = "22/09/2016 14:08:53"
|            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
|           ReadOnly = 0  <Set>
|    ReadOnlyMounted = 0
|       Reinitialize = 0
|        RequestSize = 0
|       ResourceName = "%DB_SAMPLES"
|                SFN = 50
|               Size = 128  <Set>
|           Skeleton = 0
|           SparseDB = 0
+-----------------------------------------------------

%SYS>
3
0 1,935
Discussion (2)1
Log in or sign up to continue

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.

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