こんにちはユキトモです。
今回は、Oracleの制御ファイル(コントロールファイル)を解説していきます。
制御ファイル
制御ファイルはOracleデータベースの物理構造を記録したバイナリファイルです。
記録されている内容は
内容
・データベース名
・対応するデータファイルとREDOログファイルの名前と位置
・データベース作成のタイムスタンプ
・現行のログ順序番号
・チェックとポイント情報
・制御ファイルは最低1つ必要です。
・推奨としては複数のコピーを作成して多重化することが望ましい。
 
制御ファイル名および配置場所を取得
配置場所
SELECT name FROM v$controlfile;
制御ファイルのフルパスとファイル名は上記のSQL文で取得できます。
制御ファイルはデータベース作成時に作られます。
デフォルトで作成される制御ファイルの数はOSによって異なります。
 
SPFILEから情報を取得
SPFILEから情報を取得
col name for a13
col value for a50
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
SPFILE(サーバ・パラメータ・ファイル)から制御ファイルの情報を取得するには上記のSELECT文で取得できます。
 
関連項目>> 現在有効なSPFILEの内容を動的パフォーマンスビューから表示するには
 
初期化パラメータに制御ファイルを指定する
初期化パラメータに制御ファイルを指定
ALTER SYSTEM SET control_files =
'/opt/oracle/oradata/ORCLCDB/control01.ctl',
'/opt/oracle/oradata/ORCLCDB/control02.ctl'
SCOPE = SPFILE;
control_filesは静的パラメータですので、必ずSCOPE = SPFILEを指定します。
すでに稼働中のデータベースで制御ファイルの初期化パラメータ値を変更・追加する場合はOSのコピーコマンドを使って制御ファイルをコピーします。
 
実行例
--変更前の状態を確認
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
 
--ファイルをコピー
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
SQL> !cp /opt/oracle/oradata/ORCLCDB/control01.ctl /opt/oracle/oradata/ORCLCDB/control03.ctl
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
 
--変更されていないことを確認
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
 
--追加する
ALTER SYSTEM SET control_files =
'/opt/oracle/oradata/ORCLCDB/control01.ctl',
'/opt/oracle/oradata/ORCLCDB/control02.ctl',
'/opt/oracle/oradata/ORCLCDB/control03.ctl'
SCOPE = SPFILE;
 
--確認
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
control_files /opt/oracle/oradata/ORCLCDB/control03.ctl
関連項目>> SPFILE使用時に静的パラメータ値を変更するには
 
既存の制御ファイルの複製を作成
既存の制御ファイルの複製を作成
--例
ALTER DATABASE BACKUP CONTROLEFILE TO
'/opt/oracle/oradata/ORCLCDB/<バックアップファイル名>';
 
実行例
 
--複製前の確認
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
control_files /opt/oracle/oradata/ORCLCDB/control03.ctl
 
--複製する
ALTER DATABASE BACKUP CONTROLFILE TO
'/opt/oracle/oradata/ORCLCDB/control.bkp';
 
--確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
 
 
制御ファイルをリストアできるSQL文を生成
制御ファイルをリストアできるSQL文を生成
 
--出力先を指定するにはAS <フルパス+ファイル名>を指定する
--例
ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '/opt/oracle/oradata/ORCLCDB/control01.sql';
 
--ファイルを確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/*.sql
 
--内容を確認
SQL> !cat /opt/oracle/oradata/ORCLCDB/control01.sql
 
+ 実行結果はこちら</b><b>
command
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 日 12月 26 11:48:42 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
に接続されました。
--配置場所確認 v$controlfile
SQL> SELECT name FROM v$controlfile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/ORCLCDB/control01.ctl
/opt/oracle/oradata/ORCLCDB/control02.ctl
 
--配置場所確認 v$spparameter
SQL> col name for a13
col value for a50
SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
SQL> SQL> 2 3
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
 
--コピー前確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:11 /opt/oracle/oradata/ORCLCDB/control01.ctl
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:11 /opt/oracle/oradata/ORCLCDB/control02.ctl
 
--コピーする
SQL> !cp /opt/oracle/oradata/ORCLCDB/control01.ctl /opt/oracle/oradata/ORCLCDB/control03.ctl
 
コピー後確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:12 /opt/oracle/oradata/ORCLCDB/control01.ctl
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:12 /opt/oracle/oradata/ORCLCDB/control02.ctl
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:12 /opt/oracle/oradata/ORCLCDB/control03.ctl
 
--追加前確認
SQL> SELECT name ,value
2 FROM v$spparameter
3 WHERE name = 'control_files';
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
 
--追加する
SQL> ALTER SYSTEM SET control_files =
'/opt/oracle/oradata/ORCLCDB/control01.ctl',
'/opt/oracle/oradata/ORCLCDB/control02.ctl',
'/opt/oracle/oradata/ORCLCDB/control03.ctl'
SCOPE = SPFILE;
2 3 4 5
システムが変更されました。
 
--追加後確認
SQL> SELECT name ,value
FROM v$spparameter
WHERE name = 'control_files';
2 3
NAME VALUE
------------- --------------------------------------------------
control_files /opt/oracle/oradata/ORCLCDB/control01.ctl
control_files /opt/oracle/oradata/ORCLCDB/control02.ctl
control_files /opt/oracle/oradata/ORCLCDB/control03.ctl
 
--バックアップを取得する
SQL>
SQL> ALTER DATABASE BACKUP CONTROLFILE TO
'/opt/oracle/oradata/ORCLCDB/control.bkp';
2
データベースが変更されました。
 
バックアップ後確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/control*
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:32 /opt/oracle/oradata/ORCLCDB/control.bkp
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:33 /opt/oracle/oradata/ORCLCDB/control01.ctl
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:33 /opt/oracle/oradata/ORCLCDB/control02.ctl
-rw-r-----. 1 oracle oinstall 18726912 12月 26 12:12 /opt/oracle/oradata/ORCLCDB/control03.ctl
 
--既存のファイルをリストアできるSQL文を生成する
--バックアップ先ディレクトリ確認
--出力先を指定するにはAS <フルパス+ファイル名>を指定する
--例
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '/opt/oracle/oradata/ORCLCDB/control01.sql';
データベースが変更されました。
 
--確認
SQL> !ls -l /opt/oracle/oradata/ORCLCDB/*.sql
-rw-r--r--. 1 oracle oinstall 7384 12月 26 13:01 /opt/oracle/oradata/ORCLCDB/control01.sql
 
生成されたsqlファイルの内容を確認
SQL> !cat /opt/oracle/oradata/ORCLCDB/control01.sql
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="ORCLCDB"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/opt/oracle/product/19c/dbhome_1/dbs/arch'
-- LOG_ARCHIVE_DEST_1='MANDATORY REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER'
-- LOG_ARCHIVE_DEST_1='NOALTERNATE'
-- LOG_ARCHIVE_DEST_1='NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
-- Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCLCDB" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/opt/oracle/oradata/ORCLCDB/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/opt/oracle/oradata/ORCLCDB/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/opt/oracle/oradata/ORCLCDB/redo03.log' SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/opt/oracle/oradata/ORCLCDB/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/users01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/19c/dbhome_1/dbs/arch1_1_1005785759.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/19c/dbhome_1/dbs/arch1_1_1061726795.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Open all the PDBs.
ALTER PLUGGABLE DATABASE ALL OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/temp01.dbf'
SIZE 33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "PDB$SEED";
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/temp012021-01-13_12-11-56-692-PM.dbf'
SIZE 37748736 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "ORCLPDB1";
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/temp01.dbf' REUSE;
ALTER SESSION SET CONTAINER = "CDB$ROOT";
-- End of tempfile additions.
--
-- Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCLCDB" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/opt/oracle/oradata/ORCLCDB/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/opt/oracle/oradata/ORCLCDB/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/opt/oracle/oradata/ORCLCDB/redo03.log' SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/opt/oracle/oradata/ORCLCDB/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/users01.dbf',
'/opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf',
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/19c/dbhome_1/dbs/arch1_1_1005785759.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/opt/oracle/product/19c/dbhome_1/dbs/arch1_1_1061726795.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Open all the PDBs.
ALTER PLUGGABLE DATABASE ALL OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/temp01.dbf'
SIZE 33554432 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "PDB$SEED";
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/temp012021-01-13_12-11-56-692-PM.dbf'
SIZE 37748736 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "ORCLPDB1";
ALTER TABLESPACE TEMP ADD TEMPFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/temp01.dbf' REUSE;
ALTER SESSION SET CONTAINER = "CDB$ROOT";
-- End of tempfile additions.
--
以上です。