Oracle 12C 利用Rman Duplicate搭建 Data Guard
环境(备库只需要安装数据库软件):
主库:192.168.1.100 OS: CentOS 7.3 X64 DB: ORACLE12.2.0.1 SID: ORA12C db_unique_name: ORA12C
备库:192.168.1.101 OS: CentOS 7.3 X64 DB: ORACLE12.2.0.1 SID: ORA12C db_unique_name: ORA12CDG
1.设置主库为强制归档模式:
(1)SQL> alter database force logging;
Database altered.
SQL> select name,force_logging from v$database;
NAME FORCE_LOG
--------------------------- ---------
ORA12C YES
(2)如果在主库添加或者删除数据文件时,这些文件也需要在备份添加或删除,需要如下设置:
SQL> alter system set STANDBY_FILE_MANAGEMENT='AUTO' scope=spfile;
默认此参数是MANUAL手工方式,此方式在添加或者删除数据文件时会导致日志无法应用。SQL> show parameter STANDBY_FILE;
2.创建standby log files(备用日志文件)
从库使用standby log files来保存从主库接收到的重做日志。既然主要是从库在使用,那为什么需要在主库上也建立standby log files?原因主要是主库可能转换为备库,而备库是需要有standby log files的。建立standby如要注意以下几点:
<1>standby log files的大小和redo log files一样。
查询redo log files文件大小:
SQL> select group#,thread#,archived,status, bytes/1024/1024 from v$log;
GROUP# THREAD# ARC STATUS BYTES/1024/1024
---------- ---------- --- ---------------- ---------------
1 1 YES INACTIVE 200
2 1 NO CURRENT 200
3 1 YES INACTIVE 200
<2>一般而言, standbyredo 日志文件组数要比 primary 数据库的 online redo 日志文件组数至少多一个。
SQL> select member from v$logfile;
SQL> alter database add standby logfile thread 1 group 11 '/oracle/oradata/ORA12C/stdby11.log' size 200m;
SQL> alter database add standby logfile thread 1 group 12 '/oracle/oradata/ORA12C/stdby12.log' size 200m;
SQL> alter database add standby logfile thread 1 group 13 '/oracle/oradata/ORA12C/stdby13.log' size 200m;
SQL> alter database add standby logfile thread 1 group 14 '/oracle/oradata/ORA12C/stdby14.log' size 200m;
3.密码文件创建传输
(1)一般数据库默认就有密码文件,存放为$ORACLE_HOME/dbs/orapwSID 这里为orapwORA12C
如果没有则手动创建:
[oracle@ora12c ~]$ orapwd file=$ORACLE_HOME/dbs/orapwORA12C password=ccdadmin
(2)检查REMOTE_LOGIN_PASSWORDFILE值是否为 EXCLUSIVE
SQL> show parameter REMOTE_LOGIN_PASSWORDFILE
如果值不是EXCLUSIVE,则:alter system set remote_login_passwordfile=exclusive scope=spfile;
(3)将密码文件复制到备库
[oracle@ora12c ~]$ scp $ORACLE_HOME/dbs/orapwORA12C oracle@192.168.1.101:/oracle/orahome/dbs/
4.db_name和db_unique_name
默认db_name和db_unique_name和实例名是一致的,这里是ORA12C,需要注意在DG中主库和从库的db_unique_name是不能一致的,需要区分开。这里我们设置主库的db_unique_name为ORA12C,从库为ORA12CDG
SQL> show parameter db_unique_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string ORA12C
设置:SQL> alter system set db_unique_name=ORA12C SCOPE=SPFILE;
--注意:虽然默认db_unique_name和db_name是一致的,但是需要显式设置,否则在spfile中没有此参数
5.开启flashback
SQL> select flashback_on from v$database;
SQL> alter database flashback on;
如果碰到 ORA-01153 报错,一定是在备库进行此操作。需要先取消重做日志应用,启用闪回日志,然后重新启用日志应用。
在主库启用flashback,不会同步备库也启用,必须手动在主库和备库上均启用flashback。
6.配置监听及tnsnames.ora
主库监听:
[oracle@ora12c ~]$ cd $ORACLE_HOME/network/admin
[oracle@ora12c admin]$ more listener.ora
SID_LIST_PRIM =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORA12C)
(ORACLE_HOME = /oracle/orahome)
(SID_NAME = ORA12C)
)
)
PRIM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))
)
备库监听:
[oracle@ora12cdg admin]$ more listener.ora
SID_LIST_STDBY =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORA12C)
(ORACLE_HOME = /oracle/orahome)
(SID_NAME = ORA12C)
)
)
STDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
)
主库tnsnames.ora(备库和主库一样):
[oracle@ora12c ~]$ cd $ORACLE_HOME/network/admin
[oracle@ora12c admin]$ more tnsnames.ora
ORA12C =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ORA12C)
)
)
ORA12CDG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ORA12C)
)
)
7.重做日志传输配置
(1)配置归档日志路径:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archive
Oldest online log sequence 56
Next log sequence to archive 58
Current log sequence 58
SQL> alter system set log_archive_dest_1='LOCATION=/oracle/archive valid_for=(all_logfiles,all_roles) db_unique_name=ORA12C' scope=spfile;
SQL> alter system set log_archive_dest_state_1='enable' scope=spfile;
官方文档里说使用 valid_for=(online_logfiles, all_roles) 将导致备库无法归档备用日志文件,因为它们不是在线日志。使用all_logfiles选项,主备库将都能归档在线以及备用日志。如果想在备库进行备份,并同时备份归档日志的话,必须使用all_logfiles
(2)配置重做日志到备份库:
SQL> alter system set log_archive_dest_2='SERVICE=ORA12CDG lgwr sync affirm valid_for=(online_logfile,primary_role) db_unique_name=ORA12CDG';
SQL> alter system set log_archive_dest_state_2='enable' scope=spfile;
(3)设置db_file_name_convert和log_file_name_conver参数:
SQL> alter system set log_file_name_convert='/oracle/archive','/oracle/archive' scope=spfile;
SQL> alter system set db_file_name_convert='/oracle/oradata/ORA12C','/oracle/oradata/ORA12C' scope=spfile;
如果主备库的目录结构不一样,或者主备库在同一台服务器上,则必须要设置db_file_name_convert和log_file_name_conver参数来进行数据文件和联机日志的保存路径的转换。
(4)STANDBY_ARCHIVE_DEST 参数不再需要,已经被官方弃用。
8.配置FAL_SERVER
这个参数指定当日志传输出现问题时,备库到哪里去找缺少的归档日志。它用在备库接收的到的重做日志间有缺口的时候。这种情况会发生在日志传输出现中断时,比如你需要对备库进行维护操作。在备库维护期间,没有日志传输过来,这时缺口就出现了。设置了这个参数,备库就会主动去寻找那些缺少的日志,并要求主库进行传输。
在主库:fal_server=从库
从库上就反过来:fal_server=主库
SQL> alter system set FAL_SERVER='ORA12CDG';
注意:FAL_CLIENT在11g中已经废弃,虽然可以配置但是已经不起作用了。
9.Data Guard 配置里的另外一个库的名字
SQL> alter system set log_archive_config = 'dg_config=(ORA12C,ORA12CDG)';
10.在备库创建所需要的目录以放置数据文件、控制文件和跟踪文件等
[oracle@ora12cdg ~]$ cd /oracle/
[oracle@ora12cdg oracle]$ mkdir admin archive fast_recovery_area
[oracle@ora12cdg oracle]$ cd admin/
[oracle@ora12cdg admin]$ mkdir ORA12C
[oracle@ora12cdg admin]$ cd ORA12C/
[oracle@ora12cdg ORA12C]$ mkdir adump dpdump pfile
[oracle@ora12cdg ORA12C]$ cd /oracle/fast_recovery_area/
[oracle@ora12cdg fast_recovery_area]$ mkdir ORA12C
11.主库生成pfile (initORA12C.ora),并传输到备库进行修改
SQL> create pfile from spfile;
[oracle@ora12c ~]$ scp /oracle/orahome/dbs/initORA12C.ora oracle@192.168.1.101:/oracle/orahome/dbs/
主库pfile:
[oracle@ora12c dbs]$ more initORA12C.ora
ORA12C.__data_transfer_cache_size=0
ORA12C.__db_cache_size=2298478592
ORA12C.__inmemory_ext_roarea=0
ORA12C.__inmemory_ext_rwarea=0
ORA12C.__java_pool_size=16777216
ORA12C.__large_pool_size=83886080
ORA12C.__oracle_base='/oracle'#ORACLE_BASE set from environment
ORA12C.__pga_aggregate_target=1056964608
ORA12C.__sga_target=3154116608
ORA12C.__shared_io_pool_size=167772160
ORA12C.__shared_pool_size=570425344
ORA12C.__streams_pool_size=0
*.audit_file_dest='/oracle/admin/ORA12C/adump'
*.audit_trail='db'
*.compatible='12.2.0'
*.control_files='/oracle/oradata/ORA12C/control01.ctl','/oracle/fast_recovery_area/ORA12C/control02.ctl'
*.db_block_size=8192
*.db_file_name_convert='/oracle/oradata/ORA12C','/oracle/oradata/ORA12C'
*.db_name='ORA12C' #数据库的名字,在整个DG的所有主、备库都应一致
*.db_recovery_file_dest='/oracle/fast_recovery_area/ORA12C'
*.db_recovery_file_dest_size=8016m
*.db_unique_name='ORA12C'
*.diagnostic_dest='/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORA12CXDB)'
*.fal_server='ORA12CDG'
*.log_archive_config='dg_config=(ORA12C,ORA12CDG)'
*.log_archive_dest_1='LOCATION=/oracle/archive valid_for=(all_logfiles,all_roles) db_unique_name=ORA12C'
*.log_archive_dest_2='SERVICE=ORA12CDG lgwr sync affirm valid_for=(online_logfile,primary_role) db_unique_name=ORA12CDG'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.arc'
*.log_file_name_convert='/oracle/archive','/oracle/archive'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=1000m
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=3000m
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
备库修改部分:
*.db_file_name_convert='/oracle/oradata/ORA12C','/oracle/oradata/ORA12C'
*.db_unique_name='ORA12CDG'
*.fal_server='ORA12C'
*.log_archive_config='dg_config=(ORA12CDG,ORA12C)'
*.log_archive_dest_1='LOCATION=/oracle/orabackup/archive valid_for=(all_logfiles,all_roles) db_unique_name=ORA12CDG'
*.log_archive_dest_2='SERVICE=ORA12C lgwr sync affirm valid_for=(online_logfile,primary_role) db_unique_name=ORA12C'
*.log_file_name_convert='/oracle/archive','/oracle/archive'
12.启动备库到nomount状态:
SQL> conn /as sysdba
SQL> create spfile from pfile='/oracle/orahome/dbs/initORA12C.ora';
SQL> startup nomount
13.在主系统上执行RMAN 并连接主数据库和辅助数据库(即备库)
[oracle@ora12c admin]$ rman target sys/passwd@ORA12C auxiliary sys/passwd@ORA12CDG
connected to target database: ORA12C (DBID=376201757)
connected to recovery catalog database
connected to auxiliary database: ORA12C (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;
14.启用物理备用数据库:
duplicate 完成之后,备库是mount的。
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL> alter database recover managed standby database disconnect from session;
15.查看主备库同步状态:
SQL> alter system switch logfile; //主库
SQL> select max(sequence#) from v$archived_log;
SQL> select process, client_process, sequence#, status from v$managed_standby;
16.备库开启flashback:
SQL> select flashback_on from v$database;
SQL> alter database recover managed standby database cancel;
SQL> alter database flashback on;
SQL> alter database recover managed standby database disconnect from session;
17.如果要开启Active Data Guard,按以下步骤操作即可:
(1)取消管理备用数据库Redo Apply
SQL> alter database recover managed standby database cancel;
(2)然后以只读方式打开数据库
SQL> alter database open;
(3)重新开始Redo Apply
SQL> alter database recover managed standby database disconnect from session;
(4)查看备库打开模式
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341