主库上操作
1.开启rac的 force logging
sql> alter database force logging;
sql>
2.修改rac初始化参数文件
sql> alter system set log_archive_config=’dg_config=(eisoo,eisoos)’;
sql> alter system set log_archive_dest_2=’service=eisoos async valid_for=(online_logfiles,primary_role) db_unique_name=eisoos’ scope=spfile;
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=eisoos;
sql> alter system set db_file_name_convert=’eisoos’,’eisoo’ scope=spfile;
sql> alter system set db_file_name_convert=’/data/oradata/eisoos’,’+data/eisoo/datafile’ scope=spfile; //如果备库没有使用asm
sql> alter system set log_file_name_convert=’eisoos’,’eisoo’ scope=spfile;
sql> alter system set log_file_name_convert=’/data/oradata/eisoos’,’+data/eisoo/onlinelog’ scope=spfile;//如果备库没有使用asm
sql> alter system set standby_file_management=’auto’;
sql> alter system set log_archive_max_processes=30;
3.开启归档模式
srtl stop database -d eisoo
srvctl start database -d eisoo-i eisoo -o mount
sql>alter database archivelog;
sql>alter database open;
4.创建standby logfile;
sql> select thread#,group#,bytes/1024/1024 from v$log;
thread# group# bytes/1024/1024
———- ———- —————
1 1 50
1 2 50
2 3 50
2 4 50
sql> alter database add standby logfile thread 1 group 10 size 50m;
sql> alter database add standby logfile thread 1 group 11 size 50m;
sql> alter database add standby logfile thread 1 group 12 size 50m;
sql> alter database add standby logfile thread 2 group 13 size 50m;
sql> alter database add standby logfile thread 2 group 14 size 50m;
sql> alter database add standby logfile thread 2 group 15 size 50m;
sql> select thread#,group#,bytes/1024/1024 from v$standby_log;
thread# group# bytes/1024/1024
———- ———- —————
1 10 50
1 11 50
1 12 50
2 13 50
2 14 50
2 15 50
5.创建备库参数文件
sql> show parameter spfile;
name type value
———————————— ———– ——————————
spfile string +data/eisoo/parameterfile/spfile.281.923255053
sql> create pfile=’/tmp/initeisoos.ora’ from spfile=’+data/eisoo/parameterfile/spfile.281.923255053′;
[oracle@rac1 tmp]$ scp initeisoos.ora 192.168.180.48:$oracle_home/dbs
备库上操作:
1.修改参数文件
使用asm:
*.audit_file_dest=’/u01/app/oracle/admin/eisoos/adump’
*.audit_trail=’db’
*.compatible=’12.1.0.2.0′
*.control_files=’/data/oradata/eisoos/control01.ctl’
*.db_block_size=8192
*.db_create_file_dest=’/data/oradata/eisoos’
*.db_domain=”
*.db_file_name_convert=’eisoo’,’eisoos’
*.db_name=’eisoo’
*.db_unique_name=’eisoos’
*.diagnostic_dest=’/u01/app/oracle’
*.dispatchers='(protocol=tcp) (service=eisoosxdb)’
*.fal_server=’eisoos’
*.log_archive_config=’dg_config=(eisoo,eisoos)’
*.log_archive_dest_1=’location=/data/oradata/eisoos/archivelog’
*.log_archive_dest_2=’service=eisoo async valid_for=(online_logfiles,primary_role) db_unique_name=eisoo’
*.log_archive_dest_state_1=’enable’
*.log_archive_dest_state_2=’enable’
*.log_archive_format=’%t_%s_%r.arc’
*.log_archive_max_processes=30
*.log_file_name_convert=’eisoo’,’eisoos’
*.open_cursors=300
*.pga_aggregate_target=453m
*.processes=300
*.remote_login_passwordfile=’exclusive’
*.sga_target=1361m
*.standby_file_management=’auto’
eisoos.undo_tablespace=’undotbs1′
单机未使用asm:
*.audit_file_dest=’/u01/app/oracle/admin/eisoos/adump’
*.audit_trail=’db’
*.compatible=’12.1.0.2.0′
*.control_files=’/data/oradata/eisoos/control01.ctl’#restore controlfile
*.db_block_size=8192
*.db_create_file_dest=’/data/oradata/eisoos’
*.db_domain=”
*.db_file_name_convert=’+data/eisoo/datafile’,’/data/oradata/eisoos’,’+data/eisoo/tempfile’,’/data/oradata/eisoos’
*.db_name=’eisoo’
*.db_unique_name=’eisoos’
*.diagnostic_dest=’/u01/app/oracle’
*.dispatchers='(protocol=tcp) (service=eisoosxdb)’
*.fal_server=’eisoos’
*.log_archive_config=’dg_config=(eisoo,eisoos)’
*.log_archive_dest_1=’location=/data/oradata/eisoos/archivelog’
*.log_archive_dest_2=’service=eisoo async valid_for=(online_logfiles,primary_role) db_unique_name=eisoo’
*.log_archive_dest_state_1=’enable’
*.log_archive_dest_state_2=’enable’
*.log_archive_format=’%t_%s_%r.arc’
*.log_archive_max_processes=30
*.log_file_name_convert=’+data/eisoo/onlinelog’,’/data/oradata/eisoos’
*.open_cursors=300
*.pga_aggregate_target=453m
*.processes=300
*.remote_login_passwordfile=’exclusive’
*.sga_target=1361m
*.standby_file_management=’auto’
eisoos.undo_tablespace=’undotbs1′
2.启动到 nomout状态
sql> startup nomount pfile=’/u01/app/oracle/product/12.1.0/db_1/dbs/initeisoos.ora’;
oracle instance started.
total system global area 1442840576 bytes
fixed size 2924448 bytes
variable size 486539360 bytes
database buffers 939524096 bytes
redo buffers 13852672 bytes
sql>
sql>alter system set sec_case_sensitive_logon=false;
备注:sec_case_sensitive_logon参数是决定密码文件是否可以在本地创建,否则只能从主库拷贝到备库。默认值是“true”,
3.在本地创建密码文件
ocrl:/u01/app/oracle/product/12.1.0/db_1/dbs@oracle1>orapwd file=orapweisoos password=oracle entries=10 ignorecase=y force=y
4.配置监听文件,保证primary和standby能够互连
备库:
listener =
(description_list =
(description =
(address = (protocol = tcp)(host = 192.168.180.41)(port = 1521))
(address = (protocol = ipc)(key = extproc1521))
)
)
sid_list_listener =
(sid_list =
(sid_desc =
(global_dbname = eisoos)
(oracle_home = /u01/app/oracle/product/12.1.0/db_1)
(sid_name = eisoos)
)
)
或者
sid_list_listener_eisoos =
(sid_list =
(sid_desc =
(global_dbname = eisoos)
(oracle_home = /u01/app/oracle/product/12.1.0/db_1)
(sid_name = eisoos)
)
)
主库和备库是tnsname.ora 配置如下:
eisoo =
(description =
(address = (protocol = tcp)(host = 192.168.180.51)(port = 1521))
(connect_data =
(server = dedicated)
(service_name = eisoo)
)
)
eisoos =
(description =
(address = (protocol = tcp)(host = 192.168.180.41)(port = 1521))
(connect_data =
(server = dedicated)
(service_name = eisoos)
)
)
主备分别验证:
[oracle@rac1 ~]$ sqlplus sys/oracle@eisoo as sysdba
[oracle@rac1 ~]$ sqlplus sys/oracle@eisoos as sysdba
[oracle@rac2 ~]$ sqlplus sys/oracle@eisoo as sysdba
[oracle@rac2 ~]$ sqlplus sys/oracle@eisoos as sysdba
5.备份恢复数据
eisoos:/home/oracle@oracle1>rman target sys/oracle@eisoo auxiliary sys/oracle@eisoos
recovery manager: release 12.1.0.2.0 – production on mon sep 26 16:50:42 2016
copyright (c) 1982, 2014, oracle and/or its affiliates. all rights reserved.
connected to target database: eisoo (dbid=3774196505)
connected to auxiliary database: eisoo (not mounted)
rman> duplicate target database for standby from active database;
starting duplicate db at 2016/09/26 16:52:12
6.开启实时同步
sql> alter database recover managed standby database using current logfile disconnect from session;
验证:
1)
sql> select dest_name,error from v$archive_dest;//通过查看archive_log_dest_2列是否有error报错,如果有报错,则需要先根据报错内容解决问题
2)
查询主库最大归档序号和备库最大归档序号
select max(sequence#) from v$archived_log;
然后在主库切换日志:alter system switch logfile;
再次查询备库最大归档序号,一致即归档同步成功。
主库:
sql> select max(sequence#) from v$archived_log;
max(sequence#)
————–
133
sql> alter system switch logfile;
system altered.
sql> select max(sequence#) from v$archived_log;
max(sequence#)
————–
134
sql>
备库:
sql> select max(sequence#) from v$archived_log;
max(sequence#)
————–
134
sql>
3)
主库验证
sql>select sequence#, first_time, next_time, applied, archived from v$archived_log;
备库验证
sql>select sequence#, first_time, next_time, applied, archived from v$archived_log;
备注:观察主备库日志是否同步,如一致则表示日志cdp同步正常。
主备切换
1.检查dg是否同步是否正常
主库:
sql> select switchover_status,database_role from gv$database;
switchover_status database_role
——————– —————-
to standby primary
to standby primary
备库:
sql> select switchover_status,database_role from gv$database;
switchover_status database_role
——————– —————-
not allowed physical standby
2.准备切换工作:
关闭rac库,并把rac1起到open 状态
[oracle@rac1 ~]$ srvctl stop database -d eisoo
[oracle@rac1 ~]$ sqlplus / as sysdba
sql*plus: release 12.1.0.2.0 production on tue sep 27 09:12:25 2016
copyright (c) 1982, 2014, oracle. all rights reserved.
connected to an idle instance.
sql> startup
oracle instance started.
total system global area 1442840576 bytes
fixed size 2924448 bytes
variable size 553648224 bytes
database buffers 872415232 bytes
redo buffers 13852672 bytes
database mounted.
database opened.
sql>
3.开始切换
主库:
sql> alter database commit to switchover to physical standby with session shutdown;
重启到mount状态
sql> startup mount
oracle instance started.
total system global area 1442840576 bytes
fixed size 2924448 bytes
variable size 553648224 bytes
database buffers 872415232 bytes
redo buffers 13852672 bytes
database mounted.
sql>
查看数据库角色与状态
sql> select status from v$instance;
status
————
mounted
sql> select database_role from v$database;
database_role
—————-
physical standby
sql>
此时rac1已变成备库
备库:
sql> alter database commit to switchover to primary with session shutdown;
database altered.
sql> alter database open;
database altered.