Oracle高可用之dataguard

Oracle高可用之dataguard

    DataGuard 是一种数据库级别的 HA 方案,最主要功能是冗灾、数据保护、故障恢复等。
    在生产数据库的 " 事务一致性 " 时,使用生产库的物理全备份 ( 或物理 COPY) 创建备库,备库会通过生产库传输过来的归档日志 ( 或重做条目 ) 自动维护备用数据库。将重做数据应用到备用库。本文介绍使用 RMAN 备份创建备库 (dataguard).

:.环境

1.软件环境
操作系统 Red Linux Enterprise as 5
数据库版本 Oracle 10g release 2
2.primary databae
IP:192.168.18.1
ORACLE_SID=db1
db_unique_name=db1
3.standby database
IP:192.168.18.2
ORACLE_SID=standby
db_unique_name=standby

,主数据库(db1)做准备

1.设置主数据库为Force logging
SQL> alter database force logging;
2.创建密码文件
cd $ORACLE_HOME/dbs/
orapwd  file=orapwdb1 password=123456 force=y
3.修改主库的初始化参数
alter system set log_archive_config='dg_config=(db1,standby)' scope=both;
alter system set log_archive_dest_1='location=/u01/db1/arch' scope=both;
alter system set db_unique_name=' db1 ' scope=both;
5.生成数据库备份
RMAN> connect target sys/123456
RMAN> backup database format='/oracle/rmanback/%d_%s.dbf' plus archivelog;
[oracle@oracle rmanback]$ ls
DB 1 _1.dbf  DB 1 _2.dbf
6.生成备库的control file
SQL>alter database create standby controlfile as '/oracle/rmanback/ctontrl01.ctl
7.配置listener.ora tnsnames.ora文件
    启动 lintener.ora,
[oracle@oracle dbs]$ lsnrctl status
LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 14-JUN-2009 02:54:29
Service "db1" has 1 instance(s).
  Instance "db1", status READY, has 1 handler(s) for this service...
Service "db1_XPT" has 1 instance(s).
  Instance "db1", status READY, has 1 handler(s) for this service...
The command completed successfully
    配置 rnsnames.ora
vi $ORACLE_HOME/network/admin/tnsnames.ora
db1 =
   (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = db1)
standby =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = standby)
    )
  )

.创建standby database

1.设置环境变量并安装oracle软件
# 环境变量设成与主库一样
# 只安装软件不安装库
./runInstaller �Csilent �CresponseFile /tmp/installoracle.rsp
2.建立相关的目录
mkdir �Cp $ORACLE_BASE/admin/
cd $ORACLE_BASE/admin/ORACLE_SID
mkdir adump bdump cdump dpdump udump
3.建立密码文件
cd $ORACLE_HOME/dbs/
orapwd  file=orapwSID password=123456 force=y
# 注要密码要与主库的一样 , 否则会归档失败
3.建立参数文(pfile)
db_name = standby
shared_pool_size = 120M
undo_management = AUTO
undo_tablespace = undotbs
sga_max_size = 200M
sga_target = 160M
db_2k_cache_size = 4M
 
standby_file_management=AUTO
fal_server='db1'
fal_client=' standby '
log_archive_dest_1='location=/u01/app/oracle/product/10.2.0/dbs/arch'
log_archive_dest_2='SERVICE=db1 REOPEN=300'
log_archive_dest_state_1='ENABLE'
log_archive_dest_state_2='ENABLE'
4.CP主数据库RMAN备份控制备库
    注意:备份存放位置要与primary database RMAN备份文件的位置相同. 控制文件存放位置要与生成standby database controlfile的位置相同
scp /oracle/rmanback/*.dbf [email protected]:/oracle/rmanback/
scp /oracle/rmanback/*.ctl [email protected]:/oracle/oracle/oradata/ standby /
5.利用备用的控制文件,把备用数据库启到mount
SQL>connect / as sysdba
connnpcted to an idle instance
SQL>startup nomount pfile=$ORACLE_HOME / dbs / initstandby. ora
SQL>alter database mount standby database
6. 配置listener.ora tnsnames.ora文件.
与主库相同启动 listener,tnsnames.ora 也与主库配置的一样 ,
当主备库的监听都启动后 , 进行测试 , 以例下面能顺利进行
t nsping db1
t nsping standby
SQL> s qlplus sys/123456@db1
SQL> s qlplus sys/123456@standby
7.转储数据库
RMAN>connect target /
connected to target database TEST(DBID=788075692)
RMAN> restore database
8.恢复数据库
SQL>recover managed standby database disconnect from session
# 如果有需要 用的日志并想手工 用,可以运行如下命
SQL>recover automatic standby database
9.检查standby database是否创建成功
    1. primary database 上切换日志
SQL> alter system switch logfile
    2. primary database 上运行下面的语句
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
            17
    3.  standby database 上运行下面的语句
SQL> select sequence# ,applied from v$archived_log order by sequence#;
 SEQUENCE# APP
--------------------- ---
        15     YES
        16     YES
        17     YES
    若在上步中的 max sequence# 在的的 app 状态为 YES 说明 standby database 成功创建 .
10. spfile启动并设为只读
SQL> create spfile from pfile;
SQL> shutdown immedaite
SQL> startup mount
SQL> alter database recover managed standby database disconnect from session;
SQL> alter database open read only;

你可能感兴趣的:(oracle,高可用,dataguard,休闲,chenxy)