DataGuard具体搭建环节
在上一篇blog中,详细介绍DataGuard实现的原理,本篇介绍DataGuard的具体搭建过程。
主库打开日志,并强制force logging
SQL>shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
select force_logging from v$database;
alter database force logging;
主库打开主库打开dataguard开关
语句
--alter system set log_archive_config='dg_config=(主库的唯一名,从库1的唯一名,从库2的唯一名...)';
样例中使用名字是orcl和aux1
SQL>alter system set log_archive_config='dg_config=(orcl,aux1)';
修改主库本地归档参数
mkdir -p /home/oracle/arc_orcl_dest1/
--alter system set log_archive_dest_1='location=/home/oracle/arc_orcl_dest1/ valid_for=(日志类型,数据库的角色) db_unique_name=orcl';
具体参考的
SQL>alter system set log_archive_dest_1='location=/home/oracle/arc_orcl_dest1/ valid_for=(online_logfiles,primary_role) db_unique_name=orcl';
其中参数解释
日志类型:all_logfiles | online_logfiles | standby_logfiles
数据库的角色:all_roles | primary_role | standby_role
激活主库本地归档路径
SQL>alter system set log_archive_dest_state_1='enable';
主库打开远程归档
--alter system set log_archive_dest_3='service=服务命名 valid_for=(日志类型,数据库的角色) db_unique_name=从库唯一名';
SQL>alter system set log_archive_dest_3='service=aux1srv valid_for=(online_logfiles,primary_role) db_unique_name=aux1';
.激活主库远程归档路径
SQL>alter system set log_archive_dest_state_3='enable';
为从库准备口令文件
scp $ORACLE_HOME/dbs/orapw$ORACLE_SID oracle@install0:$GRID_HOME/dbs/orapwaux1
其中 $ORACLE_HOME/dbs/orapw$ORACLE_SID 是oracle的口令文件,这一步可以不做,这样做是为了保持密码一致。
为从库准备参数文件
在主库生成pfile,修改:
create pfile='/home/oracle/p.ora' from spfile;
然后 scp pfile 到从从库的 $ORACLE_HOME/dbs/initaux1.ora
修改 $ORACLE_HOME/dbs/initaux1.ora
注意路径
*.aq_tm_processes=1
*.compatible='11.2.0.4.0'
*.db_block_size=8192
*.db_domain='example.com'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=100
*.memory_max_target=943718400
*.memory_target=843055104
*.open_cursors=500
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.utl_file_dir='/home/oracle'
log_archive_config='dg_config=(orcl,aux1)'
db_unique_name='aux1'
audit_file_dest='/u01/app/oracle/admin/aux1/adump'
control_files='/u01/app/oracle/oradata/aux1/control01.ctl'
standby_file_management=auto
log_archive_dest_2='location=/home/oracle/arc_aux1_dest2/ valid_for=(standby_logfiles,standby_role) db_unique_name=aux1'
db_file_name_convert='/home/oracle/coldbk/','/u01/app/oracle/oradata/aux1/'
log_file_name_convert='/home/oracle/coldbk/','/u01/app/oracle/oradata/aux1/'
从库相关路径
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/admin/aux1/adump
mkdir -p /u01/app/oracle/oradata/aux1
mkdir -p /home/oracle/arc_aux1_dest2
chmod -R 775 /u01/app/oracle/admin/aux1/adump
启动从库实例
export ORACLE_SID=aux1
sqlplus / as sysdba
create spfile from pfile;
startup nomount
在从库配置并启动监听程序
lsnrctl stop
vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = aux1.example.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = aux1)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.11)(PORT = 1521))
)
lsnrctl start
其中 172.25.0.11 是从库ip地址
在主库配置服务命名
vi $ORACLE_HOME/network/admin/tnsnames.ora
aux1srv =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aux1.example.com)
)
)
在主库使用网络连接从库(测试)
sqlplus sys/oracle@aux1srv as sysdba
在主库启动rman复制从库
rman target / auxiliary sys/oracle@aux1srv
RMAN> duplicate target database for standby from active database;
如果数据库文件的目录和主库一样
RMAN> duplicate target database for standby from active database nofilenamecheck;
这是一个常用方法,包括如果迁移数据库的时候也可以用这个办法
检查
在完成以上工作以后需要做最后一次检查
查看归档徐磊
SQL>select sequence#,name from v$archived_log;
在主库切换日志查看从库是否得到新的日志
SQL>alter system switch logfile;
ll /home/oracle/arc_aux1_dest2/ ()
在主库查看远程归档有什么错误
SQL>select error from v$archive_dest where dest_id=3;
如果发现错误,排除错误以后
SQL>alter system set log_archive_dest_state_3='enable';
按照主库连机日志的大小在从库创建standby log
SQL>alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo04.log' size 52428800;
SQL>alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo05.log' size 52428800;
SQL>alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo06.log' size 52428800;
以只读方式打开从库
SQL>alter database open read only;
至此大功告成。