Oracle 11gR2 dataguard搭建說明 --- rman方式
阿新 • • 發佈:2018-12-25
1.配置引數檔案
主庫引數檔案
INCA.__db_cache_size=18589155328 INCA.__java_pool_size=134217728 INCA.__large_pool_size=201326592 INCA.__oracle_base='/ora/app/oracle'#ORACLE_BASE set from environment INCA.__pga_aggregate_target=3422552064 INCA.__sga_target=21474836480 INCA.__shared_io_pool_size=0 INCA.__shared_pool_size=2348810240 INCA.__streams_pool_size=67108864 *.audit_file_dest='/ora/app/oracle/admin/INCA/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/data/INCA/control01.ctl','/data/INCA/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='INCA' *.diagnostic_dest='/ora/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=INCAXDB)' *.job_queue_processes=1000 *.log_archive_dest_1='LOCATION=/data/arch' *.log_archive_format='%t_%s_%r.arc' *.open_cursors=300 *.pga_aggregate_target=3365928960 *.processes=3000 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=3305 *.sga_max_size=27917287424 *.sga_target=21474836480 *.undo_tablespace='UNDOTBS1' #dg_parameter *.db_file_name_convert='/data/INCA','/data/incadg' *.db_unique_name='INCA' *.fal_client='INCA' *.fal_server='incadg' *.log_archive_config='DG_CONFIG=(INCA,incadg)' *.log_archive_dest_1='LOCATION=/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=INCA' *.log_archive_dest_2='SERVICE=incadg ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=incadg COMPRESSION=ENABLE' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.log_archive_format='%t_%s_%r.arc' *.log_archive_max_processes=30
備庫引數檔案
incadg.__db_cache_size=8589934592 incadg.__java_pool_size=134217728 incadg.__large_pool_size=201326592 incadg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment incadg.__pga_aggregate_target=838860800 incadg.__sga_target=12884901888 incadg.__shared_io_pool_size=0 incadg.__shared_pool_size=1073741824 incadg.__streams_pool_size=67108864 *.audit_file_dest='/u01/app/oracle/admin/incadg/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/data/incadg/control01.ctl','/data/incadg/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='inca' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=INCAXDB)' *.job_queue_processes=1000 *.log_archive_dest_1='LOCATION=/data/arch' *.log_archive_format='%t_%s_%r.arc' *.open_cursors=300 *.pga_aggregate_target=838860800 *.processes=3000 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=3305 *.sga_max_size=12884901888 *.sga_target=12884901888 *.undo_tablespace='UNDOTBS1' #dg_parameter *.db_file_name_convert='/data/INCA','/data/incadg' *.db_unique_name='incadg' *.fal_client='incadg' *.fal_server='INCA' *.log_archive_config='DG_CONFIG=(INCA,incadg)' *.log_archive_dest_1='LOCATION=/data/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=incadg' *.log_archive_dest_2='SERVICE=INCA ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=INCA COMPRESSION=ENABLE' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.log_archive_format='%t_%s_%r.arc' *.log_archive_max_processes=30
2.備庫建立adump、dpdump、pfile目錄
mkdir /u01/app/oracle/admin/incadg/adump
mkdir /u01/app/oracle/admin/incadg/dpdump
mkdir /u01/app/oracle/admin/incadg/pfile
3.備份主庫
source /home/oracle/.bash_profile export DB_BASE=$ORACLE_BASE export DB_HOME=$ORACLE_HOME export OPATCH=$ORACLE_HOME/OPatch LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/share/lib CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/jdbc/lib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib PATH=$PATH:$ORACLE_HOME/bin:$OPATCH export CLASSPATH export LD_LIBRARY_PATH export dt=`date +%Y%m%d` export PATH rman target / log=/backup/cerptraindb/log/cerptraindb_$dt.log <<eof RUN { ALLOCATE CHANNEL t1 TYPE disk maxpiecesize=20480m; ALLOCATE CHANNEL t2 TYPE disk maxpiecesize=20480m; ALLOCATE CHANNEL t3 TYPE disk maxpiecesize=20480m; ALLOCATE CHANNEL t4 TYPE disk maxpiecesize=20480m; BACKUP format '/backup/cerptraindb/rman/%d_%s_%p_%T.bak' DATABASE; sql 'alter system archive log current'; backup format '/backup/cerptraindb/rman/%d_%s_%p_%T.arc' archivelog all delete all input; release channel t1; release channel t2; release channel t3; release channel t4; ALLOCATE CHANNEL c1 TYPE disk; ALLOCATE CHANNEL c2 TYPE disk; backup spfile include current controlfile format '/backup/cerptraindb/rman/%d_%s_%p_%T.ctl'; release channel c1; release channel c2; } exit; eof
4.同步密碼檔案
scp /ora/app/oracle/product/11.2.0/dbhome_1/dbs/orapwINCA cerp01:/u01/app/oracle/product/11.2.0/db_1/orapwincadg
5.恢復備庫
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
set until sequence 1175 thread 1;
set newname for datafile 1 to '/data/incadg/system01.dbf';
set newname for datafile 2 to '/data/incadg/sysaux01.dbf';
set newname for datafile 3 to '/data/incadg/undotbs01.dbf';
set newname for datafile 4 to '/data/incadg/users01.dbf';
set newname for datafile 5 to '/data/incadg/tasly20180102_01.dbf';
set newname for datafile 6 to '/data/incadg/tasly20180102_02.dbf';
set newname for datafile 7 to '/data/incadg/tasly20180102_index_01.dbf';
set newname for datafile 8 to '/data/incadg/cerpzs.dbf';
set newname for datafile 9 to '/data/incadg/cerpzs_index.dbf';
set newname for datafile 10 to '/data/incadg/tasly20180123_01.dbf';
set newname for datafile 11 to '/data/incadg/tasly20180123_02.dbf';
set newname for datafile 12 to '/data/incadg/tasly20180123_index_01.dbf';
set newname for datafile 13 to '/data/incadg/tasly20180123_index_02.dbf';
set newname for tempfile 1 to '/data/incadg/temp01.dbf';
restore database;
switch datafile all;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
6.主庫建立standby控制檔案
#建立standby_controlfile
SQL> alter database create standby controlfile as '/home/oracle/incadg.ctl';
#複製備機控制檔案
scp /home/oracle/incadg.ctl cerp01:/home/oracle/incadg.ctl
7.備庫使用pfile啟動資料庫
startup mount pfile=’ /u01/app/oracle/product/11.2.0/db_1/dbs/initincadg.ora’;
8.恢復備庫
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
set until sequence 1175 thread 1;
set newname for datafile 1 to '/data/incadg/system01.dbf';
set newname for datafile 2 to '/data/incadg/sysaux01.dbf';
set newname for datafile 3 to '/data/incadg/undotbs01.dbf';
set newname for datafile 4 to '/data/incadg/users01.dbf';
set newname for datafile 5 to '/data/incadg/tasly20180102_01.dbf';
set newname for datafile 6 to '/data/incadg/tasly20180102_02.dbf';
set newname for datafile 7 to '/data/incadg/tasly20180102_index_01.dbf';
set newname for datafile 8 to '/data/incadg/cerpzs.dbf';
set newname for datafile 9 to '/data/incadg/cerpzs_index.dbf';
set newname for datafile 10 to '/data/incadg/tasly20180123_01.dbf';
set newname for datafile 11 to '/data/incadg/tasly20180123_02.dbf';
set newname for datafile 12 to '/data/incadg/tasly20180123_index_01.dbf';
set newname for datafile 13 to '/data/incadg/tasly20180123_index_02.dbf';
set newname for tempfile 1 to '/data/incadg/temp01.dbf';
restore database;
switch datafile all;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
9.主庫、備庫建立standby redo檔案
主庫:
alter database add standby logfile group 4 ('/data/INCA/standby04.log') size 512M;
alter database add standby logfile group 5 ('/data/INCA/standby05.log') size 512M;
alter database add standby logfile group 6 ('/data/INCA/standby06.log') size 512M;
alter database add standby logfile group 7 ('/data/INCA/standby07.log') size 512M;
alter database add standby logfile group 8 ('/data/INCA/standby08.log') size 512M;
備庫:
alter database add standby logfile group 4 ('/data/incadg/standby04.log') size 512M;
alter database add standby logfile group 5 ('/data/incadg/standby05.log') size 512M;
alter database add standby logfile group 6 ('/data/incadg/standby06.log') size 512M;
alter database add standby logfile group 7 ('/data/incadg/standby07.log') size 512M;
alter database add standby logfile group 8 ('/data/incadg/standby08.log') size 512M;
alter database add standby logfile group 9 ('/data/incadg/standby08.log') size 512M;
10.備庫啟動DG
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
recover managed standby database cancel;
11.檢視DG狀態
SQL> select open_mode,database_role,switchover_status from v$database;
OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
-------------------- ---------------- --------------------
READ WRITE PRIMARY UNRESOLVABLE GAP
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;