zoukankan      html  css  js  c++  java
  • 搭建DG(data guard),及搭建过程中遇到的一些小问题 高伟

    一.准备工作:主库:虚拟机名称host06 主机名:host06 IP:192.168.100.60 db_name&SID:ENMO  db_unique_name:PROD 存储:文件系统

                     备库:虚拟机名称:host07 主机名:host07 IP:192.168.100.70 db_name&SID:ENMO db_unique_name:SBDB 存储:文件系统

    二.主库:

    1.数据库归档并强制生成日志

    [oracle@host06 ~]$ sqlplus / as sysdba

    SQL> select status from v$instance;

    SQL> archive log list;

    Database log mode              No Archive Mode
    Automatic archival             Disabled
    Archive destination            /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
    Oldest online log sequence     4
    Current log sequence           6

    SQL> shutdown immediate;

    SQL> alter database archivelog;

    SQL> alter database force logging;

    SQL> alter database open;

    SQL> archive log list; 
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
    Oldest online log sequence     4
    Next log sequence to archive   6
    Current log sequence           6
    SQL> select force_logging from v$database;

    FOR
    ---
    YES

    2.主库创建 standby logfile,原则是最大日志组数+1

    SQL> select group#,member from v$logfile; 查看日志组数

    SQL> select group#,bytes/1024/1024 as size_m from v$log; 查看日志组大小

    SQL> alter database add standby logfile group 4 ('/u01/app/oracle/oradata/ENMO/standby_redo04.log') size 50m;  创建standby logfile

    SQL> alter database add standby logfile group 5 ('/u01/app/oracle/oradata/ENMO/standby_redo05.log') size 50m;

    SQL>  alter database add standby logfile group 6 ('/u01/app/oracle/oradata/ENMO/standby_redo06.log') size 50m;

    SQL> alter database add standby logfile group 7 ('/u01/app/oracle/oradata/ENMO/standby_redo07.log') size 50m;

    3.查看添加的日志组

    SQL> select group#,sequence#,bytes,status from v$standby_log;

        GROUP#  SEQUENCE#      BYTES STATUS
    ---------- ---------- ---------- ----------
             4          0   52428800 UNASSIGNED
             5          0   52428800 UNASSIGNED
             6          0   52428800 UNASSIGNED
             7          0   52428800 UNASSIGNED

    SQL> select group#,type,member from v$logfile;

    4.主库查看当前参数文件

    SQL> host                   
    [oracle@host06 ~]$ cd $ORACLE_HOME/dbs
    [oracle@host06 dbs]$ ls
    hc_ENMO.dat  init.ora  lkENMO  orapwENMO  spfileENMO.ora

    5.生成pfile文件并修改

    SQL> create pfile from spfile;

    File created.

    SQL> host
    [oracle@host06 ~]$ cd $ORACLE_HOME/dbs
    [oracle@host06 dbs]$ ls
    hc_ENMO.dat  initENMO.ora  init.ora  lkENMO  orapwENMO  spfileENMO.ora
    [oracle@host06 dbs]$ vi initENMO.ora

    追加如下内容

    db_unique_name=PROD
    log_archive_format=%t_%s_%r.arc
    log_archive_config='DG_CONFIG=(PROD,SBDB)'
    LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/FRA
    VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD'
    LOG_ARCHIVE_DEST_2='SERVICE=ENMO70      LGWR                               SYNC
    VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=SBDB'
    log_archive_dest_state_1=ENABLE
    log_archive_dest_state_2=ENABLE
    LOG_ARCHIVE_MAX_PROCESSES=4
    ## Paraneters which using for switch over from Primary to Standby.
    fal_server=ENMO70
    standby_file_management=AUTO
    db_file_name_convert='ENMO','ENMO'
    log_file_name_convert='ENMO','ENMO'

    6.通过pfile重新生成spfile并启动数据库

    SQL> shutdown immediate;

    SQL> create spfile from pfile;

    SQL> startup

    SQL> show parameter name;

    7.主库配置tnsnames(注:数据库service_name默认与db_unique_name相同)

    [oracle@host06 dbs]$ cd $ORACLE_HOME/network/admin
    [oracle@host06 admin]$ ls
    listener.ora  samples  shrept.lst
    [oracle@host06 admin]$ vi tnsnames.ora
    ENMO60 =
      (DESCRIPTION =
        (ADDESS_LIST =
          (ADDERSS = (PROTOCOL = TCP)(HOST = 192.168.100.60)(PORT = 1521))
        )
        (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = PROD)
        )
       )

    ENMO70 =
     (DESCRIPTION =
      (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.70)(PORT = 1521))
      )
      (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = SBDB)
      )
     )

    8.主库 拷贝相关文件至备库

    找到主库文件所在目录

    [oracle@host06 admin]$ cd $ORACLE_HOME/dbs

    [oracle@host06 dbs]$ ls
    hc_ENMO.dat  initENMO.ora  init.ora  lkENMO  lkPROD  orapwENMO  spfileEN

    拷贝密码文件

    [oracle@host06 dbs]$ scp orapwENMO oracle@192.168.100.70:$ORACLE_HOME/dbs/orapwENMO

    拷贝pfile参数文件

    [oracle@host06 dbs]$ scp initENMO.ora oracle@192.168.100.70:$ORACLE_HOME/dbs/initENMO.ora

    拷贝tnsnames配置文件

    [oracle@host06 dbs]$ scp $ORACLE_HOME/network/admin/tnsnames.ora oracle@192.168.100.70:$ORACLE_HOME/network/admin/tnsnames.ora

    二.备库

    1.备库创建静态监听并启动

    [oracle@host07 admin]$ cd $ORACLE_HOME/dbs
    [oracle@host07 dbs]$ ls
    initENMO.ora  init.ora  orapwENMO
    [oracle@host07 dbs]$ vi initENMO.ora

    因为主库备库的DB_NAME和SID相同,所以只需改如下参数(已加粗)即可

    db_unique_name=SBDB

    log_archive_format=%t_%s_%r.arc

    log_archive_config='DG_CONFIG=(PROD,SBDB)'

    LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/FRA

    VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=SBDB'

    LOG_ARCHIVE_DEST_2='SERVICE=SBDB60      LGWR                               SYNC

    VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD'

    log_archive_dest_state_1=ENABLE

    log_archive_dest_state_2=ENABLE

    LOG_ARCHIVE_MAX_PROCESSES=4

    ## Paraneters which using for switch over from Primary to Standby.

    fal_server=SBDB60

    standby_file_management=AUTO

    db_file_name_convert='ENMO','ENMO'

    "initENMO.ora" 38L, 1415C written

    2.按照参数创建文件目录

    [oracle@host07 dbs]$ mkdir -p /u01/app/oracle/admin/ENMO/adump
    [oracle@host07 dbs]$ mkdir -p /u01/app/oracle/oradata/ENMO/
    [oracle@host07 dbs]$ mkdir -p /u01/app/oracle/FRA

    3.备库通过pfile生成spfile并启动数据库至nomount

    [oracle@host07 dbs]$ echo $ORACLE_SID

    SQL> create spfile from pfile;

    SQL> startup nomount;

    三.在主库操作,用RMAN auxiliary恢复数据库

    [oracle@host06 dbs]$ rman target sys/oracle@enmo60 auxiliary sys/oracle@enmo70

    Recovery Manager: Release 11.2.0.4.0 - Production on Tue May 2 02:47:05 2017

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

    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-00554: initialization of internal recovery manager package failed
    RMAN-04005: error from target database:

    ORA-12533: TNS:illegal ADDRESS parameters

    加粗部分报错说明 tnsnames.ora 的 ‘ADDRESS ’写错了

    action:cd $ORACLE_HOME/network/admin

              vi tnsnames.ora

    注:修改完毕一定要在主库和备库都重新启动一下监听(lsnrctl stop  lsnrctl start)

    4.再次执行连接rman的命令

    [oracle@host06 dbs]$ rman target sys/oracle@enmo60 auxiliary sys/oracle@enmo70

    5.连接成功

    Recovery Manager: Release 11.2.0.4.0 - Production on Tue May 2 03:29:19 2017

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

    connected to target database: ENMO (DBID=784235869)
    connected to auxiliary database: ENMO (not mounted)

    6.执行恢复命令

    RMAN> duplicate target database for standby from active database dorecover nofilenamecheck;

    四。在备库应用日志同步数据

    [oracle@host07 dbs]$ sqlplus / as sysdba

    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE    OPEN_MODE
    ---------------- --------------------
    PHYSICAL STANDBY MOUNTED

    SQL> alter database recover managed standby database using current logfile disconnect from session;

    五。启库

    开启备库应用日志之后没取消应用日志,直接启库,报错

    SQL> alter database open;
    alter database open
    *
    ERROR at line 1:
    ORA-10456: cannot open standby database; media recovery session may be in
    progress

    备库取消应用日志,启库

    SQL> alter database recover managed standby database cancel;

    Database altered.

    SQL> alter database open;

    Database altered.

    六。做快照

    切换物理备库为snapshot standby,报错

    SQL> alter database convert to snapshot standby;
    alter database convert to snapshot standby
    *
    ERROR at line 1:
    ORA-38784: Cannot create restore point 'SNAPSHOT_STANDBY_REQUIRED_05/02/2017
    04:43:13'.
    ORA-38786: Recovery area is not enabled.

    解决办法:(1)SQL> show parameter recovery;

                          NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_recovery_file_dest                string
    db_recovery_file_dest_size           big integer 0
    recovery_parallelism                 integer     0
    SQL> alter system set db_recovery_file_dest='/u01/recovery';
    alter system set db_recovery_file_dest='/u01/recovery'

                   (2)SQL> alter system set db_recovery_file_dest_size=3G;

                    (3) 创建一个目录用于存放快速恢复区

                          [oracle@host07 ~]$ cd /u01

                          [oracle@host07 u01]$ mkdir recovery

                     (4)SQL> alter system set db_recovery_file_dest='/u01/recovery';

    解决完报错就可以执行快照

    SQL> alter database convert to snapshot standby;

    七:查看快照信息(可以查看alert日志,会发现数据库创建了一个guaranteed restore point,确保我们切回主备,可应用日志)

    SQL> show parameter user_dump;

    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    user_dump_dest                       string      /u01/app/oracle/diag/rdbms/sbd
    b/ENMO/trace

    [oracle@host07 u01]$ cd /u01/app/oracle/diag/rdbms/sbdb/ENMO/trace

    [oracle@host07 trace]$ tail -100f alert_ENMO.log

     alter database convert to snapshot standby
    Starting background process RVWR
    Tue May 02 04:47:40 2017
    RVWR started with pid=28, OS id=24152
    Allocated 3981120 bytes in shared pool for flashback generation buffer
    Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_05/02/2017 04:47:40
    Killing 3 processes with pids 24140,24144,24148 (all RFS) in order to disallow current and future RFS connections. Requested by OS process 24071
    All dispatchers and shared servers shutdown

    八。查看备库数据库状态,并从快照状态恢复至物理状态

    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE    OPEN_MODE
    ---------------- --------------------
    SNAPSHOT STANDBY MOUNTED

    报错

    SQL> alter database convert to physical standby;
    alter database convert to physical standby
    *
    ERROR at line 1:
    ORA-16433: The database must be opened in read/write mode.

    解决:SQL> alter database open;

           Database altered.

           SQL> select open_mode from v$database;

           OPEN_MODE
           --------------------
           READ WRITE

          

    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE    OPEN_MODE
    ---------------- --------------------
    SNAPSHOT STANDBY READ WRITE

    SQL> shutdown immediate

     SQL> startup mount;
     SQL> alter database convert to physical standby;

    SQL> select status from v$instance;

    STATUS
    ------------
    STARTED

    切换完成后需要重启到mount应用日志

    SQL> shutdown immediate;

     SQL> startup mount;
    SQL> alter database recover managed standby database using current logfile disconnect from session
     

    SQL> select database_role,open_mode from v$database;

    DATABASE_ROLE    OPEN_MODE
    ---------------- --------------------
    PHYSICAL STANDBY MOUNTED

      SQL> alter database recover managed standby database cancel;
      SQL> alter database open; 
  • 相关阅读:
    springMVC controller输出前台提示信息
    使用ionic3开始自己的App开发之路
    async await
    mongodb安装和启动
    express框架的安装和使用
    js继承的实现方式
    node版本管理
    git提交时冲突问题解决
    css推荐
    js工具推荐
  • 原文地址:https://www.cnblogs.com/gw666/p/6796963.html
Copyright © 2011-2022 走看看