
はじめに
以上のLiveLabsを参考に実際に手を動かしながらDBA GOLDの内容を手を動かして学習しました。
今回はバックアップとリカバリの内容を扱います。
初期設定のポイント
本編に入る前にマニュアル通り実行してもうまくいかないことがあったので、以下の記事に自分なりのポイントをまとめてます。
本編
ライブラボのなかで大事だと思われるところをピックアップしていきます。
高速リカバリ領域について
Note: The db_recovery_file_dest parameter sets the location of the fast recovery area. Oracle recommends placing the fast recovery area on a separate storage device from the Oracle Database files. The db_recovery_file_dest_size parameter shows the size of your fast recovery area. The size of your fast recovery area may differ from what is shown in this example. Generally, the default size present for the fast recovery area might not be sufficient for your files.
以下、翻訳。
メモ :db_recovery_file_destパラメータは、高速リカバリ領域の場所を設定します。Oracleでは、Oracle Databaseファイルとは別のストレージ・デバイスに高速リカバリ領域を配置することを推奨しています。db_recovery_file_dest_size パラメーターは、高速リカバリ領域のサイズを示します。高速リカバリ領域のサイズは、この例で示すものとは異なる可能性があります。一般に、高速リカバリ領域のデフォルトサイズがファイルに対し て十分でない場合があります。
(余談)db_recovery_file_destを設定する時にエラーが発生したので以下にまとめた
元々/opt/oracleの配下にrecovery_areaというファイルが存在していなかったので、エラーが発生した。
なので、ファイル作成を行った。
alter system set db_recovery_file_dest="/opt/oracle/recovery_area";
alter system set db_recovery_file_dest="/opt/oracle/recovery_area"
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is inva
ORA-01261: Parameter db_recovery_file_dest destination string cannot be
translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory
SQL> exit
Disconnected from Oracle Database 21c Enterprise Edition Release 21.0.0 oduction
Version 21.4.0.0.0
[CDB1:oracle@dbhol:/opt/oracle/product/21c/dbhome_1/bin]$ cd /opt/oracl
[CDB1:oracle@dbhol:/opt/oracle]$ ls
admin cfgtoollogs dbs homes jdk1.8.0_321 oraInventory
audit checkpoints diag jdk oradata product
[CDB1:oracle@dbhol:/opt/oracle]$ mkdir /opt/oracle/recovery_area
[CDB1:oracle@dbhol:/opt/oracle]$ ls
admin cfgtoollogs dbs homes jdk1.8.0_321 oraInventory recovery_a
audit checkpoints diag jdk oradata product
[CDB1:oracle@dbhol:/opt/oracle]$ cd /opt/oracle/product/21c/dbhome_1/bi
[CDB1:oracle@dbhol:/opt/oracle/product/21c/dbhome_1/bin]$ ./sqlplus / a
SQL*Plus: Release 21.0.0.0.0 - Production on Wed Aug 16 06:34:09 2023
Version 21.4.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.4.0.0.0
SQL> alter system set db_recovery_file_dest="/opt/oracle/recovery_area"
System altered.
アーカイブログを有効化する方法
↓現在はノーアーカイブログモード
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /opt/oracle/homes/OraDB21Home1/dbs/arch
Oldest online log sequence 162
Current log sequence 164
To enable archiving, you must mount the Oracle Database but not open it. Use the following command to shut down the Oracle Database instance.
アーカイブを有効にするには、Oracleデータベースをマウントする必要がありますが、開く必要はありません。次のコマンドを使用して、Oracle Databaseインスタンスをシャットダウンします。
SQL>exit;
[CDB1:oracle@dbhol:/opt/oracle/product/21c/dbhome_1/bin]$ ./rman
Recovery Manager: Release 21.0.0.0.0 - Production on Mon Aug 7 16:42:31 2023
Version 21.4.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target;
connected to target database: CDB1 (DBID=1058798813)
RMAN> shutdown immediate;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount;
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 3221225384 bytes
Fixed Size 9691048 bytes
Variable Size 1644167168 bytes
Database Buffers 1560281088 bytes
Redo Buffers 7086080 bytes
Oracle recommends that you always back up the Oracle Database before making any significant change to the Oracle Database. Use the following command to create a back up of the Oracle Database before you enable the ARCHIVELOG mode.
Oracleでは、Oracle Databaseに重要な変更を加える前に必ずOracle Databaseをバ ッ ク ア ッ プすることを推奨しています。ARCHIVELOGモードを有効にする前に、 次のコマンドを使用してOracleデータベースのバックアップを作成します。
RMAN> backup database;
Starting backup at 07-AUG-23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=/opt/oracle/oradata/CDB1/sysaux01.dbf
input datafile file number=00001 name=/opt/oracle/oradata/CDB1/system01.dbf
input datafile file number=00004 name=/opt/oracle/oradata/CDB1/undotbs01.dbf
input datafile file number=00007 name=/opt/oracle/oradata/CDB1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/01237tdk_1_1_1 tag=TAG20230807T165204 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00012 name=/opt/oracle/oradata/CDB1/PDB1/users01.dbf
input datafile file number=00010 name=/opt/oracle/oradata/CDB1/PDB1/sysaux01.dbf
input datafile file number=00011 name=/opt/oracle/oradata/CDB1/PDB1/undotbs01.dbf
input datafile file number=00009 name=/opt/oracle/oradata/CDB1/PDB1/system01.dbf
input datafile file number=00013 name=/opt/oracle/homes/OraDB21Home1/dbs/octs.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/02237ten_2_1_1 tag=TAG20230807T165204 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/opt/oracle/oradata/CDB1/pdbseed/sysaux01.dbf
input datafile file number=00008 name=/opt/oracle/oradata/CDB1/pdbseed/undotbs01.dbf
input datafile file number=00005 name=/opt/oracle/oradata/CDB1/pdbseed/system01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/03237tg4_3_1_1 tag=TAG20230807T165204 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 07-AUG-23
Starting Control File and SPFILE Autobackup at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/c-1058798813-20230807-00 comment=NONE
Finished Control File and SPFILE Autobackup at 07-AUG-23
RMAN> alter database archivelog;
Statement processed
RMAN> alter database open;
Statement processed
Use the following command to back up the Oracle Database. As the Oracle Database is now in ARCHIVELOG mode, you can back up the Oracle Database while the Oracle Database is open.
Oracleデータベースをバックアップするには、次のコマンドを使用します。Oracleデータベースが ARCHIVELOGモードになっているので、Oracleデータベースを開いている間はバックアップできます。
RMAN> backup database plus archivelog;
Starting backup at 07-AUG-23
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=164 RECID=1 STAMP=1144256683
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/05237u5c_5_1_1 tag=TAG20230807T170444 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-23
Starting backup at 07-AUG-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00003 name=/opt/oracle/oradata/CDB1/sysaux01.dbf
input datafile file number=00001 name=/opt/oracle/oradata/CDB1/system01.dbf
input datafile file number=00004 name=/opt/oracle/oradata/CDB1/undotbs01.dbf
input datafile file number=00007 name=/opt/oracle/oradata/CDB1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/06237u5d_6_1_1 tag=TAG20230807T170445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00012 name=/opt/oracle/oradata/CDB1/PDB1/users01.dbf
input datafile file number=00010 name=/opt/oracle/oradata/CDB1/PDB1/sysaux01.dbf
input datafile file number=00011 name=/opt/oracle/oradata/CDB1/PDB1/undotbs01.dbf
input datafile file number=00009 name=/opt/oracle/oradata/CDB1/PDB1/system01.dbf
input datafile file number=00013 name=/opt/oracle/homes/OraDB21Home1/dbs/octs.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/07237u66_7_1_1 tag=TAG20230807T170445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/opt/oracle/oradata/CDB1/pdbseed/sysaux01.dbf
input datafile file number=00008 name=/opt/oracle/oradata/CDB1/pdbseed/undotbs01.dbf
input datafile file number=00005 name=/opt/oracle/oradata/CDB1/pdbseed/system01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/08237u6v_8_1_1 tag=TAG20230807T170445 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 07-AUG-23
Starting backup at 07-AUG-23
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=165 RECID=2 STAMP=1144256750
channel ORA_DISK_1: starting piece 1 at 07-AUG-23
channel ORA_DISK_1: finished piece 1 at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/09237u7e_9_1_1 tag=TAG20230807T170550 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-23
Starting Control File and SPFILE Autobackup at 07-AUG-23
piece handle=/opt/oracle/homes/OraDB21Home1/dbs/c-1058798813-20230807-01 comment=NONE
Finished Control File and SPFILE Autobackup at 07-AUG-23
フラッシュバックを有効化する方法
You can revert the whole Oracle Database to a prior point in time using the following ways: either revert the whole Oracle Database to a prior point in time by restoring a backup and performing a point-in-time recovery or enable flashback database. When you enable flashback database, the Oracle Database generates flashback logs in the fast recovery area. These logs are used to flashback the Oracle Database to a specified time. The Oracle Database automatically creates, deletes, and resizes flashback logs.
バックアップを復元してポイントインタイムリカバリを実行するか、またはフラッシュバックデータベースを有効にするかです。フラッシュバックデータベースを有効にすると、Oracle Databaseは高速リカバリ領域にフラッシュバックログを生成します。これらのログは、Oracle Databaseを指定した時点にフラッシュバックするために使用されます。Oracle Databaseはフラッシュバックログを自動的に作成、削除、およびサイズ変更します。
RMAN> alter database flashback on;
RMAN> exit;
RMANの永続設定を確認する
[CDB1:oracle@dbhol:/opt/oracle/product/21c/dbhome_1/bin]$ ./rman
Recovery Manager: Release 21.0.0.0.0 - Production on Mon Aug 7 17:46:46 2023
Version 21.4.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target;
connected to target database: CDB1 (DBID=1058798813)
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name CDB1 are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/dbs/snapcf_CDB1.f'; # default
全ての永続設定がデフォルトになっていることが分かった
保存ポリシーについて
RMAN> configure retention policy to recovery window of 31 days;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 31 DAYS;
new RMAN configuration parameters are successfully stored
RMAN> show retention policy;
RMAN configuration parameters for database with db_unique_name CDB1 are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 31 DAYS;
バックアップの最適化設定について
Configure backup optimization to save space in the fast recovery area. Optimization excludes unchanged files, such as read-only files and offline data files, that were previously backed up.
RMAN> configure backup optimization on;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
RMAN> show backup optimization;
RMAN configuration parameters for database with db_unique_name CDB1 are:
CONFIGURE BACKUP OPTIMIZATION ON;
デフォルトデバイスタイプについて
例えばデフォルトデバイスタイプをディスクに設定する
RMAN> configure default device type to disk;
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters are successfully stored
RMAN> show default device type;
RMAN configuration parameters for database with db_unique_name CDB1 are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
showコマンドで実際にデフォルトデバイスタイプがディスクになっていことを確認できた
自動バックアップについて
you can configure RMAN to automatically backup the control file and server parameter file with every backup. This is referred to as an autobackup. The control and server parameter files are critical to the Oracle Database and RMAN. Creating automatic backups of the control file enables RMAN to recover the Oracle Database even if the current control file and server parameter file are lost. The control and server parameter files are relatively small compared to typical data files and, therefore, backing them up frequently results in relatively little storage overhead.
If the Oracle Database runs in ARCHIVELOG mode, an automatic backup is also taken whenever the Oracle Database structure metadata in the control file changes.
バックアップのたびに制御ファイルとサーバーパラメータファイルを自動的にバックアップするようにRMANを設定できます。これは自動バックアップと呼ばれます。制御ファイルおよびサーバーパラメータファイルは、OracleデータベースとRMANにとって重要です。制御ファイルの自動バックアップを作成することで、現在の制御ファイルとサーバーパラメータファイルが失われても、RMANはOracleデータベースを復旧できます。制御ファイルおよびサーバーパラメータファイルは、一般的なデータファイルと比較すると比較的小さいため、頻繁にバックアップを実行してもストレージのオーバーヘッドは比較的小さくなります。
OracleデータベースがARCHIVELOGモードで実行されている場合、制御ファイル内のOracleデータベース構造メタデータが変更されるときに自動バックアップが実行されます。
RMAN> configure controlfile autobackup on;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
RMAN> show controlfile autobackup;
RMAN configuration parameters for database with db_unique_name CDB1 are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
自動ブロックチェンジトラッキングについて
Block change tracking improves the performance of incremental backups by recording changed blocks in the block change tracking file. During an incremental backup, instead of scanning all data blocks to identify which blocks have changed, RMAN uses this file to identify the changed blocks that need to be backed up.
You can enable block change tracking when the Oracle Database is either open or mounted. This section assumes that you intend to create the block change tracking file as an Oracle-managed file in the database area, where the Oracle Database maintains active database files such as data files, control files, and online redo log files.
メモ: incremental backup = 増分バックアップ
ブロック変更追跡は、変更されたブロックをブロック変更追跡ファイルに記録して、増分バックアップのパフォーマンスを向上させます。増分バックアップ中、全てのデータブロックをスキャンして変更されたブロックを特定するのではなく、RMANはこのファイルを使用してバックアップが必要な変更ブロックを特定します。
ブロック変更追跡は、Oracle Databaseがオープンまたはマウントされているときに有効にできます。このセクションでは、Oracleデータベースがデータベースファイル、制御ファイル、オンラインREDOログファイルなどのアクティブデータベースファイルを保持するデータベース領域に、Oracle管理ファイルとしてブロック変更追跡ファイルを作成することを想定しています。
SQL> alter system set db_create_file_dest = '/opt/oracle/oradata/CDB1';
System altered.
db_create_file_destは、Oracleが管理するファイルのデフォルトの格納場所を指定します。このラボでは、db_create_file_destパラメータはデータファイルと制御ファイルの格納場所である/opt/oracle/oradata/CDB1に設定されます。
SQL> alter database enable block change tracking;
Database altered.
SQL> select status, filename from v$block_change_tracking;
STATUS
----------
FILENAME
--------------------------------------------------------------------------------
ENABLED
/opt/oracle/oradata/CDB1/CDB1/changetracking/o1_mf_lfs0y2d5_.chg
続く・・・
今日はここまでにします。