oracle9i在windows上的dataguard配置

主库:win2003 server ora9i(9.2.0.1.0) 192.168.3.135主机名:data580 SID:PRIMARY
从库:win2003 server ora9i(9.2.0.1.0) 192.168.3.136主机名:data380 SID:STANDBY


1、主库和从库的Oracle 安装的时候都选择相同的安装路径 D:\oracle\ora92 ;并且先不要安装数据库,即在安装过程中“数据库配置”一项下面选择“只安装软件”;

2、在主库上使用DBCA(Database Configuration Assistant)建一个数据库,SID设为PRIMARY;

3、设置主库归档路径为d:\oracle\ora92\database\Archive :

      SQL> alter system set log_archive_dest_1='LOCATION=d:\oracle\ora92\database\Arch
                  ive MANDATORY' scope=both;

                 系统已更改。
4、将主库实例、数据库关闭,然后启动实例,但不打开数据库,只启动到数据库挂载模式:

      SQL> shutdown immediate;
                 数据库已经关闭。
                 已经卸载数据库。
                ORACLE 例程已经关闭。
      SQL> startup mount;
                ORACLE 例程已经启动。

               Total System Global Area  135338868 bytes
               Fixed Size                   453492 bytes
               Variable Size             109051904 bytes
               Database Buffers           25165824 bytes
               Redo Buffers                 667648 bytes
               数据库装载完毕。
5、将主库设置成归档状态和自动归档模式:

        SQL> alter database archivelog;

                   数据库已更改。

        SQL> alter system set log_archive_start=true scope=spfile;

                  系统已更改。

6、在主库上面创建从库的控制文件standby.ctl :

         SQL> alter database create standby controlfile as 'd:\oracle\oradata\standby.ctl';

                  数据库已更改。


7、在主库上面创建从库的初始化参数文件standby.ora(将其拷贝回从库后转换成从库的 spfile):

         SQL> create pfile='d:\oracle\oradata\standby.ora' from spfile;

                  文件已创建。

8、查看主库的数据文件及其的位置:

         SQL> select name from v$datafile;

                    NAME
                    --------------------------------------------------------------------------------

                    D:\ORACLE\ORADATA\PRIMARY\SYSTEM01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\UNDOTBS01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\CWMLITE01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\DRSYS01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\EXAMPLE01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\INDX01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\ODM01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\TOOLS01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\USERS01.DBF
                    D:\ORACLE\ORADATA\PRIMARY\XDB01.DBF

                    已选择10行。

9、关闭实例:

         SQL> shutdown immediate;
                    ORA-01109: 数据库未打开


                    已经卸载数据库。
                   ORACLE 例程已经关闭。


10、将第6步中的standby.ctl、第7步中的standby.ora和第8步骤中的数据文件、还有D:\oracle\oradata\PRIMARY路径下面的联机日志文件(REDO.LOG)、D:\oracle\ora92\database里面的口令文件PWDPRIMARY.ora备份出来,拷贝到从库中;在从库中创建路径D:\oracle\oradata\PRIMARY ,存放standby.ctl、数据文件、联机日志文件;创建路径D:\oracle\admin\PRIMARY ,在里面创建空文件夹bdump、cdump、udump、create、pfile ;将standby.ora 放到D盘根目录下面;将口令文件PWDPRIMARY.ora更名为PWDSTANDBY.ora ,放到从库的D:\oracle\ora92\database下面。


11、回到主库,启动主库实例和数据库:

        SQL> startup
                   ORACLE 例程已经启动。

                   Total System Global Area  135338868 bytes
                   Fixed Size                   453492 bytes
                   Variable Size             109051904 bytes
                   Database Buffers           25165824 bytes
                   Redo Buffers                 667648 bytes
                   数据库装载完毕。
                   数据库已经打开。


12、转回到从库,手动创建服务OracleServiceSTANDBY:

          C:\Documents and Settings\Administrator>oradim -new -sid STANDBY -startmode manual

          C:\Documents and Settings\Administrator>


           设置环境变量:在环境变量的“Administrator的用户变量”一栏里面新建一个值,变量名为ORACLE_SID ,变量值为STANDBY(服务名)。


13、创建主从库监听器OracleOraHome92TNSListener:进入Net Configuration Assistant ,使用“监听程序配置”来创建从库的监听器,同时会在D:\oracle\ora92\network\admin下面生成listener.ora文件:

主库listener.ora文件内容:

        # LISTENER.ORA Network Configuration File: D:\oracle\ora92\network\admin\listener.ora
        # Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = data580)(PORT = 1521))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = D:\oracle\ora92)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = primary)
      (ORACLE_HOME = d:\oracle\ora92)
      (SID_NAME = primary)
    )
  )

备库listener.ora内容:
# LISTENER.ORA Network Configuration File: D:\oracle\ora92\network\admin\listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = data380)(PORT = 1521))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = primary)
      (ORACLE_HOME = d:\oracle\ora92)
      (SID_NAME = primary)
    )
  )


14、配置主从库本地NET服务名:进入Net Configuration Assistant ,使用“本地NET服务名配置”来配置,同时会在D:\oracle\ora92\network\admin下面生成tnsnames.ora文件;


主库tnsnames.ora内容:
# TNSNAMES.ORA Network Configuration File: D:\oracle\ora92\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.136)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRIMARY)
    )
  )


PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.135)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRIMARY)
    )
  )


备库tnsnames.ora内容:
# TNSNAMES.ORA Network Configuration File: D:\oracle\ora92\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.136)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRIMARY)
    )
  )

PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.136)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRIMARY)
    )
  )


15、在主库上tnsping测试

C:\Documents and Settings\Administrator>tnsping standby

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 31-10月-2
009 21:55:53

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的参数文件:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.3.136)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRIMARY)))

OK(20毫秒)

C:\Documents and Settings\Administrator>tnsping primary

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 31-10月-2
009 21:56:03

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的参数文件:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.3.135)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRIMARY)))

OK(30毫秒)


在从库上tnsping测试

C:\Documents and Settings\Administrator>tnsping primary

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 31-10月-2
009 21:58:30

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的参数文件:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.3.135)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRIMARY)))

OK(10毫秒)

C:\Documents and Settings\Administrator>tnsping standby

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 31-10月-2
009 21:58:36

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

已使用的参数文件:
D:\oracle\ora92\network\admin\sqlnet.ora


已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.3.136)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRIMARY)))

OK(30毫秒)



16、修改D根目录下面的初始化参数文件standby.ora ,里面的全部内容如下(删除了原来的control_files参数,将instance_name改成了STANDBY,最后面的7行红体部分是新添加的内容):

*.aq_tm_processes=1
*.background_dump_dest='D:\oracle\admin\PRIMARY\bdump'
*.compatible='9.2.0.0.0'
*.core_dump_dest='D:\oracle\admin\PRIMARY\cdump'
*.db_block_size=8192
*.db_cache_size=25165824
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='PRIMARY'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=PRIMARYXDB)'
*.fast_start_mttr_target=300
*.hash_join_enabled=TRUE
*.instance_name='STANDBY'
*.java_pool_size=33554432
*.job_queue_processes=10
*.large_pool_size=8388608
*.log_archive_dest_1='LOCATION=d:\oracle\ora92\database\Archive MANDATORY'
*.log_archive_start=TRUE
*.open_cursors=300
*.pga_aggregate_target=25165824
*.processes=150
*.query_rewrite_enabled='FALSE'
*.remote_login_passwordfile='EXCLUSIVE'
*.shared_pool_size=50331648
*.sort_area_size=524288
*.star_transformation_enabled='FALSE'
*.timed_statistics=TRUE
*.undo_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='D:\oracle\admin\PRIMARY\udump'
*.standby_file_management=AUTO
*.remote_archive_enable=TRUE
*.lock_name_space='standby'
*.fal_server='primary'
*.fal_client='standby'
*.standby_archive_dest='d:\oracle\ora92\database\Archive'
*.control_files='d:\oracle\oradata\primary\STANDBY.CTL'


17、在从库中进入sqlplus将standby.ora创建成从库的spfile :

         C:\Documents and Settings\Administrator>sqlplus /nolog

            SQL*Plus: Release 9.2.0.1.0 - Production on 星期六 10月 31 15:19:12 2009

           Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

           SQL> conn /as sysdba
                      已连接到空闲例程。
           SQL> create spfile from pfile='d:\standby.ora';

                      文件已创建。


18、启动从库的实例,并且将从库设置成standby模式:

    SQL> startup nomount;
               ORACLE 例程已经启动。

              Total System Global Area  135338868 bytes
              Fixed Size                   453492 bytes
              Variable Size             109051904 bytes
              Database Buffers           25165824 bytes
              Redo Buffers                 667648 bytes
    SQL> alter database mount standby database;


19、在从库启动日志应用服务:

      SQL>alter database recover managed standby database disconnect from session;

20、转到主库,启动到物理从库的归档:

     SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=STANDBY' SCOPE=BOTH;(注意红色部分,这里我曾经出错)

                系统已更改。

     SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=BOTH;

               系统已更改。

上面两句SQL也可改为(alter system set log_archive_dest_2='service=standby mandatory reopen=60';),不过我没有做过


21、校验Data Guard的运转:

      (1)主库,归档当前日志:

           SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

                      系统已更改。
       (2)从库,校验归档日志是否正常接收:

           SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUEN
CE#;

                      SEQUENCE# FIRST_TIME NEXT_TIME
                      ---------- ---------- ----------
                      9 31-10月-09 31-10月-09
                      10 31-10月-09 31-10月-09
                      11 31-10月-09 31-10月-09
                      已选择6行。


        (3)从库,查看新的归档日志是否正常用于恢复:
       SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

                   SEQUENCE# APP
                   ---------- ---
                   9 YES
                   10 YES
                   11 YES
                   12 YES
                   13 YES
                   14 YES

                   已选择6行。

如果都是像以上那样的内容,都是YES的话,那就成功了。也可以分别查看主从库的D:\oracle\ora92\database\archive文件夹里面的内容,如果从库的和主库的内容一致,就算data guard配置成功了。


22、(这个时候从库只是将日志文件拿过来存放起来,但并没有执行日志文件,所以在主库上所做的操作无法在从库上得到结果,即无法在从库上查询数据。要在从库上查询数据,要执行以下语句:在从库上用sysdba 用户连接  Sql>alter database recover managed standby database disconnect from session ; Sql>alter database recover managed standby database cancel ; Sql>alter database open read only ; 查询数据即可。查询完成以后,需要恢复从库为恢复模式  Sql>alter database recover managed standby database disconnect from session ; 这个功能的可以用来查询前一天(或者前若干时间)以前的数据,比如报表之类的,因为今天只能查询昨天以前的报表,对数据的同步性的要求不是那么严格。查询完后一定要将从库设回恢复模式。)

这段内容我表示怀疑,第一次在从库上运行

      SQL> alter database recover managed standby database disconnect from session ;
              alter database recover managed standby database disconnect from session
               *
              ERROR 位于第 1 行:
              ORA-01153: 激活了不兼容的介质恢复
      说明managed media recover正在运行中

     在主库上以sysdba执行:

      SQL> conn /as sysdba
                  已连接。
      SQL> create table t(x varchar2(10));

                  表已创建。

      SQL> insert into t values('test1');

                  已创建 1 行。

      SQL> commit;

                  提交完成。

      SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

                  系统已更改。

      SQL>



     在从库上以sysdba 执行:

       SQL> conn /as sysdba
                  已连接。
       SQL> alter database recover managed standby database cancel ;

                   数据库已更改。

       SQL> alter database open read only ;

                   数据库已更改。

        SQL> select * from t;

                    X
                    ----------
                    test1

         在从库上查询完成以后,需要恢复从库为恢复模式

         SQL> alter database recover managed standby database disconnect from session ;

                     数据库已更改。
         查询完后一定要将从库设回恢复模式。


你可能感兴趣的:(dataguard)