ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle 10g R2 dataguard

oracle 10g R2 dataguard

原创 Linux操作系统 作者:wang_0720 时间:2013-11-06 14:52:55 0 删除 编辑
确定数据库版本
SYS>select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 
   10.2.0.1.0    Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
前期规划
           Global Database Name   SID      DB_UNIQUE_NAME
primary    oracleDB               primDB   primDB
standby    oracleDB               stanDB   stanDB
hostname 
192.168.151.143 primDB
hostname
192.168.151.2 stanDB
安装oracle在此不详述
日志归档
开启primary和standby的数据库归档强制归档属性并查看
SYS>alter database force logging;
Database altered.
SYS>SELECT DBID, NAME, LOG_MODE, FORCE_LOGGING FROM V$DATABASE;

      DBID NAME      LOG_MODE      FOR
---------- --------- ------------ ---
3434715927 ORACLEDB  ARCHIVELOG   YES
准备初始化参数文件
primDB的初始化参数文件
create pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initprimDB.ora' from spfile;
修改initprimDB.ora,红色部分为添加的内容
shutdown immediate;
vim initprimDB.ora
DB_UNIQUE_NAME=primDB
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primDB,stanDB)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/flash_recovery_area/ORACLEDB/archivelog
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=primDB'
LOG_ARCHIVE_DEST_2='SERVICE=stanDB
LGWR SYNC AFFIRM
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=stanDB'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
FAL_SERVER=primDB
FAL_CLIENT=stanDB
STANDBY_FILE_MANAGEMENT=AUTO

注意:1 /u01/app/oracle/flash_recovery_area/ORACLEDB/archivelog需要手动创建
      2
SERVIC=stanDB中的stanDB是在本机上配置的数据库服务名用于访问standby数据库
pfile创建spfile
sqlplus / as sysdba
SQL>create spfile from pfile='
/u01/app/oracle/product/10.2.0/db_1/dbs/initprimDB.ora';
SQL>startup 启动数据库验证初始化参数文件是否创建正确
standby 初始化参数文件
SQL>create pfile='
/u01/app/oracle/product/10.2.0/db_1/dbs/initstanDB.ora' from spfile;
修改initstanDB.ora,添加红色部分内容
vim initstanDB.ora
DB_UNIQUE_NAME=stanDB
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primDB,stanDB)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/flash_recovery_area/ORACLEDB/archivelog
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=stanDB'
LOG_ARCHIVE_DEST_2='SERVICE=primDB
LGWR SYNC AFFIRM
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=primDB'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
FAL_SERVER=stanDB
FAL_CLIENT=primDB
STANDBY_FILE_MANAGEMENT=AUTO
注意:1 /u01/app/oracle/flash_recovery_area/ORACLEDB/archivelog需要手动创建
      2
SERVIC=primDB中的stanDB是在本机上配置的数据库服务名用于访问primary数据库
用pfile创建spfile
sqlplus / as sysba
SQL>create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initstanDB.ora';
SQL>startup 启动验证参数文件是否正确
创建密码文件,控制文件
创建密码文件,primary,standby密码要相同
orapwd file='/u01/app/oracle/product/10.2.0/db_1/dbs/orapwstanDB' password=sys entries=30
在primary数据库上创建standby数据库要用到的控制文件
SQL>alter database create standby controlfile as '/u01/app/oracle/back/control01.ctl';
SQL>host cp /u01/app/oracle/back/control01.ctl /u01/app/oracle/back/control02.ctl
SQL>host cp /u01/app/oracle/back/control01.ctl /u01/app/oracle/back/control03.ctl
删除standby数据库中所有的控制文件,数据文件,在线日志文件
关闭primary,standby数据库,复制/u01/app/oracle/back/中的控制文件副本,primary中所有的数据文件,在线日志文件到standby数据库对应的位置。注意,所属权限。
创建standby redo log
启动primary,standby数据库到mount状态,创建standby redo log
alter database add standby logfile '/u01/app/oracle/oradata/oracleDB/standby_redo01.log' size 50M;
alter database add standby logfile '/u01/app/oracle/oradata/oracleDB/standby_redo02.log' size 50M;
alter database add standby logfile '/u01/app/oracle/oradata/oracleDB/standby_redo03.log' size 50M;
alter database add standby logfile '/u01/app/oracle/oradata/oracleDB/standby_redo04.log' size 50M;
数量至少要比在线日志多一个,大小和在线日志一样大
网络配置
primary
vim /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsname.ora
primDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.151.143)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primDB)
    )
  )

stanDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.151.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stanDB)
    )
  )
standby
vim /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsname.ora
primDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.151.143)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primDB)
    )
  )

stanDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.151.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stanDB)
    )
  )
standby数据库启动redo应用
alter database recover managed standby database disconnect from session;
启动primary到open状态,测试同步效果
在primary建表
SYS>create table scott.e as select * from scott.emp;
standby切换到read only状态
停止日志应用服务,在该模式下可以切换为read only状态
alter database recover managed standby database cancel;
alter database open read only;
查看是否有e表生成
SYS>select table_name from all_tables where owner='SCOTT';

TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE
E
有e表生成,说明同步成功。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27181165/viewspace-775870/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    111
  • 访问量
    913628