Article
· Jan 25 4m read

Reasons why journal files remain for a long time without being deleted

InterSystems FAQ rubric

If the system does not stop for 24 hours, old journal files will be deleted at 0:30 according to the "Journal file deletion settings".

A possible cause of journal files remaining that are older than the "Journal file deletion settings" is that there are transactions that remain open.

In that case, you will be able to delete the journal file by searching for processes executing transactions and finalizing the transactions.

The sample below checks for the existence of open transactions, and if they exist, outputs the target file name and journal record information.

(Samples  can be downloaded from here

*Note* If the journal file size to be checked is large or if there are many journal files, it will take time to execute, so please contact our support center.

Class ISJ.JournalUtility
{
ClassMethod GetOpenTransaction() As %Status
{
    set status=$$$OK
    #dim ex As %Exception.AbstractException
    #dim rset As %ResultSet
    try {
        //current journal file
        write !,"Current journal file name:",
            ##class(%SYS.Journal.System).GetCurrentFileName(),!!         // Open transaction file
        // Get info about journals recorded in WIJ
        $$$ThrowOnError(##class(%SYS.Journal.System).GetImageJournalInfo(.filename,.jrnoffset,.jrnfilecount,.opentranoffset,.opentranfilecount))
        if $get(opentranoffset)="" {
            write !,"There are no open transactions",!
            return status
        }         //If there is a differeence in file counts(jrnfilecount-opentranfilecount>0 )
        // There is an open transaction in the old journal file, so please search for a target file name
        if jrnfilecount-opentranfilecount>0 {
            set loopcnt=jrnfilecount-opentranfilecount
            for i=1:1:loopcnt {
                set currentfile=filename
                $$$ThrowOnError(##class(%SYS.Journal.File).GetPrev(currentfile,.filename))
            }
        }         write "〇〇 list of open target journal records 〇〇",!
        set rset=##class(%ResultSet).%New("%SYS.Journal.Record:List")
        do rset.%Execute(filename,,,,$LB("Address","=",opentranoffset))
        write !,"=== File Name : ",filename," ===",!
        write "Address : TimeStamp : ProcessID : RemoteSystemID : TypeName : Transaction",!
        while rset.%Next() {
            write rset.%Get("Address")," : ",
                rset.%Get("TimeStamp")," : ",
                rset.%Get("ProcessID")," : ",
                rset.%Get("RemoteSystemID")," : ",
                rset.%Get("TypeName")," : ",
                rset.%Get("InTransaction"),!
        }
    }
    catch ex {
        set status=ex.AsStatus()
    }
    return status
}
}

An example of execution is as follows.

USER>do ##class(ISJ.JournalUtility).GetOpenTransaction()

Current journal file name:/usr/irissys/mgr/journal/20210330.002
〇〇 list of open target journal records 〇〇

=== File Name : /usr/irissys/mgr/journal/20210330.001 ===
Address : TimeStamp : ProcessID : RemoteSystemID : TypeName : Transaction
1834156 : 2021-03-30 13:19:00 : 5194 : 1073741824 : BeginTrans : 1
Discussion (3)1
Log in or sign up to continue

Another option to view/monitor opened transactions directly from System Management Portal is to use the System Dashboard (System Operation -> System Dashboard). No need to write code or SQL, just a few clicks.
In System Dashboard there is a line "Transactions":

In case one or more transactions is/are opened for more then 20 minutes (or so...) the System Dashboard shows a Troubled state.

In System Dashboard, if you click the "Transactions" label (regardless of Troubled state) then at the bottom of the page a link "Click here for more details" is displayed:

If/when "Click here for more details" is clicked a page with top 5 transactions (longer time) are displayed:
 

From there you can click the Process ID and go directly to the Process Details page.