Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1149052
  • 博文数量: 231
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 2662
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-03 16:35
个人简介

学无止境

文章分类

全部博文(231)

文章存档

2014年(7)

2013年(103)

2011年(11)

2010年(53)

2009年(57)

分类: Oracle

2013-09-18 10:23:49

配置前提是primary数据库已经打开了归档模式,并且配置DG环境为异机配置,2个服务器的目录结构完全相同。
这样在配置DG的过程中,可以不需要重启primary数据库。

确认每个服务器上的/etc/hosts都配置正确,每个主机都能认到IP别名。

在standby服务器上建与主库服务器相同的目录结构,包括dump目录,datafile目录等。
$ mkdir -p /ogg/admin/billdb/{a,b,c,u}dump
$ mkdir -p /ogg/oradata/billdb

在standby服务器上建相同的归档目录,如果要分开目录,建立另外的standby归档目录
$ mkdir -p /ogg/billdb_arch1
$ mkdir -p /ogg/billdb_std1


确认primary数据库已经开启归档

开启primary数据库force logging
SQL> alter database force logging;

修改primary数据库2个必要的参数:
SQL> alter system set standby_file_management=AUTO;
SQL> alter system set log_archive_config='dg_config=(billdb,billdb2)';


在primary端创建一个pfile到一个临时路径,传输该pfile到standby端,进行修改。
SQL> create pfile='/ogg/billdb.ora' from spfile;
只修改其中一个参数:db_unique_name=billdb2
在standby端创建密码文件
$ orapwd file=$ORACLE_HOME/dbs/orapwbilldb password=oracle
在standby端创建spfile
SQL> create spfile from pfile;
将standby数据库启动到nomount状态。
SQL> startup nomount;


分别在2个数据库端修改listener.ora,修改内容如下,注意ORACLE_HOME的配置,如果2个数据库的ORACLE_HOME路径是相同的,就可以配置成一样的,如果不同需要修改。
注意GLOBAL_DBNAME,增加2个带_DGMGRL后缀的名称,前缀是每个数据库的db_unique_name
在SID_LIST_LISTENER中增加以下内容:
     (SID_DESC =
      (GLOBAL_DBNAME = billdb)
      (ORACLE_HOME=/opt/ora10g/product/10.2.0/db_1)
      (SID_NAME = billdb)
     )
    (SID_DESC =
      (GLOBAL_DBNAME = billdb2)
      (ORACLE_HOME=/opt/ora10g/product/10.2.0/db_1)
      (SID_NAME = billdb)
    )
     (SID_DESC =
      (GLOBAL_DBNAME = billdb_DGMGRL)
      (ORACLE_HOME=/opt/ora10g/product/10.2.0/db_1)
      (SID_NAME = billdb)
     )
    (SID_DESC =
      (GLOBAL_DBNAME = billdb2_DGMGRL)
      (ORACLE_HOME=/opt/ora10g/product/10.2.0/db_1)
      (SID_NAME = billdb)
    )

分别在2个数据库端修改tnsnames.ora
billdb =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.165.238)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = billdb)
    )
  )

billdb2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.165.239)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = billdb2)
    )
  )

在standby端增加/etc/oratab的信息。
billdb:/opt/ora10g/product/10.2.0/db_1:N


使用rman创建standby数据库:
$ rman target sys/oracle@billdb auxiliary sys/oracle@billdb2
在RMAN中检查一下配置,如果没有配置默认备份位置,最好配置一个,指定备份到某个目录,这样后面的命令就可以简化。
RMAN> show all;
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK format '/ogg/backup/dbbak_%d_%s_%p.BKP';

备份数据库:
RMAN> backup current controlfile for standby database;
将备份文件传输到standby端相同位置
$ scp /ogg/backup/*.BKP dgdb@dg1:/ogg/backuup
回到rman,由于是相同位置,不需要检查文件名。
RMAN> duplicate target database for standby nofilenamecheck;


创建standby logfile。注意,standby log最好大于online redo log数量:
primary和standby数据库上都执行相同的命令:
SQL> alter database add standby logfile group 4 ('/ogg/oradata/billdb/std01.log') size 100m;
SQL> alter database add standby logfile group 5 ('/ogg/oradata/billdb/std02.log') size 100m;
SQL> alter database add standby logfile group 6 ('/ogg/oradata/billdb/std03.log') size 100m;
SQL> alter database add standby logfile group 7 ('/ogg/oradata/billdb/std04.log') size 100m;


修改2个库的dg_broker_start参数:
SQL> alter system set dg_broker_start=true;


配置DG broker:
$ dgmgrl sys/oracle@billdb
DGMGRL> create configuration DGCONF as primary database is billdb connect identifier is billdb;
DGMGRL> add database billdb2 as connect identifier is billdb2 maintained as physical;
DGMGRL> enable configuration;
DGMGRL> show configuration verbose;
如果出现
Warning: ORA-16610: command 'EDIT DATABASE billdb SET PROPERTY' in progress
是正常的,说明操作正在进行中,等待一段时间后再检查,直到最后出现SUCCESS。
DGMGRL> show database verbose billdb;
DGMGRL> show database verbose billdb2;

检查数据库配置时,特别注意下StandbyArchiveLocation参数,该参数为指定standby归档日志存放的路径,最好设置为和归档日志同样的位置,否则可能会将归档日志保存到$ORACLE_HOME/dbs目录下。
DGMGRL> edit database billdb set PROPERTY StandbyArchiveLocation='/ogg/billdb_arch1';
DGMGRL> edit database billdb2 set PROPERTY StandbyArchiveLocation='/ogg/billdb_arch1';


配置完成后可以做一些归档切换的测试。


正常主备切换

DGMGRL> switchover to billdb2;

主数据库失败时切换
DGMGRL> failover to billdb2;


关于failover切换:

本文档中并未开启flashback,所以当发生failover切换之后无法通过
reinstate database billdb
这种方式进行DG环境的恢复,需要重建DG。

重建DG,例如现在primary数据库是billdb2,需要重建billdb为standby数据库。
先重新使用rman创建standby数据库。

再将2个数据库的dg_broker_config_file都删除,例如:
[oracle@node2 dbs]$ rm -fr dr2billdb.dat dr1billdb.dat

在DGMGRL中删除原配置,然后重新增加配置。
DGMGRL> remove configuration;
Removed configuration
DGMGRL> show configuration verbose
Error: ORA-16532: Data Guard broker configuration does not exist

Configuration details cannot be determined by DGMGRL
DGMGRL> create configuration DGCONF as primary database is billdb2 connect identifier is billdb2;
Configuration "dgconf" created with primary database "billdb2"
DGMGRL> add database billdb as connect identifier is billdb maintained as physical;
Database "billdb" added
DGMGRL> enable configuration;
Enabled.
DGMGRL> show configuration verbose;

Configuration
  Name:                dgconf
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    billdb2 - Primary database
    billdb  - Physical standby database

Current status for "dgconf":
Warning: ORA-16610: command 'EDIT DATABASE billdb SET PROPERTY' in progress


DGMGRL> show configuration verbose;

Configuration
  Name:                dgconf
  Enabled:             YES
  Protection Mode:     MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
    billdb2 - Primary database
    billdb  - Physical standby database

Current status for "dgconf":
SUCCESS


关于DG备份 

备份dataguard数据库可以和备份正常数据库一样,但要注意备份归档日志时不能执行sql语句切换日志,所以sql脚本不宜出现在rman脚本中。

 


附录:

billdb数据库的创建语句:

CREATE DATABASE billdb
   USER SYS IDENTIFIED BY oracle
   USER SYSTEM IDENTIFIED BY oracle
   LOGFILE GROUP 1 ('/ogg/oradata/billdb/redo01a.log') SIZE 100M,
           GROUP 2 ('/ogg/oradata/billdb/redo02a.log') SIZE 100M,
           GROUP 3 ('/ogg/oradata/billdb/redo03a.log') SIZE 100M
   MAXLOGFILES 20
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 200
   MAXDATAFILES 1000
   MAXINSTANCES 1
   CHARACTER SET UTF8
   NATIONAL CHARACTER SET AL16UTF16
   DATAFILE '/ogg/oradata/billdb/system01.dbf' SIZE 350m autoextend on
   EXTENT MANAGEMENT LOCAL
   SYSAUX DATAFILE '/ogg/oradata/billdb/sysaux01.dbf' SIZE 350m autoextend on
   DEFAULT TEMPORARY TABLESPACE temp
      TEMPFILE '/ogg/oradata/billdb/temp01.dbf'
      SIZE 200m autoextend on maxsize 2048m
   UNDO TABLESPACE undotbs
      DATAFILE '/ogg/oradata/billdb/undotbs01.dbf'
      SIZE 200m autoextend on maxsize 2048m;

数据库0级备份脚本:
rman target sys/oracle@billdb
run {
crosscheck archivelog all;
delete noprompt expired archivelog all;
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup
incremental level 0
format "/ogg/backup/%d_full_%s_%p_%D_%M"
filesperset  5
database
include current controlfile;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}


数据库1级备份脚本:
run {
allocate channel i1 type disk;
allocate channel i2 type disk;
allocate channel i3 type disk;
allocate channel i4 type disk;
backup
incremental level 1
format "/ogg/backup/%d_incr_%s_%p_%D_%M"
filesperset 5
database
include current controlfile;
release channel i1;
release channel i2;
release channel i3;
release channel i4;
}


数据库归档备份脚本:
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
crosscheck archivelog all;
delete expired archivelog all;
backup
format "/ogg/backup/%d_arch_%s_%p_%D_%M"
archivelog all delete input
filesperset 5;
release channel t1;
release channel t2;
}

删除过期归档及控制文件脚本:
run {
crosscheck backup of archivelog all;
delete backup of archivelog all completed before 'sysdate-9' device type disk;
delete backup of controlfile completed before 'sysdate-9' device type disk;
}

删除过期数据库备份脚本:
run {
crosscheck backup of database;
delete backup of database completed before 'sysdate-9' device type disk;
crosscheck backup;
crosscheck archivelog all;
report obsolete;
delete noprompt obsolete;
delete noprompt expired backup;
}

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