003、控制檔案
阿新 • • 發佈:2021-06-21
控制檔案:
1、描述了資料庫的結構和行為
2、位置在引數據檔案的control_files引數中描述
3、最少1個,最多8個
4、所有的控制檔案都是映象關係
5、控制檔案預先分配空間,可以自動增長,也可以建立新的更大的控制檔案
6、mount時讀控制檔案
7、open時一直在使用控制檔案
SQL> select name from v$controlfile; --記錄的是當前例項正在使用的控制檔案 NAME -------------------------------------------------------------------------------- +DATA/ora10g/controlfile/current.256.1043492187 SQL> select value from v$spparameter where name='control_files'; --二進位制引數檔案中,control_files的值記錄的控制檔案的路徑 VALUE -------------------------------------------------------------------------------- +DATA/ora10g/controlfile/current.256.1043492187
增加控制檔案個數
1、修改引數的值:2、重啟資料庫,發現無法啟動,報錯ora-00205:SQL> alter system set control_files= 2 '+DATA/ora10g/controlfile/current.256.1043492187', 3 '/u01/scripts/control02.ctl' 4 scope=spfile; System altered. SQL> select name from v$controlfile; --記錄的是當前例項正在使用的控制檔案 NAME -------------------------------------------------------------------------------- +DATA/ora10g/controlfile/current.256.1043492187 SQL> select value from v$spparameter where name='control_files'; --二進位制引數檔案中,control_files的值記錄的控制檔案的路徑 VALUE -------------------------------------------------------------------------------- +DATA/ora10g/controlfile/current.256.1043492187 /u01/scripts/control02.ctl
檢視alert日誌:SQL> startup; ORACLE instance started. Total System Global Area 599785472 bytes Fixed Size 2098112 bytes Variable Size 167775296 bytes Database Buffers 423624704 bytes Redo Buffers 6287360 bytes ORA-00205: error in identifying control file, check alert log for more info [oracle@rac1 ~]$ oerr ora 00205 00205, 00000, "error in identifying control file, check alert log for more info" // *Cause: The system could not find a control file of the specified name and // size. // *Action: Check that ALL control files are online and that they are the same // files that the system created at cold start time.
……
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/scripts/control02.ctl'
……
複製控制檔案:
--若資料檔案是儲存在檔案系統,或者Oracle版本為11g以上,則可以直接用作業系統命令複製現有的控制檔案:
-- cp +DATA/ora10g/controlfile/current.256.1043492187 /u01/scripts/control02.ctl
--但是oracle 10g asm儲存的檔案,不支援直接用作業系統命令複製,需要通過RMAN恢復的方式複製控制檔案,如下:
RMAN> restore controlfile to '/u01/scripts/control02.ctl' from '+DATA/ora10g/controlfile/current.256.1043492187';
Starting restore at 16-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=146 instance=ora10g1 devtype=DISK
channel ORA_DISK_1: copied control file copy
Finished restore at 16-JUN-21
3、修改資料庫狀態為mount:
SQL> alter database mount;
Database altered.
SQL> select name from v$controlfile; --記錄的是當前例項正在使用的控制檔案
NAME
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
/u01/scripts/control02.ctl
SQL> select value from v$spparameter where name='control_files'; --二進位制引數檔案中,control_files的值記錄的控制檔案的路徑
VALUE
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
/u01/scripts/control02.ctl
減少控制檔案的個數
1、修改引數檔案中,控制檔案的個數SQL> alter system set control_files=
2 '+DATA/ora10g/controlfile/current.256.1043492187'
3 scope=spfile;
System altered.
SQL> select value from v$spparameter where name='control_files';
VALUE
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
2、重啟生效
SQL> shutdown immediate;
SQL> startup mount;
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
SQL> select value from v$spparameter where name='control_files';
VALUE
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
檢視控制檔案的版本號
SQL> select CONTROLFILE_SEQUENCE# from v$database;
CONTROLFILE_SEQUENCE#
---------------------
662
只要資料庫是在OPEN的狀態,控制檔案的版本號就在增長,增長機制:
資料庫發生變化,會先將變化寫進控制檔案,再寫進控制檔案的映象檔案,每寫一次控制檔案,版本號就增加1.
驗證控制檔案最多8個
1、修改控制檔案個數為9個SQL> alter system set control_files=
2 '+DATA/ora10g/controlfile/current.256.1043492187',
3 '/u01/scripts/control02.ctl',
4 '/u01/scripts/control03.ctl',
5 '/u01/scripts/control04.ctl',
6 '/u01/scripts/control05.ctl',
7 '/u01/scripts/control06.ctl',
8 '/u01/scripts/control07.ctl',
9 '/u01/scripts/control08.ctl',
10 '/u01/scripts/control09.ctl'
11 scope=spfile;
System altered.
--檢視引數檔案記錄的個數
SQL> select value from v$spparameter where name='control_files';
VALUE
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
/u01/scripts/control02.ctl
/u01/scripts/control03.ctl
/u01/scripts/control04.ctl
/u01/scripts/control05.ctl
/u01/scripts/control06.ctl
/u01/scripts/control07.ctl
/u01/scripts/control08.ctl
/u01/scripts/control09.ctl
9 rows selected.
RMAN> shutdown immediate
2、複製控制檔案
--若資料檔案是儲存在檔案系統,或者Oracle版本為11g以上,則可以直接用作業系統命令複製現有的控制檔案:
-- cp +DATA/ora10g/controlfile/current.256.1043492187 /u01/scripts/control02.ctl
--但是oracle 10g asm儲存的檔案,不支援直接用作業系統命令複製,需要通過RMAN恢復的方式複製控制檔案,如下:
RMAN> startup nomount
RMAN> restore controlfile to '/u01/scripts/control02.ctl' from '+DATA/ora10g/controlfile/current.256.1043492187';
Starting restore at 16-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=146 instance=ora10g1 devtype=DISK
channel ORA_DISK_1: copied control file copy
Finished restore at 16-JUN-21
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control03.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control04.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control05.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control06.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control07.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control08.ctl
[oracle@rac1 ~]$ cp /u01/scripts/control02.ctl /u01/scripts/control09.ctl
3、修改資料庫狀態為mount,並檢視報錯:
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
檢視alert日誌:
……
Errors in file /u01/app/oracle/admin/ora10g/bdump/ora10g1_ckpt_1980.trc:
ORA-00208: number of control file names exceeds limit of 8
……
Shutting down instance (abort)
License high water mark = 4
Wed Jun 16 21:48:54 CST 2021
Instance terminated by CKPT, pid = 1980
Wed Jun 16 21:48:58 CST 2021
Instance terminated by USER, pid = 12271
說明控制檔案個數最多為8個。
4、修改引數,將control_files引數記錄的個數修改為少於8個
SQL> startup nomount
SQL> select value from v$spparameter where name='control_files';
VALUE
--------------------------------------------------------------------------------
……
9 rows selected.
--查詢,可以直接修改control_files引數
--或者修改文字的引數檔案,並轉化成spfile
修改文字的引數檔案:
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/10.2.0
/db_1/dbs/spfileora10g1.ora
SQL> create pfile='/u01/scripts/initora10g1.ora' from spfile='/u01/app/oracle/product/10.2.0/db_1/dbs/spfileora10g1.ora';
File created.
[oracle@rac1 ~]$ vi /u01/scripts/initora10g1.ora
……
*.control_files='+DATA/ora10g/controlfile/current.256.1043492187'
……
SQL> create spfile='+data/ora10g/spfileora10g.ora' from pfile='/u01/scripts/initora10g1.ora';
File created.
[oracle@rac1 bdump]$ cd $ORACLE_HOME/dbs
[oracle@rac1 dbs]$ rm spfileora10g1.ora
5、重新啟動資料庫:
SQL> shutdown immediate
SQL> startup
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/ora10g/spfileora10g.ora
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
SQL> select value from v$spparameter where name='control_files';
VALUE
--------------------------------------------------------------------------------
+DATA/ora10g/controlfile/current.256.1043492187
建立控制檔案
1、產生建立控制檔案的指令碼到udump目錄:SQL> alter database backup controlfile to trace;
Database altered.
--檔名為sid_ora_pid.trc
--檢視當前會話的程序號:
SQL> select spid from v$process where addr=(
2 select paddr from v$session where sid=(
3 select sid from v$mystat where rownum=1));
SPID
------------
20503
SQL> show parameter dump;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_core_dump string partial
background_dump_dest string /u01/app/oracle/admin/ora10g/bdump
core_dump_dest string /u01/app/oracle/admin/ora10g/cdump
max_dump_file_size string UNLIMITED
shadow_core_dump string partial
user_dump_dest string /u01/app/oracle/admin/ora10g/udump
2、產生建立控制檔案的指令碼到指定目錄:
--SQL> alter database backup controlfile to trace as '/u01/scripts/createcontrolfile.txt' reuse; --reuse代表覆蓋已存在的檔案
SQL> alter database backup controlfile to trace as '/u01/scripts/createcontrolfile.txt';
Database altered.
3、檢視指令碼內容:
[oracle@rac1 ~]$ vi /u01/scripts/createcontrolfile.txt
……
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORA10G" NORESETLOGS ARCHIVELOG
MAXLOGFILES 192 --這幾個max..就是預先分配空間
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 32
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '+DATA/ora10g/onlinelog/group_1.257.1043492187' SIZE 50M,
GROUP 2 '+DATA/ora10g/onlinelog/group_2.258.1043492189' SIZE 50M,
GROUP 3 '+DATA/ora10g/onlinelog/group_3.265.1043492623' SIZE 50M,
GROUP 4 '+DATA/ora10g/onlinelog/group_4.266.1043492625' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'+DATA/ora10g/datafile/system.259.1043492191',
'+DATA/ora10g/datafile/undotbs1.260.1043492199',
'+DATA/ora10g/datafile/sysaux.261.1043492199',
'+DATA/ora10g/datafile/undotbs2.263.1043492205',
'+DATA/ora10g/datafile/users.264.1043492207',
'+DATA/ora10g/goldengate/goldengate01.dbf'
CHARACTER SET ZHS16GBK
;
……
--不要忘記新增臨時檔案等內容