11gRAC对单机dataguard

主库unique_name test 
备库unique_name orcl


查看是否为归档模式
SQL> archive log list  
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +FRA
Oldest online log sequence     5
Next log sequence to archive   8
Current log sequence           8
如果不是则修改为归档模式,将数据库启动到MOUNT状态,将数据库修改为归档模式后建数据库启动到OPEN状态。
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
SQL> alter database force logging;  (强制产生日志)


修改主备库的hosts文件
12.68.10.45  rac1
12.68.10.46  rac2


12.68.10.47  rac1-vip
12.68.10.48  rac2-vip


12.68.12.83    rac1-priv
12.68.12.239    rac2-priv


12.68.10.49   scan


12.68.10.100   orcl


修改主库参数:
SQL>create pfile='/backup/pfile.ora' from spfile; 
SQL>alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(test,orcl)'; 
SQL>alter system set LOG_ARCHIVE_DEST_1='LOCATION=+FRA VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=test'; 
SQL>alter system set LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl';
SQL>alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;    
SQL>alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;    
SQL>alter system set FAL_SERVER=orcl;   
SQL>alter system set FAL_CLIENT=test;
SQL>alter system set STANDBY_FILE_MANAGEMENT=auto scope=spfile;
备份主库
[oracle@dg1 ~]$ rman target /
RMAN>backup full database format '/backup/backup_%T_%s_%p.bak'; 
RMAN>sql "alter system archive log current";
RMAN>backup archivelog all format='/backup/arch_%T_%s_%p.bak';
在主库上建立备库控制文件(控制文件通常需要有多份,手工将文件复制几份)
$sqlplus / as sysdba
SQL>alter database create standby controlfile as '/backup/stdby_control01.ctl';
把主库的密码文件拷贝到下面的目录下
[oracle@dg1 backup]$ cd $ORACLE_HOME
[oracle@dg1 dbhome_1]$ cd dbs
[oracle@dg1 dbs]$ cp orapwtest1 /backup/
[oracle@dg1 backup]$ scp * oracle@orcl:/backup/
#/backup 下应该有参数文件,密码文件,控制文件


备库
[oracle@dg2 backup]$ cp orapwdg1 $ORACLE_HOME/dbs/orapwdg2密码文件传到备库中,必须和备库的实例名一样(orapw实例名)


修改主备库的tnsnames.ora,备库如果没有的话从主库复制过去。tnsnames.ora在[oracle@dg1]$ cd $ORACLE_HOME/network/admin  下。 
TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 12.68.10.47)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 12.68.10.48)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test)
    )
  )


ORCL=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 12.68.10.100)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )


修改pfile.ora 文件。删除dg1开头的,保留*开头的。
*.audit_file_dest='/u01/app/oracle/admin/test/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/data/orcl/controlfile/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest=''
*.db_domain=''
*.db_files=2000
*.db_name='test'
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testXDB)'
*.log_archive_dest_1='LOCATION=/data/arch/'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=314572800
*.processes=1500
*.remote_login_passwordfile='exclusive'
*.sessions=1655
*.sga_target=1258291200
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
~
启动到nomount状态,修改参数
SQL>startup nomount pfile='/backup/pfile.ora';
SQL>create spfile from pfile='/backup/pfile.ora';
SQL>startup nomount force;
SQL>alter system set db_unique_name=orcl scope=spfile;
SQL>alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(test,orcl)' scope=spfile;
SQL>alter system set LOG_ARCHIVE_DEST_1='LOCATION=/data/arch/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'scope=spfile;
SQL>alter system set LOG_ARCHIVE_DEST_2='SERVICE=test LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=test' scope=spfile;
SQL>alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=spfile;
SQL>alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=spfile;
SQL>alter system set FAL_SERVER=test scope=spfile;
SQL>alter system set FAL_CLIENT=orcl scope=spfile;
*************************************************************************************************************
alter system set DB_FILE_NAME_CONVERT='+DATA/test/datafile/','/data/orcl/datafile/' scope=spfile;    ----(前为主库存放数据文件的路径,后为备库存放数据文件的路径,如果主备库目录结构完全一样,则无需设定。)
alter system set LOG_FILE_NAME_CONVERT='+DATA/test/onlinelog/','/data/orcl/onlinelog/' scope=spfile; ---- (前为主库在线日志的路径,后为备库在线日志的路径,如果主备库目录结构完全一样,则无需设定)
主备切换之后在当前备库上设置这两个参数时路径要反过来
*************************************************************************************************************
SQL>alter system set STANDBY_FILE_MANAGEMENT=auto scope=spfile;
恢复控制文件:
RMAN> restore controlfile from'/backup/stdby_control01.ctl';
RMAN>alter database mount;
RMAN>run { 
 set  newname for datafile 1 to '/data/orcl/datafile/o1_mf_system_bwocwhpc_.dbf';
 set  newname for datafile 2 to '/data/orcl/datafile/o1_mf_sysaux_bwocwhs2_.dbf';
 set  newname for datafile 3 to '/data/orcl/datafile/o1_mf_undotbs1_bwocwht5_.dbf';
 set  newname for datafile 4 to '/data/orcl/datafile/o1_mf_users_bwocwhvw_.dbf';
 set  newname for datafile 5 to '/data/orcl/datafile/o1_mf_undotbs2_byx1qkr2_.dbf';
 set  newname for datafile 6 to '/data/orcl/datafile/o1_mf_aa.301.dbf';
 set  newname for datafile 7 to '/data/orcl/datafile/o1_mf_aa.278.dbf';
 restore database;               
 switch datafile all;            
  }


在备库增加standby redolog组数是主库+1。查询语句SQL> select group#,members,bytes/1024/1024,status from v$log;(select group#,type,member from v$logfile;)
SQL>alter database add standby logfile          -----首先创建/oradata/DG2/onlinelog/路径
    group 5 ('/data/orcl/onlinelog/stdby_redo5.log') size 50m,
    group 6 ('/data/orcl/onlinelog/stdby_redo6.log') size 50m,-------###特别注意standby redolog的大小要和主库redolog的大小一致!!!
    group 7 ('/data/orcl/onlinelog/stdby_redo7.log') size 50m,
    group 8 ('/data/orcl/onlinelog/stdby_redo8.log') size 50m,
    group 9 ('/data/orcl/onlinelog/stdby_redo9.log') size 50m;
如果以后主库要切换成备库  就要在现在的主库上加上standbyredolog
SQL>alter database add standby logfile          -----首先创建/oradata/dg1/onlinelog/路径
    group 5 ('+DATA/test/onlinelog/stdby_redo5.log') size 50m,
    group 6 ('+DATA/test/onlinelog/stdby_redo6.log') size 50m,
    group 7 ('+DATA/test/onlinelog/stdby_redo7.log') size 50m,
    group 8 ('+DATA/test/onlinelog/stdby_redo8.log') size 50m,
    group 9 ('+DATA/test/onlinelog/stdby_redo9.log') size 50m;




启动备库
lsnrctl start
SQL >shutdown immediate
SQL >startup nomount;
SQL >alter database mount standby database;

SQL >alter database recover managed standby database using current logfile disconnect from session;

正常主备切换:
主库
SQL >alter database commit to switchover to physical standby;
SQL >shutdown immediate
SQL >startup nomount;
SQL >alter database mount standby database;
SQL >alter database recover managed standby database disconnect from session;
备库
SQL >alter database commit to switchover to primary;
如果此处报ORA-16139: media recovery required错误,可能是由于未应用日志引起,可先执行alter database recover managed standby database disconnect from session;
SQL >shutdown immediate;
SQL >startup


非正常切换:(即主服务器当机的情况)启动failover
备服务器
SQL >alter database recover managed  standby database finish;
SQL >alter database commit to switchover to primary;
SQL >shutdown immediate;
SQL >startup;

你可能感兴趣的:(11gRAC对单机dataguard)