Chinaunix首页 | 论坛 | 博客
  • 博客访问: 676374
  • 博文数量: 163
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1625
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-24 11:40
个人简介

资深Oracle数据库专家 OCM认证大师 10年数据库相关服务及开发经验 各类数据库相关方案的编写,管理及实施 数据中心数据库日常运维、大型项目割接、性能优化等方面有丰富的实战经验 客户包括: 电信,银行,保险,航空,国网,汽车,烟草等 想要一起学习探讨数据安全技术的请加qq群 256041954

文章分类

全部博文(163)

文章存档

2017年(2)

2016年(112)

2015年(38)

2014年(11)

我的朋友

分类: Oracle

2016-04-26 21:11:29

一:注意事项
1:
目录不同
db_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/oradu/')
log_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/oradu/')
必须设置


2:
创建密码文件,必须保持target DB和auxiliary DB的密码一致。这里我直接对target DB密码文件重命名使用
[root@oracledba dbs]# cp orapworcl orapworadu

3:
开始复制,复制时需要注意是否使用nofilenamecheck参数,如果两个实例相关数据目录结构完全相同,则需要指定,否则会报错。这里不需要使用。复制日志太多,有兴趣的可以看看,或者


跳过直接看结果!
[oracle@oracledba ~]$ export ORACLE_SID=oradu    --------异机操作可省略此步操作
[oracle@oracledba ~]$rman target sys/oracle@orcl auxiliary sys/oracle@oradu


duplicate target database to oradu from active database;


如果目录相同:
duplicate target database to oradu from active database nofilenamecheck;


4:
 alter database open read only;


5:ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;


6:特别注意:在修改主库参数时必须创建pfile 
create pfile='/home/oracle/init.ora' from spfile;

         二:ADG配置
1、确定数据库是否为归档模式


On primarydb:


 select log_mode from v$database;
 archive log list;


2、开启强制日志模式


On primarydb:


 select FORCE_LOGGING from v$database;
 ALTER DATABASE FORCE LOGGING;


3、验证是否有密码文件(HA备库也验证)


On primarydb:


cd $ORACLE_HOME/dbs
ls orap*






4、添加standby redo


On primarydb:


确认redo 大小和路径


set linesize 200
col member for a55
select a.group#,a.thread#,b.type,a.bytes/1024/1024 mb ,b.member from v$log a ,v$logfile b where a.group#=b.group#;


select a.group#,a.thread#,b.type,a.bytes/1024/1024 mb ,b.member from v$standby_log a ,v$logfile b where a.group#=b.group#;


alter database add standby logfile thread 1 group 11 '/oradata/PROD/redo11.log' size 1000M;
alter database add standby logfile thread 1 group 12 '/oradata/PROD/redo12.log' size 1000M;
alter database add standby logfile thread 1 group 13 '/oradata/PROD/redo13.log' size 1000M;
alter database add standby logfile thread 1 group 14 '/oradata/PROD/redo14.log' size 1000M;
alter database add standby logfile thread 1 group 15 '/oradata/PROD/redo15.log' size 1000M;
                                                                    
alter database add standby logfile thread 2 group 16 '/oradata/PROD/redo16.log' size 1000M;
alter database add standby logfile thread 2 group 17 '/oradata/PROD/redo17.log' size 1000M;
alter database add standby logfile thread 2 group 18 '/oradata/PROD/redo18.log' size 1000M;
alter database add standby logfile thread 2 group 19 '/oradata/PROD/redo19.log' size 1000M;
alter database add standby logfile thread 2 group 20 '/oradata/PROD/redo20.log' size 1000M;


/oradata/PROD/




5、修改主库参数


On primarydb:


alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD,PRODDG)';


alter system set LOG_ARCHIVE_DEST_1='LOCATION=+FRADG/PROD/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD';


alter system set LOG_ARCHIVE_DEST_3='SERVICE=PRODDG LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PRODDG';


alter system set fal_server='PRODDG';






alter system set standby_file_management=AUTO scope=both;




下列2个参数需要下次重启后生效


alter system set DB_FILE_NAME_CONVERT='/oradata/PROD/','+DATADG/PROD/data/' scope=spfile;


alter system set LOG_FILE_NAME_CONVERT='/oradata/PROD/','+DATADG/PROD/data/' scope=spfile;










7、创建备库静态监听文件


On Standbydb:


cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin


vi listener.ora


LISTENER =
  (ADDRESS_LIST=
        (ADDRESS=(PROTOCOL=tcp)(HOST= 10.18.0.210)(PORT=1521))
  )


SID_LIST_LISTENER=
   (SID_LIST=
        (SID_DESC=
          (GLOBAL_DBNAME=PRODDG)
          (SID_NAME= PRODDG)
          (ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1)
         )
        )




8、启动备库监听


On Standbydb:


lsnrctl start




9、修改主、备库的TNSNAMES文件(主库另外一节点也要复制)






PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.18.0.83)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD)
    )
  )


PRODDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.18.0.210)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PRODDG)
    )
  )










11、tnsping测试,确保都能通


主库:(主库另外一节点也要测试)


On Primarydb:


 tnsping PROD
 tnsping PRODDG


备库:


On Standbydb:


 tnsping PROD
 tnsping PRODDG




12、创建备库密码文件


从主库中scp 密码文件备库,sys密码不能有下划线


On Primarydb:


cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs
scp orapwPROD1   10.18.0.210:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwPRODDG






13、为备库创建初始化参数文件






On Primarydb:




create pfile= '/tmp/p.ora' from spfile;


scp /tmp/p.ora  10.18.0.210:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/












修改参数文件


On Standbydb:


cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/


*.db_unique_name='PRODDG'
*.fal_server='PROD'
*.log_archive_dest_1='location=/arch/PROD  VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PRODDG'
*.log_archive_dest_3='service=PROD lgwr async noaffirm valid_for=(online_logfiles,primary_role) db_unique_name=PROD'
*.db_create_file_dest='/oradata'
*.db_file_name_convert='+DATADG/PROD/','/oradata/PROD/'
*.log_file_name_convert='+DATADG/PROD/','/oradata/PROD/'
*.control_files='/oradata/PROD/controlfile/ctrol01.ctl','/oradata/PROD/controlfile/ctrol02.ctl'


#*.cluster_database=true
#testdb2.thread=2
#testdb1.thread=1
#testdb1.instance_number=1
#testdb2.instance_number=2
#*.remote_listener='testcluster:1521'
*.undo_tablespace='UNDOTBS1'
#testdb2.undo_tablespace='UNDOTBS2'




 检查文件目录权限
 /oradata
 /arch


 chown -R oracle:oinstall /oradata
 chown -R oracle:oinstall /arch








14、创建备库相应目录


On Standbydb:


su - oracle






mkdir -p /u01/app/oracle/admin/PROD/adump
mkdir -p /oradata/PROD/datafile
mkdir -p /oradata/PROD/tempfile
mkdir -p /oradata/PROD/onlinelog
mkdir -p /oradata/PROD/controlfile
mkdir -p /arch/PROD




15、为备库创建spfile




On Standbydb:


export ORACLE_SID=PRODDG
SQL> startup nomount pfile='/tmp/p.ora'
SQL> create spfile from pfile='/tmp/p.ora';


16、关闭重启
shutdown abort
startup nomount
SQL> show parameter name
SQL> show parameter log


17、连接至主数据库作为其目标数据库,以运行创建备用 ON STANDBY


On Primarydb:








sqlplus sys/oracle@PROD as sysdba
sqlplus sys/oracle@PRODDG as sysdba


On Standbydb:


sqlplus sys@PROD as sysdba
<<< sqlplus sys@PRODDG as sysdba
<<<







18、配置dataguard备库




On Primarydb:


export ORACLE_SID=PROD1


sqlplus / as sysdba
show parameter name
exit


export ORACLE_SID=PROD1
rman target  sys/oracle auxiliary sys/oracle@PRODDG nocatalog < run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database;
}
exit
EOF




19、只读模式打开数据库


备库:


alter database open;


20、应用实时日志


备库:


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




alter database recover managed standby database disconnect from session;




21 ,check
#on standby 
select * from v$archive_gap;
select process,client_process,sequence#,status from v$managed_standby;
select database_role,protection_mode,protection_level,open_mode from v$database;


set linsize 200
 col value for a20
 col name for a30
 col time for a30
 col time_computed for a20
 select to_char(SYSDATE,'yyyymmdd hh24:mi:ss') CTIME,NAME,VALUE,DATUM_TIME from V$DATAGUARD_STATS WHERE NAME LIKE '%lag'; 






shutdown immediate;
startup 
recover managed standby database using current logfile disconnect from session;


#on primary
create table adg_tst (id int);
insert into adg_tst values(1);
commit;
alter system switch logfile;
alter system archive log current;


#on standby 
select * from adg_tst;



阅读(4488) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~