1:主庫上開啟Forced Logging
alter database force logging;
scp /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwahqy 192.168.100.118:/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwahqy
select member from v$logfile; du -h /home/oracle/oradata/ahqy/redo01.log sqlplus / as sysdba mkdir standby alter database add standby logfile group 4 '/home/oracle/oradata/ahqy/standby/standby04.log' size 200M; alter database add standby logfile group 5 '/home/oracle/oradata/ahqy/standby/standby05.log' size 200M; alter database add standby logfile group 6 '/home/oracle/oradata/ahqy/standby/standby06.log' size 200M;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(ahqy,standby)'; alter system set log_archive_dest_1='LOCATION=/home/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=ahqy' scope=spfile; alter system set log_archive_dest_2='service=standby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=standby' scope=spfile; alter system set log_archive_dest_state_1=enable; alter system set log_archive_dest_state_2=enable; alter system set log_archive_format='%t_%s_%r.arc' scope=spfile; show parameter remote_login; alter system set log_archive_max_processes=30; alter system set fal_server=standby; alter system set fal_client=ahqy; alter system set standby_file_management=auto; shutdown immediate; startup;
cat /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin//tnsnames.ora # tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. LISTENER_AHQY = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) AHQY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ahqy) ) ) STANDBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.118)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) )
mkdir -p /home/oracle/backup/ create pfile='/home/oracle/backup/initahqy.ora' from spfile; rman target / backup tag 'dg_20141226' format '/home/oracle/backup/dg_%U' incremental level 0 database plus archivelog; backup format '/home/oracle/backup/controlfile_%U' current controlfile for standby;
echo $ORACLE_SID scp /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora [email protected]:/home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
mkdir -p /home/oracle/backup/ scp -rp [email protected]:/home/oracle/backup/* /home/oracle/backup/ cp /home/oracle/backup/initahqy.ora $ORACLE_HOME/dbs grep 'fal_' $ORACLE_HOME/dbs/initahqy.ora *.fal_client='STANDBY' *.fal_server='AHQY' grep 'log_archive_dest_' $ORACLE_HOME/dbs/initahqy.ora *.log_archive_dest_1='LOCATION=/home/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=standby' *.log_archive_dest_2='service=ahqy lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=ahqy' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.db_unique_name='standby' ----------------------------這一句漏了,導致默認成了AHQY,一定要加上 *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(standby,ahqy)' --主備庫切換用,否則切換會有問題 ---alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(standby,ahqy)'; mkdir -p /home/oracle/arch/ahqy mkdir -p /home/oracle/app/oracle/admin/ahqy/{adump,bdump,cdump,dpdump,udump,pfile} --有幾個文件夾可能用不到 mkdir -p /home/oracle/oradata/ahqy mkdir -p /u01/app/oracle/flash_recover_area/ORCL --未找到 --(將相應的主庫文件直接移到了備庫上,如:/home/oracle/arch/、/home/oracle/oradata/、/home/oracle/oradiag_oracle) mkdir -p /home/oracle/app/oracle/diag/rdbms/ahqy/ahqy/{alert,cdump,hm,incident,incpkg,ir,lck,metadata,stage,sweep,trace} 考慮到可能有文件夾沒有建,所以我這裡將幾個主要文件夾直接從主庫拷貝到備庫相應的目錄中去。
sqlplus / as sysdba startup nomount;
rman target sys/ORACLE@AHQY auxiliary / duplicate target database for standby nofilenamecheck;
sqlplus / as sysdba archive log list; alter database recover managed standby database disconnect from session; select SEQUENCE#,FIRST_TIME,NEXT_TIME,APPLIED from v$archived_log; select member from v$logfile; 可以在主庫上進行日志切換,加快備庫應用日志的速度! sqlplus / as sysdba alter system switch logfile; archive log list; 備庫上再次查詢: select SEQUENCE#,FIRST_TIME,NEXT_TIME,APPLIED from v$archived_log; select name,database_role from v$database;
select name,database_role from v$database; create tablespace ahqy datafile '/home/oracle/oradata/ahqy/ahqy.dbf' size 10M autoextend on; create table dg01 as select * from dba_source; alter system switch logfile;
alter database recover managed standby database cancel; alter database open read only; select type from dg01;
sqlplus / as sysdba shutdown immediate; startup nomount; alter database mount standby database; alter database recover managed standby database disconnect from session;
select open_mode,database_role,db_unique_name from v$database;
alter database recover managed standby database cancel;
alter database open; select open_mode from v$database; alter database recover managed standby database using current logfile disconnect; select open_mode,database_role,db_unique_name from v$database;
alter database commit to switchover to physical standby with session shutdown; shutdown immediate startup mount alter database recover managed standby database disconnect from session;
shutdown immediate startup mount alter database commit to switchover to primary; alter database open;
[oracle@118 admin]$ cat listener.ora # listener.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.118)(PORT = 1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1) (PROGRAM = extproc) ) (SID_DESC = (SID_NAME = ahqy) (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1) (GLOBAL_DBNAME = standby) ) ) ADR_BASE_LISTENER = /home/oracle/app/oracle [oracle@117 admin]$ cat listener.ora # listener.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1) (PROGRAM = extproc) ) (SID_DESC = (SID_NAME = ahqy) (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1) (GLOBAL_DBNAME = ahqy) ) ) ADR_BASE_LISTENER = /home/oracle/app/oracle
[oracle@117 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. LISTENER_AHQY = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) AHQY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ahqy) ) ) standby = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.118)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) ) [oracle@118 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. LISTENER_AHQY = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) AHQY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.117)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ahqy) ) ) STANDBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.118)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) )