1. 修改主端为归档模式
两节点执行:
SQL> alter system set log_archive_dest_1='location=+data_dg/arch';
System altered.
--关闭两节点
SQL> shutdown immediate;
--启动一个节点到mount状态
SQL> startup mount;
SQL> alter database archivelog;
Database altered.
--open两节点
SQL> alter database open;
--验证
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +DATA_DG/arch
Oldest online log sequence 15
Next log sequence to archive 16
Current log sequence
2. 设置主库为force logging
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
3. 配置主,备端tnsnames.ora(高可用)
prod_std =
(DESCRIPTION_LIST =
(LOAD_BALANCE = off)
(FAILOVER = on)
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = OFF)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.19.108)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod_std)
(Instance_name = prod1)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 4)
(DELAY = 1)
)
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = OFF)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.19.109)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod_std)
(Instance_name = prod2)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 4)
(DELAY = 1)
)
)
)
)
prod_pri =
(DESCRIPTION_LIST =
(LOAD_BALANCE = off)
(FAILOVER = on)
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = OFF)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.19.106)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod)
(Instance_name = prod1)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 4)
(DELAY = 1)
)
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = OFF)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.19.107)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod)
(Instance_name = prod2)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 4)
(DELAY = 1)
)
)
)
)
4. 主端修改参数
a. log_archive_config --dtaaguard主备端db_unique_name配置范围
alter system set log_archive_config='dg_config=(prod,prod_std)';
b. log_archive_dest_1 --本地归档路径
alter system set log_archive_dest_1='location=+DATA_DG/arch valid_for=(all_logfiles,all_roles) db_unique_name=prod' sid='*';
c. log_archive_dest_2 --远程归档路径
alter system set log_archive_dest_2='service=prod_std lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=prod_std' sid='*';
d. log_archive_dest_state
alter system set log_archive_dest_state_1=ENABLE sid='*';
alter system set log_archive_dest_state_2=ENABLE sid='*';
e .standby_file_management
alter system set standby_file_management='auto' sid='*';
f. fal_server,fal_client(11g已废弃)
alter system set fal_server=prod_std sid='*';
alter system set fal_client=prod_pri sid='*';
g. service_names
alter system set service_names='prod','prod_std' scope=both sid='*';
5. asm存储创建与主端相同目录
6. 生产备库参数文件
SQL> create pfile='/home/oracle/pfile0802.ora' from spfile;
File created.
--根据参数文件创建目录
[oracle@oracle-node3 ~]$ mkdir -p /u01/app/oracle/admin/prod/adump
prod1.__data_transfer_cache_size=0
prod2.__data_transfer_cache_size=0
prod2.__db_cache_size=3674210304
prod1.__db_cache_size=3674210304
prod1.__java_pool_size=33554432
prod2.__java_pool_size=33554432
prod2.__large_pool_size=83886080
prod1.__large_pool_size=83886080
prod1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
prod2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
prod1.__pga_aggregate_target=1660944384
prod2.__pga_aggregate_target=1660944384
prod1.__sga_target=4982833152
prod2.__sga_target=4982833152
prod2.__shared_io_pool_size=251658240
prod1.__shared_io_pool_size=251658240
prod1.__shared_pool_size=922746880
prod2.__shared_pool_size=922746880
prod1.__streams_pool_size=0
prod2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/prod/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='12.1.0.2.0'
*.control_files='+DATA_DG/PROD/CONTROLFILE/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='+DATA_DG'
*.db_domain=''
*.db_name='prod'
*.db_unique_name='prod_std'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=prodXDB)'
*.enable_pluggable_database=true
*.fal_client='PROD_STD'
*.fal_server='PROD_PRI'
prod2.instance_number=2
prod1.instance_number=1
*.log_archive_config='dg_config=(prod,prod_std)'
*.log_archive_dest_1='location=+DATA_DG/arch valid_for=(all_logfiles,all_roles) db_unique_name=prod_std'
*.log_archive_dest_2='service=prod_pri lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=prod'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.open_cursors=300
*.pga_aggregate_target=1580m
*.processes=300
*.remote_login_passwordfile='exclusive'
*.service_names='prod','prod_std'
*.sga_target=4740m
*.standby_file_management='auto'
prod2.thread=2
prod1.thread=1
prod2.undo_tablespace='UNDOTBS2'
prod1.undo_tablespace='UNDOTBS1'
--创建spfile
startup nomount pfile='/home/oracle/pfile_std.ora';
create spfile from pfile='/home/oracle/pfile_std.ora';
--复制到asm存储
ASMCMD -P
ASMCMD [+data_dg/prod/PARAMETERFILE] > cp /u01/app/oracle/product/12.1.0/db_1/dbs/spfileprod1.ora +data_dg/prod/parameterfile/spfileprod.ora
copying /u01/app/oracle/product/12.1.0/db_1/dbs/spfileprod.ora -> +data_dg/prod/parameterfile/spfileprod1.ora
--注册到crs,添加实例资源到CRS
srvctl remove database -db prod --移除db配置
srvctl add database -db prod_std -oraclehome /u01/app/oracle/product/12.1.0/db_1 -dbtype RAC -spfile +data_dg/prod/parameterfile/spfileprod.ora -dbname prod
srvctl add instance -db prod_std -instance prod1 -node oracle-node3
srvctl add instance -db prod_std -instance prod2 -node oracle-node4
[grid@oracle-node3 ~]$ srvctl config database -d prod_std
Database unique name: prod_std
Database name: prod
Oracle home: /u01/app/oracle/product/12.1.0/db_1
Oracle user: oracle
Spfile: +data_dg/prod/parameterfile/spfileprod.ora
Password file:
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups:
Mount point paths:
Services:
Type: RAC
Start concurrency:
Stop concurrency:
OSDBA group: dba
OSOPER group: oper
Database instances: prod1,prod2
Configured nodes: oracle-node3,oracle-node4
Database is administrator managed
6. 复制主端密码文件到备端
ASMCMD> cp pwdprod.276.950980181 /home/grid/pwdprod_std
copying +data_dg/prod/password/pwdprod.276.950980181 -> /home/grid/pwdprod_std
[grid@oracle-node1 ~]$ scp pwdprod_std
[email protected]:/home/grid
[grid@oracle-node3 ~]$ orapwd input_file='/home/grid/pwdprod_std' file='+DATA_DG/prod/PASSWORD/pwdprod_std' asm=y
srvctl modify database -db prod_std -pwfile +DATA_DG/prod/PASSWORD/pwdprod_std
[oracle@oracle-node3 ~]$ srvctl modify database -db prod_std -pwfile +DATA_DG/prod/PASSWORD/pwdprod_std
7. 配置静态监听
SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = PROD)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1)
(SID_NAME =prod2)
)
)
在主端即备端的listener.ora中均加入这一段,重启监听,不过动态监听注册较慢,过一段时间才能看到其他动态监听
sqlplus sys/Oracle_123@prod_std as sysdba:在主端测试密码文件及监听是否有效
8. 修改备端oracle用户权限,加上asmadmin用户组,否则oracle用户无法写入asm磁盘组的
此时虽然备端可以使用asm存储中的spfile启动到nomout状态,但无法修改参数,也就是没有磁盘组的权限
[root@oracle-node4 dev]# usermod -a -G asmadmin oracle
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 08/03/2017 04:24:19
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
ORA-19660: some files in the backup set could not be verified
ORA-19661: datafile 0 could not be verified
ORA-19849: error while reading backup piece from service prod_pri
ORA-19504: failed to create file "+DATA_DG/PROD/CONTROLFILE/control01.ctl"
ORA-17502: ksfdcre:3 Failed to create file +DATA_DG/PROD/CONTROLFILE/control01.ctl
ORA-15001: diskgroup "DATA_DG" does not exist or is not mounted
ORA-15040: diskgroup is incomplete
9. rman duplicate复制
[oracle@oracle-node1 ~]$ rman target sys/Oracle_123@prod_pri auxiliary sys/Oracle_123@prod_std
RMAN> duplicate target database for standby nofilenamecheck from active database;
9. 主端和备端创建standby日志组,比生产每个节点多一组
Alter database add standby logfile thread 1 group 9 ('+DATA_DG/PROD/ONLINELOG/redo_st09.log') size 50m;
Alter database add standby logfile thread 1 group 10 ('+DATA_DG/PROD/ONLINELOG/redo_st10.log') size 50m;
Alter database add standby logfile thread 1 group 11 ('+DATA_DG/PROD/ONLINELOG/redo_st11.log') size 50m;
Alter database add standby logfile thread 1 group 12 ('+DATA_DG/PROD/ONLINELOG/redo_st12.log') size 50m;
Alter database add standby logfile thread 1 group 13 ('+DATA_DG/PROD/ONLINELOG/redo_st13.log') size 50m;
Alter database add standby logfile thread 2 group 14 ('+DATA_DG/PROD/ONLINELOG/redo_st14.log') size 50m;
Alter database add standby logfile thread 2 group 15 ('+DATA_DG/PROD/ONLINELOG/redo_st15.log') size 50m;
Alter database add standby logfile thread 2 group 16 ('+DATA_DG/PROD/ONLINELOG/redo_st16.log') size 50m;
Alter database add standby logfile thread 2 group 17 ('+DATA_DG/PROD/ONLINELOG/redo_st17.log') size 50m;
Alter database add standby logfile thread 2 group 18 ('+DATA_DG/PROD/ONLINELOG/redo_st18.log') size 50m;
alter system set log_file_name_convert='+DATA_DG/PROD/ONLINELOG','+DATA_DG/PROD_STD/ONLINELOG' sid='*' scope=spfile;
10. open数据库,开启日志应用即可
alter database recover managed standby database using current logfile disconnect from session;