• oracle DG搭建


    Oracle DG 搭建
    1、 环境
    OS IP hostname db_name DB_UNIQUE_NAME
    主库 RHEL 5.4 192.168.12.20 edgzrip1.oracle.com PROD1 PROD1
    备库 RHEL 5.4 192.168.12.30 edgzrip2.oracle.com PROD1 DG

    2、 设置主库开启归档
    SQL> alter database archivelog;
    Database altered.
    3、 设置主库开启强制记录日志
    SQL> alter database force logging;
    Database altered.
    4、 查询主库归档模式及日志强制记录
    SQL> select log_mode,force_logging from v$database;
    LOG_MODE FOR
    ------------ ---
    ARCHIVELOG YES
    5、 添加standby log
    SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/PROD1/standby04.log' size 50m;

    Database altered.

    SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/PROD1/standby05.log' size 50m;

    Database altered.

    SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/PROD1/standby06.log' size 50m;

    Database altered.

    SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/PROD1/standby07.log' size 50m;

    Database altered.
    6、 主库创建pfile
    SQL> create pfile from spfile;
    File created.
    7、 传送pfile到备库
    [root@edgzrip1 dbs]# scp initPROD1.ora edgzrip2:/u01/app/oracle/product/11.2.0/db_1/dbs/initDG.ora
    root@edgzrip2's password:
    initPROD1.ora
    8、 修改pfile
    在pfile追加以下参数
    DB_UNIQUE_NAME=PROD1
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD1,DG)'
    LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD1'
    LOG_ARCHIVE_DEST_2= 'SERVICE=DG ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DG'
    LOG_ARCHIVE_DEST_STATE_1=ENABLE
    LOG_ARCHIVE_DEST_STATE_2=ENABLE
    FAL_SERVER=DG
    DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/DG','/u01/app/oracle/oradata/PROD1'
    LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/DG','/u01/app/oracle/oradata/PROD1'
    STANDBY_FILE_MANAGEMENT=AUTO
    9、 使用新的pfile启动主库,并创建新的spfile
    Startup pfile=’/u01/app/oracle/product/11.2.0/db_1/dbs/initPROD1.ora’
    Create spfile from pfile;
    10、 传送密码文件orapwPROD1到备库
    [root@edgzrip1 dbs]# scp orapwPROD1 edgzrip2:/u01/app/oracle/product/11.2.0/db_1/dbs/ orapwDG

    11、 修改备库参数文件initDG.ora
    追加以下参数:
    DB_UNIQUE_NAME=DG
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(DG,PROD1)'
    LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DG'
    LOG_ARCHIVE_DEST_2= 'SERVICE=PROD1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD1'
    LOG_ARCHIVE_DEST_STATE_1=ENABLE
    LOG_ARCHIVE_DEST_STATE_2=ENABLE
    FAL_SERVER=PROD1
    DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/PROD1','/u01/app/oracle/oradata/DG'
    LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/PROD1','/u01/app/oracle/oradata/DG'
    STANDBY_FILE_MANAGEMENT=AUTO
    12、 在备库创建相应目录
    Mkdir –p /u01/app/oracle/oradata/DG
    Mkdir –p /u01/app/oracle/fast_recovery_area/DG
    Mkdir –p /u01/app/oracle/admin/DG/{a,dp}dump
    13、 使用备库pfile创建spfile,并启动到nomount状态
    [oracle@edgzrip2-DG ~]$ sqlplus / as sysdba
    Create spfile from pfile;
    Startup nomount
    14、 配置主库备库网络
    主库listener.ora:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (GLOBAL_DBNAME = PROD1.us.oracle.com)
    (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
    (SID_NAME = PROD1)
    )
    )

    LISTENER =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip1.oracle.com)(PORT = 1521))
    )

    ADR_BASE_LISTENER = /u01/app/oracle

    主库tnsnames.ora:
    PROD1 =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip1.oracle.com)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = PROD1.us.oracle.com)
    )
    )

    DG =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip2.oracle.com)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = DG.us.oracle.com)
    )
    )

    备库listener.ora:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (GLOBAL_DBNAME = DG.us.oracle.com)
    (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
    (SID_NAME = DG)
    )
    )

    备库tnsnames.ora:
    PROD1 =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip1.oracle.com)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = PROD1.us.oracle.com)
    )
    )

    DG =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip2.oracle.com)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = DG.us.oracle.com)
    )
    )

    测试主备库网络:
    启动主备库监听:lsnrctl start
    主库:
    [oracle@edgzrip1-PROD1 admin]$ tnsping prod1

    TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 26-AUG-2019 19:52:18

    Copyright (c) 1997, 2011, Oracle. All rights reserved.

    Used parameter files:


    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip1.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PROD1.us.oracle.com)))
    OK (10 msec)
    [oracle@edgzrip1-PROD1 admin]$ tnsping dg

    TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 26-AUG-2019 19:52:25

    Copyright (c) 1997, 2011, Oracle. All rights reserved.

    Used parameter files:


    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip2.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = DG.us.oracle.com)))
    OK (0 msec)

    备库:
    [oracle@edgzrip2-DG admin]$ tnsping prod1

    TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 26-AUG-2019 19:55:22

    Copyright (c) 1997, 2011, Oracle. All rights reserved.

    Used parameter files:


    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip1.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PROD1.us.oracle.com)))
    OK (10 msec)
    [oracle@edgzrip2-DG admin]$ tnsping dg

    TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 26-AUG-2019 19:55:26

    Copyright (c) 1997, 2011, Oracle. All rights reserved.

    Used parameter files:


    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = edgzrip2.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = DG.us.oracle.com)))
    OK (10 msec)
    确认主备库网络无问题
    15、 备库登录rman
    [oracle@edgzrip2-DG admin]$ rman target sys/oracle@prod1 auxiliary sys/oracle@dg

    Recovery Manager: Release 11.2.0.3.0 - Production on Mon Aug 26 19:56:30 2019

    Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

    connected to target database: PROD1 (DBID=2202819890)
    connected to auxiliary database: PROD1 (not mounted)

    RMAN>
    16、 执行duplicate
    RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;

    Starting Duplicate Db at 21-SEP-19
    using target database control file instead of recovery catalog
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: SID=19 device type=DISK

    contents of Memory Script:
    {
    backup as copy reuse
    targetfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwPROD1' auxiliary format
    '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwDG' ;
    }
    executing Memory Script

    Starting backup at 21-SEP-19
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=41 device type=DISK
    Finished backup at 21-SEP-19

    contents of Memory Script:
    {
    backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/DG/control01.ctl';
    restore clone controlfile to '/u01/app/oracle/fast_recovery_area/DG/control02.ctl' from
    '/u01/app/oracle/oradata/DG/control01.ctl';
    }
    executing Memory Script

    Starting backup at 21-SEP-19
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting datafile copy
    copying standby control file
    output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD1.f tag=TAG20190921T171431 RECID=2 STAMP=1019582073
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
    Finished backup at 21-SEP-19

    Starting restore at 21-SEP-19
    using channel ORA_AUX_DISK_1

    channel ORA_AUX_DISK_1: copied control file copy
    Finished restore at 21-SEP-19

    contents of Memory Script:
    {
    sql clone 'alter database mount standby database';
    }
    executing Memory Script

    sql statement: alter database mount standby database

    contents of Memory Script:
    {
    set newname for tempfile 1 to
    "/u01/app/oracle/oradata/DG/temp01.dbf";
    switch clone tempfile all;
    set newname for datafile 1 to
    "/u01/app/oracle/oradata/DG/system01.dbf";
    set newname for datafile 2 to
    "/u01/app/oracle/oradata/DG/sysaux01.dbf";
    set newname for datafile 3 to
    "/u01/app/oracle/oradata/DG/undotbs01.dbf";
    set newname for datafile 4 to
    "/u01/app/oracle/oradata/DG/users01.dbf";
    set newname for datafile 5 to
    "/u01/app/oracle/oradata/DG/example01.dbf";
    backup as copy reuse
    datafile 1 auxiliary format
    "/u01/app/oracle/oradata/DG/system01.dbf" datafile
    2 auxiliary format
    "/u01/app/oracle/oradata/DG/sysaux01.dbf" datafile
    3 auxiliary format
    "/u01/app/oracle/oradata/DG/undotbs01.dbf" datafile
    4 auxiliary format
    "/u01/app/oracle/oradata/DG/users01.dbf" datafile
    5 auxiliary format
    "/u01/app/oracle/oradata/DG/example01.dbf" ;
    sql 'alter system archive log current';
    }
    executing Memory Script

    executing command: SET NEWNAME

    renamed tempfile 1 to /u01/app/oracle/oradata/DG/temp01.dbf in control file

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    executing command: SET NEWNAME

    Starting backup at 21-SEP-19
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
    output file name=/u01/app/oracle/oradata/DG/system01.dbf tag=TAG20190921T171443
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:23
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
    output file name=/u01/app/oracle/oradata/DG/sysaux01.dbf tag=TAG20190921T171443
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:11
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
    output file name=/u01/app/oracle/oradata/DG/example01.dbf tag=TAG20190921T171443
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:38
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
    output file name=/u01/app/oracle/oradata/DG/undotbs01.dbf tag=TAG20190921T171443
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
    output file name=/u01/app/oracle/oradata/DG/users01.dbf tag=TAG20190921T171443
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
    Finished backup at 21-SEP-19

    sql statement: alter system archive log current

    contents of Memory Script:
    {
    backup as copy reuse
    archivelog like "/u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_09_21/o1_mf_1_9_grctj6gy_.arc" auxiliary format
    "/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_%u_.arc" archivelog like
    "/u01/app/oracle/fast_recovery_area/PROD1/archivelog/2019_09_21/o1_mf_1_10_grctprql_.arc" auxiliary format
    "/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_%u_.arc" ;
    catalog clone recovery area;
    switch clone datafile all;
    }
    executing Memory Script

    Starting backup at 21-SEP-19
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=9 RECID=4 STAMP=1019582086
    output file name=/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_07ucb5qs_.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=10 RECID=5 STAMP=1019582296
    output file name=/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_08ucb5qt_.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:02
    Finished backup at 21-SEP-19

    searching for all files in the recovery area

    List of Files Unknown to the Database
    =====================================
    File Name: /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_07ucb5qs_.arc
    File Name: /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_08ucb5qt_.arc
    cataloging files...
    cataloging done

    List of Cataloged Files
    =======================
    File Name: /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_07ucb5qs_.arc
    File Name: /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_08ucb5qt_.arc

    List of files in Recovery Area not managed by the database
    ==========================================================
    File Name: /u01/app/oracle/fast_recovery_area/DG/control02.ctl
    RMAN-07526: Reason: File is not an Oracle Managed File

    number of files not managed by recovery area is 1, totaling 9.28MB

    datafile 1 switched to datafile copy
    input datafile copy RECID=2 STAMP=1019582304 file name=/u01/app/oracle/oradata/DG/system01.dbf
    datafile 2 switched to datafile copy
    input datafile copy RECID=3 STAMP=1019582304 file name=/u01/app/oracle/oradata/DG/sysaux01.dbf
    datafile 3 switched to datafile copy
    input datafile copy RECID=4 STAMP=1019582304 file name=/u01/app/oracle/oradata/DG/undotbs01.dbf
    datafile 4 switched to datafile copy
    input datafile copy RECID=5 STAMP=1019582304 file name=/u01/app/oracle/oradata/DG/users01.dbf
    datafile 5 switched to datafile copy
    input datafile copy RECID=6 STAMP=1019582304 file name=/u01/app/oracle/oradata/DG/example01.dbf

    contents of Memory Script:
    {
    set until scn 879213;
    recover
    standby
    clone database
    delete archivelog
    ;
    }
    executing Memory Script

    executing command: SET until clause

    Starting recover at 21-SEP-19
    using channel ORA_AUX_DISK_1

    starting media recovery

    archived log for thread 1 with sequence 9 is already on disk as file /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_07ucb5qs_.arc
    archived log for thread 1 with sequence 10 is already on disk as file /u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_08ucb5qt_.arc
    archived log file name=/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_9_07ucb5qs_.arc thread=1 sequence=9
    archived log file name=/u01/app/oracle/fast_recovery_area/DG/archivelog/2019_09_21/o1_mf_1_10_08ucb5qt_.arc thread=1 sequence=10
    media recovery complete, elapsed time: 00:00:03
    Finished recover at 21-SEP-19
    Finished Duplicate Db at 21-SEP-19

    RMAN>


    17、 Duplicate完成后,在备库启用实时ADG

    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE OPEN_MODE
    ---------------- --------------------
    PHYSICAL STANDBY READ ONLY

    SQL> recover managed standby database using current logfile disconnect from session;
    Media recovery complete.
    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE OPEN_MODE
    ---------------- --------------------
    PHYSICAL STANDBY READ ONLY WITH APPLY

    SQL> select switchover_status,database_role,open_mode from v$database;

    SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE
    -------------------- ---------------- --------------------
    NOT ALLOWED PHYSICAL STANDBY READ ONLY WITH APPLY

    此时数据库状态时READ ONLY WITH APPLY,即只读且实时应用日志,通常所说的ADG,Active Data Guard。  

    READ ONLY WITH APPLY表示备库处于READ ONLY状态的同时可以接收主库传过来的日志文件并进行恢复,以便备库可以即时查看到主库的变化。

  • 相关阅读:
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    C语言基础知识【作用域规则】
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/11415227.html
Copyright © 2020-2023  润新知