可能会遇上如下报错信息,这个时候需要重启下数据库
SQL> shutdown immediate;
SQL> startup
SQL> alter system set log_archive_dest_1= 'location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles) db_unique_name=db1' scope=both;
SQL> alter system set log_archive_dest_2= 'service=db2 async valid_for=(online_logfiles,primary_role) db_unique_name=db2' scope=both;
SQL> alter system set log_archive_dest_state_1=enable scope=both;
SQL> alter system set log_archive_dest_state_2=enable scope=both;
SQL> alter system set standby_file_management=auto scope=both;
SQL> alter system set fal_server=db2 scope=both;
SQL> alter system set fal_client=db1 scope=both;
SQL> alter system set db_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' scope=spfile;
SQL> alter system set log_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' scope=spfile;
4.修改监听文件
[oracle@db1 ~]$ vim /opt/oracle/product/11.2.0/network/admin/tnsnames.ora
在后面增加
db1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = db1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db1)
)
)
db2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = db2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db2)
)
)
5.RMAN备份主库
创建备份存放目录
[oracle@db1 ~]$ mkdir -p /opt/oracle/dbackup
执行备份
rman>run{
allocate channel c1 type disk;
backup format '/opt/oracle/dbackup/tpy100_%T_%s_%p' database;
sql 'alter system archive log current';
backup format '/opt/oracle/dbackup/archive_log_%T_%s_%p' archivelog all;
backup spfile format '/opt/oracle/dbackup/spfile_%u_%T.bak';
release channel c1;
}
rman>copy current controlfile for standby to '/opt/oracle/dbackup/standby.ctl';
6.复制文件至备库
[oracle@db1 ~]$ scp -r /opt/oracle/dbackup/ db2:/opt/oracle
[oracle@db1 ~]$ cd $ORACLE_HOME/dbs
[oracle@db1 dbs]$ scp -r orapwtpy100 db2:$ORACLE_HOME/dbs
[oracle@db1 dbs]$ cd $ORACLE_HOME/network/admin
[oracle@db1 admin]$ scp -r listener.ora tnsnames.ora db2:$ORACLE_HOME/network/admin
7.恢复参数文件(db2)
RMAN> set dbid 2926260986
RMAN> startup nomount;
#这里会报错不用理会即可
RMAN> restore spfile to pfile '/tmp/tpy100.pfile' from '/opt/oracle/dbackup/spfile_04quaekm_20160219.bak';
#我们将参数文件恢复至/tmp/tpy100.pfile,因为这个是主库的参数文件,备库略有不同
8.修改备库参数文件(db2)
[oracle@db2 ~]$ vim /tmp/tpy100.pfile
#将里面的DB1 db1变成相应的DB2 db2,将DB1变成db1
tpy100.__db_cache_size=322961408
tpy100.__java_pool_size=4194304
tpy100.__large_pool_size=4194304
tpy100.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment
tpy100.__pga_aggregate_target=339738624
tpy100.__sga_target=503316480
tpy100.__shared_io_pool_size=0
tpy100.__shared_pool_size=159383552
tpy100.__streams_pool_size=0
*.audit_file_dest='/opt/oracle/admin/tpy100/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/opt/oracle/oradata/tpy100/control01.ctl','/opt/oracle/flash_recovery_area/tpy100/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area'
*.db_name='tpy100'
*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.db_unique_name='DB2'
*.diagnostic_dest='/opt/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=tpy100XDB)'
*.fal_client='DB2'
*.fal_server='DB1'
*.log_archive_config='dg_config=(db2,db1)'
*.log_archive_dest_1='location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles) db_unique_name=db2'
*.log_archive_dest_2='service=db1 async valid_for=(online_logfiles,primary_role) db_unique_name=db1'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area'
*.memory_target=843055104
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'