Written by

Sales Engineer at InterSystems
Article Sylvain Guilbaud · Oct 6, 2016 2m 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
Vicente Abril · 4 hr ago

Good afternoon;

I am at a stop point tying to figure out how to check programmatically, for Unmounted/Mounted and most important *Dismounted* 
I can check for Unmounted with the following:
echo "S db=##class(SYS.Database).%OpenId(\"/bat2022/ROCKET2022/YOU/\") W db.Mounted" \     | irissession CLS -U %SYS

If results i 1 is mounted and if it 0 is Unmounted
So now how do I check for Dismounted is this possible?
Your help is greatly appreciate !!

0
Robert Cemper  3 hr ago to Vicente Abril

To clarify things:

  • ##class(SYS.Database).shows only the actual status Mounted / Unmounted
  • It doesn't record any transitions
  • DISMOUNTED (same as MOUNTED) is such a transition
  • It is recorded in messages.log of your system directory

Example:
06/10/26-22:00:23:437 (14644) 0 [Generic.Event] Dismounted database c:\intersystems\iris242\mgr\uiris\ 
That's what you you have to scan if you chase the transition
 

0
Patrick Fleming · 3 hr ago

 Thank you for sharing this example. I didn't know that SYS.Database provides both Dismount() and Mount() methods. This is a very useful approach for database administration tasks and automation. I also appreciate the example showing how to verify the Mounted property before and after the operation.

0