RMAN远程复制搭建物理DG过程小结

搭建环境前配置主备库的tns,确保两数据库能正常彼此通信

primary

确定数据库开启强制归档

startup mount;

alter database archivelog;

alter database force logging;

alter database open;

修改配置,并导出pfile,将pfile复制到目标备库

alter system set db_unique_name=pri scope=spfile;

alter system set log_archive_config = 'DG_CONFIG=(pri,sty)' scope=spfile;

alter system set log_archive_dest_1 = 'LOCATION=/opt/app/Oracle/product/11.2.0/dbhome_1/dbs/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pri' scope=spfile;

alter system set log_archive_dest_2 = 'SERVICE=sty LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=sty' scope=spfile;

alter system set log_archive_dest_state_1 = ENABLE;

alter system set log_archive_dest_state_2 = ENABLE;

alter system set fal_server=sty scope=spfile;

alter system set fal_client=pri scope=spfile;

alter system set standby_file_management=AUTO scope=spfile;

create pfile='/home/oracle/pripfile.ora' from spfile;

standby

安装数据库软件,无需安装数据库

复制元库的sys密码文件,确保两库的密码一致

scp 192.168.20.46:$ORACLE_HOME/dbs/orapwxtttestdb $ORACLE_HOME/dbs/

复制目标库导出的pfile,并添加 *.log_file_name_convert参数选项(10g之后必须添加,即使路径没有改变)

scp 192.168.20.46:/home/oracle/pripfile.ora /home/oracle/

*.log_file_name_convert='/opt/app/oracle/oradata/xtttestdb/','/opt/app/oracle/oradata/xtttestdb/'

创建要恢复备库的必要目录

mkdir -p /opt/app/oracle/admin/xtttestdb/adump
 mkdir -p /opt/app/oracle/oradata/xtttestdb
 mkdir -p /opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch

设置SID登入数据库

export $ORACLE_SID=xtttestdb

sqlplus / as sysdba

利用copy并修改后的pfile创建spfile,并启动到nomount
 SQL> create spfile from pfile='/home/oracle/pripfile.ora';
 File created.

SQL> startup nomount;
 ORACLE instance started.
 Total System Global Area 1570009088 bytes
 Fixed Size                  2213696 bytes
 Variable Size            1174407360 bytes
 Database Buffers          385875968 bytes
 Redo Buffers                7512064 bytes

修改备库的参数配置

alter system set db_unique_name=sty scope=spfile;

alter system set log_archive_config='DG_CONFIG=(pri,dg)' scope=spfile;

alter system set log_archive_dest_1 ='LOCATION=/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=sty' scope=spfile;

alter system set log_archive_dest_2 ='SERVICE=pri LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=pri' scope=spfile;

alter system set fal_server=pri scope=spfile;

alter system set fal_client=sty scope=spfile;

重启数据库到nomount,是配置生效(这些配置也可以在pfile中修改完成后再启动数据库库)

SQL> shutdown immediate;

SQL> startup mount;

primary利用rman复制数据库

rman target sys/oraclepwd@XTTTESTDB.46 auxiliary sys/oraclepwd@XTTTESTDB.54
 RMAN> duplicate target database for standby from active database nofilenamecheck;

复制完成后在主备库天剑standby redo(至少要三组)

alter database add standby logfile

group 4 ('/opt/app/oracle/oradata/xtttestdb/styredo04.log') size 50m,

group 5 ('/opt/app/oracle/oradata/xtttestdb/styredo05.log') size 50m,

group 6 ('/opt/app/oracle/oradata/xtttestdb/styredo06.log') size 50m,

group 7 ('/opt/app/oracle/oradata/xtttestdb/styredo07.log') size 50m;

启动standby的redo应用的两种方式

①、默认的物理DG启动应用后,在主库arch日志被完整写入后才会开始应用该arch log

SQL> alter database recover managed standby database disconnect from session;

②、可以添加current logfile参数,使得应用当前正在读写,还没有完成归档的日志

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

关闭REDO应用

SQL> alter database recover managed standby database cancel;

查看standby log状态

select group#,thread#,sequence#,archived,status from v$standby_log;

查看应用日志情况
select name,creator,sequence#,applied,completion_time from v$archived_log;

验证:

primary端创建测试表,并添加数据

SQL> select count(*) from test;

COUNT(*)

----------

7

SQL> insert into test select * from test;

7 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

COUNT(*)

----------

14

standby端验证数据是否同步

SQL> select count(*) from test;

COUNT(*)

----------

14

搭建过程问题小结:

1、在备库启动到nomount后用tns测试连接时发现数无法连接
ORA-12528: TNS:listener: all appropriate instances are blocking new connections

原因是11g之后动态监听不支持在nomount状态下远程的tns访问,自己的服务器中配置的监听一直是动态的

添加listener.ora 文件,为standby设置静态监听

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SID_NAME = PLSExtProc)

(ORACLE_HOME = /opt/app/oracle/product/11.2.0/dbhome_1)

(PROGRAM = extproc)

)

(SID_DESC =

(GLOBAL_DBNAME = xtttestdb)

(ORACLE_HOME = /opt/app/oracle/product/11.2.0/dbhome_1)

(SID_NAME = xtttestdb)

)

)

之后再测试连接正常

2、RMAN远程复制数据库完成后有redo的报错

ORACLE error from auxiliary database: ORA-19527: physical standby redo log must be renamed

ORA-00312: online log 1 thread 1: '/opt/app/oracle/oradata/xtttestdb/redo01.log'

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/078bf4e7c1879c949be7a84cb22a3c3c.html