【IRIS/Cache】ジャーナル(中級編)

本記事はグローバル・ジャーナル(中級編)についての解説になります。

※この記事は下記の方向けになります。
  • ジャーナルの操作をターミナルで行いたい方
  • 実践的なジャーナル操作を行いたい方

はじめに

前回の記事で、ジャーナルとは?に触れました。
また、管理ポータルでのジャーナル操作を解説しました。

本記事では、ターミナルを使用してジャーナルの操作方法を行っていこうと思います。

ジャーナルは単に蓄積するだけではなく、適切に管理・活用することが重要です。
放置するとディスク容量を圧迫し、パフォーマンスの低下を招くこともあるため、適切な運用が求められます。

今回は中級編として実際にコマンドを実行しながら、ジャーナルの管理や運用方法を解説していきます。

それでは、ターミナルを起動して、ジャーナル操作を始めましょう。

ターミナルによるジャーナル操作

ネームスペースを「%SYS」に変更し、下記コマンドを実行します。

zn "%SYS"
d ^JOURNAL

コマンドを入力後、ターミナルにNo.1~13のメニュー一覧が表示されます。
 ※No.10は欠番です。
 ※No.13は、ジャーナル・ファイルの出力先「プライマリ・セカンダリ」が相違している場合に表示されます。

「Option?」にメニュー番号を入力すると、対応する作業を実行できます。

基本的には、メニューからの操作で問題ありませんが、特定の操作を直接実行する事も可能です。
 →^JRNSTAET等
併せて解説していきたいと思います。

1. Begin Jounaling

停止しているジャーナルを再開する。

開始している状態でコマンドを実行すると、下記メッセージが表示されます。
Already journaling to <journal dir>\ジャーナル・ファイル名

基本的には停止しているジャーナルを再開するメニューです。
再開すると、新規ジャーナルファイルでジャーナリングが開始します。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNSTART

2. Stop Jounaling

ジャーナルを停止する。

ジャーナル停止のメニューを選択すると、下記メッセージが表示されます。

翻訳)ジャーナリングが再開されるまで、トランザクションのロールバックは失敗します。
データベースの更新はジャーナルから失われ、データベースはジャーナル ファイルから完全に回復できなくなります。

このメニューを実行すると、システム全体でジャーナリングが停止します。
「%Save」等でのジャーナリングも停止するので、データの安全性を考えると実行する時は、慎重に検討を行ってください。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNSTOP

3. Switch Journal File

新規ジャーナルファイルに切り替えます。
現在のジャーナルファイルを即バックアップしたい時等に、よく使用しています。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNSWTCH

4. Restore Globals From Journal

ジャーナルファイルからデータ・ベースをリストアします。
下記手順を追って、リストアを確認していきます。

リストア動作確認方法

ジャーナル・ファイルを使用したリストア方法と、その確認方法を併せて解説していきます。

作業の流れはこんな感じ

①先ずは、リストアするファイルが分かりやすいようにジャーナルを切り替えます。

メニューNo.3のジャーナル切り替えコマンドを実行します。

d ^JRNSWTCH

②データ・ベースをディスマウントして、DATファイルをコピーします。

このコピーしたDATファイルに対し、リストアを行いたいと思います。

③再度マウントして、下記コマンドをターミナルで実行し、グローバルを追加します。

zn "sample"
f pos=1:1:10000 { s ^test(pos)="ジャーナル・リストア実行:"_$tr($j(pos,5)," ",0) }

コマンド実行後、ジャーナルに登録されている事を確認します。

ばっちりジャーナルが出力されています。

④現在のDATファイルを削除し、②でコピーしたDATファイルを設定します。

下記コマンドをターミナルで実行し、グローバルが存在しない事を確認します。

zn "sample"
zw ^test

⑤ジャーナル・ファイルによるリストアを開始します。

メニューNo.4のジャーナルファイルのリストアを選択してください。

翻訳)このユーティリティは、ジャーナル ファイルの内容を使用して、バックアップからグローバルを最新の状態に更新します。

・リストアを行う意思を確認してくるので、「y」を入力します。

Process all journaled globals in all directories?

翻訳)すべてのディレクトリ内のすべてのジャーナル化されたグローバルを処理しますか?

・今回は特定のDBのリストアを行いたいので、「n」を入力します。

Are journal files imported from a different operating system?

翻訳)ジャーナル ファイルは別のオペレーティング システムからインポートされていますか?

・今回は異なるので「n」を入力します。

Directory to restore [? for help]: ?
 
    Enter a directory which is in the journal; you will
    then be given the option to process all or some of the
    globals which were journaled from that directory.
 
    Note that you will also be given the chance to re-direct
    the contents of this directory to another directory.
 
Directory to restore [? for help]: D:\IRISDB\SAMPLE-DATA  d:\irisdb\sample-data\
Redirect to Directory: d:\irisdb\sample-data\
 => --> d:\irisdb\sample-data\

翻訳)ジャーナルにあるディレクトリを入力すると、そのディレクトリからジャーナルされたグローバルのすべてまたは一部を処理するオプションが表示されます。
このディレクトリの内容を別のディレクトリにリダイレクトする機会も提供されることに注意してください。

・今回のリストア対象である「D:\IRISDB\SAMPLE-DATA」を入力するとターミナルに「=>」が表示されます。
 今回のターゲットは1つなので、「Enter」で確定させます。

Process all globals in d:\irisdb\sample-data\? No => no
 
Global ^test
Global ^

翻訳)d:\irisdb\sample-data\? 内のすべてのグローバルを処理します。

・「^test」グローバルのみを対象としたいため「n」を入力し、対象グローバルを聞かれるので「test」と入力して「Enter」で確定させます。

Directory to restore [? for help]:

・再度リストア対象を確認してくるので、「Enter」で確定します。

Processing globals from the following datasets:
 1. d:\irisdb\sample-data\   Selected Globals:
          ^test

・今回のリストア対象が表示されます。

Specifications correct? Yes =>

翻訳)仕様は正しいですか?

・Yes!!「Y」

Are journal files created by this InterSystems IRIS instance and located
in their original paths? (Uses journal.log to locate journals)?

翻訳)ジャーナル ファイルは、この InterSystems IRIS インスタンスによって作成され、元のパスに配置されていますか? (journal.log を使用してジャーナルを検索します)?

・Yes!!「Y」

Specify range of files to process
 
Enter ? for a list of journal files to select the first and last files from
First file to process:

翻訳)処理するファイルの範囲を指定
ジャーナル ファイルのリストを表示するには、? と入力して、最初のファイルと最後のファイルを選択します

・リストを確認したいので、「?」を入力します。※お好みで!

Specify range of files to process
 
Enter ? for a list of journal files to select the first and last files from
First file to process:  ?
 
 1) d:\iris\mgr\journal\hoge_20250211.008
 2) d:\iris\mgr\journal\hoge_20250212.001
 3) d:\iris\mgr\journal\hoge_20250212.002
 4) d:\iris\mgr\journal\hoge_20250212.003
 5) d:\iris\mgr\journal\hoge_20250212.004
 6) d:\iris\mgr\journal\hoge_20250212.005
 7) d:\iris\mgr\journal\hoge_20250213.001
 8) d:\iris\mgr\journal\hoge_20250213.002
 9) d:\iris\mgr\journal\hoge_20250213.003
10) d:\iris\mgr\journal\hoge_20250213.004
11) d:\iris\mgr\journal\hoge_20250213.005
 
First file to process:

・今回は、直近で切り替えた最新ジャーナルのみ対象なので、「11」を選択します。

Final file to process:  d:\iris\mgr\journal\hoge_20250213.005 =>

・当然最後も同じジャーナル・ファイルになるため「Enter」を入力します。

Prompt for name of the next file to process? No =>

翻訳)次に処理するファイルの名前を要求しますか?

・リストアするジャーナル・ファイルは他にないため「n」を入力します。

The following actions will be performed if you answer YES below:
 
* Listing journal files in the order they will be processed
* Checking for any missing journal file on the list ("a broken chain")
 
The basic assumption is that the files to be processed are all
currently accessible. If that is not the case, e.g., if you plan to
load journal files from tapes on demand, you should answer NO below.
Check for missing journal files? Yes =>

翻訳)以下に「はい」と答えると、次のアクションが実行されます:
 ・ジャーナル ファイルを処理順にリストする
 ・リストに欠落しているジャーナル ファイル (「壊れたチェーン」) がないか確認する
処理するファイルはすべて現在アクセス可能であることが基本的な前提です。そうでない場合 (たとえば、ジャーナル ファイルをオンデマンドでテープからロードする予定の場合) は、以下に「いいえ」と答えてください。
欠落しているジャーナル ファイルを確認しますか? はい =>

・今回は1ファイルのみなので「n」と入力します。

The journal restore includes the current journal file.
You cannot do that unless you stop journaling or switch
     journaling to another file.
Do you want to switch journaling? Yes =>

翻訳)ジャーナルの復元には現在のジャーナル ファイルが含まれます。
ジャーナリングを停止するか、ジャーナリングを別のファイルに切り替えない限り、これを行うことはできません。
ジャーナリングを切り替えますか? はい =>

・ジャーナル・ファイルを切り替えるため「y」を入力します。
 →新規ジャーナル・ファイルに切り替わります。

You may disable journaling of updates for faster restore for all
databases other than mirrored databases. You may not want to do this
if a database to restore is being shadowed as the shadow will not
receive the updates.
Do you want to disable journaling the updates? Yes =>

翻訳)ミラーリングされたデータベース以外のすべてのデータベースの復元を高速化するために、更新のジャーナリングを無効にすることができます。復元するデータベースがシャドウされている場合、シャドウは更新を受信しないため、この操作は行わない方がよいでしょう。更新のジャーナリングを無効にしますか? はい =>

・「y」を入力します。

Updates will NOT be journaled
Before we job off restore daemons, you may tailor the behavior of a
restore daemon in certain events by choosing from the options below:
 
     DEFAULT:    Continue despite database-related problems (e.g., a target
     database cannot be mounted, error applying an update, etc.), skipping
     updates to that database. Affected database(s) may not be self-consistent
     and will need to be recovered separately
 
     ALTERNATE:  Abort if an update would have to be skipped due to a
     database-related problem (e.g., a target database cannot be mounted,
     error applying an update, etc.). Databases will be left in a
     self-consistent state as of the record that caused the restore to be
     aborted. Parallel dejournaling will be disabled with this setting
 
     DEFAULT:    Abort if an update would have to be skipped due to a
     journal-related problem (e.g., journal corruption, some cases of missing
     journal files, etc.)
 
     ALTERNATE:  Continue despite journal-related problems (e.g., journal
     corruption, some missing journal files, etc.), skipping affected updates
 
Would you like to change the default actions? No =>

翻訳)更新はジャーナリングされません
復元デーモンをジョブオフする前に、以下のオプションから選択して、特定のイベントでの復元デーモンの動作をカスタマイズできます:

DEFAULT: データベース関連の問題 (ターゲット データベースをマウントできない、更新の適用エラーなど) があっても続行し、そのデータベースへの更新をスキップします。影響を受けるデータベースは自己整合していない可能性があり、個別に回復する必要があります。

ALTERNATE: データベース関連の問題 (ターゲット データベースをマウントできない、更新の適用エラーなど) のために更新をスキップする必要がある場合は中止します。データベースは、復元の中止の原因となったレコードの時点で自己整合状態のままになります。この設定では、並列デジャーナリングは無効になります。


DEFAULT: ジャーナル関連の問題 (例: ジャーナルの破損、ジャーナル ファイルの欠落など) により更新をスキップする必要がある場合は中止します。


ALTERNATE: ジャーナル関連の問題 (例: ジャーナルの破損、ジャーナル ファイルの欠落など) があっても、影響を受ける更新をスキップして続行します

デフォルトのアクションを変更しますか? いいえ =>

・変更予定がないので「n」を入力します。

Start the restore? Yes =>

・Yes!!!

リストアが完了しました。
全体の流れは下記になります。

Option? 4
This utility uses the contents of journal files
to bring globals up to date from a backup.
 
Restore the Journal? Yes => yes
Process all journaled globals in all directories? no
Are journal files imported from a different operating system? No => no
 
Directory to restore [? for help]: ?
 
    Enter a directory which is in the journal; you will
    then be given the option to process all or some of the
    globals which were journaled from that directory.
 
    Note that you will also be given the chance to re-direct
    the contents of this directory to another directory.
 
Directory to restore [? for help]: D:\IRISDB\SAMPLE-DATA  d:\irisdb\sample-data\
Redirect to Directory: d:\irisdb\sample-data\
 => --> d:\irisdb\sample-data\
Process all globals in d:\irisdb\sample-data\? No => no
 
Global ^test
Global ^
 
Directory to restore [? for help]:
 
Processing globals from the following datasets:
 1. d:\irisdb\sample-data\   Selected Globals:
          ^test
 
Specifications correct? Yes => Yes
Are journal files created by this InterSystems IRIS instance and located
in their original paths? (Uses journal.log to locate journals)? yes
Specify range of files to process
 
Enter ? for a list of journal files to select the first and last files from
First file to process:  ?
 
 1) d:\iris\mgr\journal\hoge_20250211.008
 2) d:\iris\mgr\journal\hoge_20250212.001
 3) d:\iris\mgr\journal\hoge_20250212.002
 4) d:\iris\mgr\journal\hoge_20250212.003
 5) d:\iris\mgr\journal\hoge_20250212.004
 6) d:\iris\mgr\journal\hoge_20250212.005
 7) d:\iris\mgr\journal\hoge_20250213.001
 8) d:\iris\mgr\journal\hoge_20250213.002
 9) d:\iris\mgr\journal\hoge_20250213.003
10) d:\iris\mgr\journal\hoge_20250213.004
11) d:\iris\mgr\journal\hoge_20250213.005
 
First file to process:  11 d:\iris\mgr\journal\hoge_20250213.005
Final file to process:  d:\iris\mgr\journal\hoge_20250213.005 =>
Prompt for name of the next file to process? No => No
 
The following actions will be performed if you answer YES below:
 
* Listing journal files in the order they will be processed
* Checking for any missing journal file on the list ("a broken chain")
 
The basic assumption is that the files to be processed are all
currently accessible. If that is not the case, e.g., if you plan to
load journal files from tapes on demand, you should answer NO below.
Check for missing journal files? Yes => no
The journal restore includes the current journal file.
You cannot do that unless you stop journaling or switch
     journaling to another file.
Do you want to switch journaling? Yes => Yes
Journaling switched to d:\iris\mgr\journal\hoge_20250213.006
 
You may disable journaling of updates for faster restore for all
databases other than mirrored databases. You may not want to do this
if a database to restore is being shadowed as the shadow will not
receive the updates.
Do you want to disable journaling the updates? Yes => Yes
Updates will NOT be journaled
Before we job off restore daemons, you may tailor the behavior of a
restore daemon in certain events by choosing from the options below:
 
     DEFAULT:    Continue despite database-related problems (e.g., a target
     database cannot be mounted, error applying an update, etc.), skipping
     updates to that database. Affected database(s) may not be self-consistent
     and will need to be recovered separately
 
     ALTERNATE:  Abort if an update would have to be skipped due to a
     database-related problem (e.g., a target database cannot be mounted,
     error applying an update, etc.). Databases will be left in a
     self-consistent state as of the record that caused the restore to be
     aborted. Parallel dejournaling will be disabled with this setting
 
     DEFAULT:    Abort if an update would have to be skipped due to a
     journal-related problem (e.g., journal corruption, some cases of missing
     journal files, etc.)
 
     ALTERNATE:  Continue despite journal-related problems (e.g., journal
     corruption, some missing journal files, etc.), skipping affected updates
 
Would you like to change the default actions? No => No
 
 
Start the restore? Yes => Yes
 
d:\iris\mgr\journal\hoge_20250213.005
100.00%
[Journal restore completed at 20250213 22:32:45]
 
The following databases have been updated:
 
1. d:\irisdb\sample-data\

⑥グローバルの確認

ネームスペースを切り替えて、グローバルを確認したいと思います。

zn "sample"
 
w ^test(1) // > ジャーナル・リストア実行:00001
w ^test(10000) // > ジャーナル・リストア実行:10000

正常にリストアが完了したようです。

今回は1ジャーナル・ファイル、1グローバルのリストアを実施しましたが、特に問題なく正常にリストアが完了しました。
複数ファイル、複数グローバルでもそこまで操作が変わる事はありません。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNRESTO

5. Display Journal File

ジャーナル・ファイルから、ジャーナルレコードを参照します。

コマンドを入力すると、ジャーナル・ファイルの一覧が表示されます。

ターミナルの操作は、キーボードの「D, U, N, P, G, E, I, Q」で行います。

キー名説明
D, Uページの切り替え。PageDown, PageUpの略
N, Pカーソル「>」の移動。Next, Prevの略
Gジャーナル・ファイルの中身を参照する。
 ※参照したいジャーナル・ファイルのフルパスを入力します。


ジャーナル・ファイルの中身が表示されます。

 ・・・管理ポータルの方が見やすいですね。

各コマンド「G,F,E」に関しては、また別途解説します。
Eカーソル「>」で選択したジャーナル・ファイルの中身を表示します。
 ※上記スナップショット
Iジャーナル・ファイルのファイル情報を表示します。


さらに「D」を入力すると、データベース情報が表示されます。
Qメニュー一覧に戻る

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNDUMP

6. Purge Journal Files

ジャーナル・ファイルの削除を行います。

大量のジャーナルが出力され、ストレージが圧迫される前に実行しましょう。
筆者もチョイチョイ使っています。

コマンドを実行すると下記1or2の選択肢を求められます。

1) トランザクションのロールバックやクラッシュ回復に必要のないジャーナルを消去する
2) 既存の基準 (1 日または 1 回のバックアップ) に基づいてジャーナルを消去する

ターミナルで直接実行する場合は、下記コマンドを入力します。

d PURGE^JOURNAL

7. Edit Journal Properties

管理ポータルの「ジャーナルの設定」をターミナルで行います。

上記No.① ~ ⑥に対応する項目が下記になります。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ^JRNOPTS

8. Activate or Deactivate Journal Encryption

ジャーナルの暗号化の有効化/無効化を切り替えます。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d ENCRYPT^JOURNAL

9. Display Journal status

ジャーナルの状態を表示します。

項目名説明
Primary journal directoryメインのディレクトリ名
Primary journal directory free space上記の空き容量
Secondary journal directory代替ディレクトリ名
Secondary journal directory free space上記の空き容量
Current journal file現在のジャーナルファイル名
Current journal file maximum sizeジャーナル・ファイルの最大サイズ
Current journal file space used使用量
Journaling isジャーナルの状態
 ・enabled = 有効
 ・disabled = 無効 (停止))
 ・suspended = I/O エラーのために無効 (中断)
 ・frozen = I/O エラーのためにフリーズ
 ・paused = ジャーナルの切り替え中 (一時停止)

ターミナルで直接実行する場合は、下記コマンドを入力します。

d Status^JOURNAL

12. Journal catch-up for mirrored databases

ミラー・ジャーナル・ファイルをミラーリングされるデータベースにリストアします。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d MirrorCatchup^JRNRESTO

13. Switch Journaling to Secondary Directory

「Primary journal directory」と「Secondary journal directory」の設定値が異なっている時のみ表示される項目となります。

ターミナルで直接実行する場合は、下記コマンドを入力します。

d SWDIR^JOURNAL

おわりに

いかがだったでしょうか。

かなり長い記事となりましたが、ターミナルを使用してのジャーナル操作を一通り実施しました。
各コマンドを理解し正しく運用することで、システムの安定性とデータの整合性を確保できます。

ジャーナルの管理は、障害発生時の迅速な復旧にも直結するため、実践を重ねながら理解を深めていくことが重要です。

障害によって、管理ポータルが起動しないケースも考えられます。
その際は、ターミナル操作での確認方法を知っておいても良いと思います。

今後も最適な運用を目指し、より効率的な管理方法を探っていきましょう。