Oracle数据库容灾解决方案:Oracle DataGuard部署实录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle数据库容灾解决方案:Oracle DataGuard部署实录相关的知识,希望对你有一定的参考价值。

SQL> alter database force logging;
Database altered.

SQL> col force_logging for a15
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------
YES


SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     35
Next log sequence to archive   37
Current log sequence           37


SQL> alter system set db_unique_name='kingm' scope=spfile;
SQL> alter system set log_archive_config='dg_config=(kingm,kings)' scope=spfile;
SQL> alter system set log_archive_dest_1='location=db_recovery_file_dest valid_for=(all_logfiles,all_roles) db_unique_name=kingm' scope=spfile;
SQL> alter system set log_archive_dest_2='service=kings lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=kings' scope=spfile;
SQL> alter system set fal_server='kings' scope=spfile;
SQL> alter system set fal_client='kingm' scope=spfile;
SQL> alter system set standby_file_management='auto' scope=spfile;
SQL> alter system set log_archive_dest_state_2='defer' scope=spfile;
SQL> alter system set service_names=king,kingm scope=spfile;


[[email protected] ~]$ cd $ORACLE_HOME/dbs
[[email protected] dbs]$ sqlplus / as sysdba
SQL> create pfile from spfile;  
File created.

[[email protected] dbs]$ scp initking.ora 192.168.1.202:/u01/app/oracle/product/11.2.0/db_1/dbs
[[email protected] dbs]$ scp orapwking 192.168.1.202:/u01/app/oracle/product/11.2.0/db_1/dbs


[[email protected] ~]$ mkdir -p /u01/app/oracle/backup
[[email protected] ~]$ mkdir -p /u01/app/oracle/backup

[[email protected] ~]$ rman target /
RMAN> backup device type disk format '/u01/app/oracle/backup/%U' database plus archivelog;
RMAN> backup device type disk format '/u01/app/oracle/backup/%U' current controlfile for standby;

[[email protected] ~]$ scp /u01/app/oracle/backup/*  192.168.1.202:/u01/app/oracle/backup

 

[[email protected] ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
KINGS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = king)
    )
  )
KINGM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = king)
    )
  )


[[email protected] ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = king)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = king)
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = king02)(PORT = 1521))
  )
ADR_BASE_LISTENER = /u01/app/oracle

[[email protected] ~]$ lsnrctl start
[[email protected] ~]$ lsnrctl status


[[email protected] ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
KINGS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = king)
    )
  )
KINGM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = king)
    )
  )


[[email protected] ~]$ tnsping kings
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = 
king)))
OK (40 msec)

[[email protected] ~]$ tnsping kingm
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = 
king)))
OK (30 msec)


[[email protected] ~]$ cd $ORACLE_HOME/dbs
[[email protected] dbs]$ vi initking.ora
*.audit_file_dest='/u01/app/oracle/admin/king/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/king/control01.ctl','/u01/app/oracle/fast_recovery_area/king/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='king'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=107374182400
*.db_unique_name='kings'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=kingXDB)'
*.fal_client='kings'
*.fal_server='kingm'
*.log_archive_config='dg_config=(kingm,kings)'
*.log_archive_dest_1='location=db_recovery_file_dest valid_for=(all_logfiles,all_roles) db_unique_name=kings'
*.log_archive_dest_2='service=kings lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=kingm'
*.memory_max_target=1073741824
*.memory_target=1073741824
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='KING','KINGS'
*.standby_file_management='auto'
*.undo_tablespace='UNDOTBS1'

[[email protected] dbs]$ sqlplus / as sysdba
SQL> create spfile from pfile;

File created.


[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/king/adump
[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/king/dpdump
[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/king/pfile
[[email protected] ~]$ mkdir -p /u01/app/oracle/oradata/king
[[email protected] ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/king


[[email protected] ~]$ sqlplus / as sysdba
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             432014216 bytes
Database Buffers          629145600 bytes
Redo Buffers                5517312 bytes


[[email protected] ~]$ rman target sys/[email protected] auxiliary sys/[email protected] nocatalog
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Mar 31 14:25:26 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: KING (DBID=1072562510)
using target database control file instead of recovery catalog
connected to auxiliary database: KING (not mounted)

RMAN> duplicate target database for standby dorecover nofilenamecheck;


[[email protected] ~]$ sqlplus / as sysdba
SQL> alter database add standby logfile '/u01/app/oracle/oradata/king/standby01.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/king/standby02.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/king/standby03.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/king/standby04.log' size 50m;

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


[[email protected] ~]$ sqlplus / as sysdba
SQL> alter system set log_archive_dest_state_2=enable scope=both;
SQL> alter system switch logfile;


[[email protected] ~]$ sqlplus / as sysdba
SQL> alter database recover managed standby database cancel;
SQL> alter database open;
SQL> alter database recover managed standby database disconnect from session using current logfile;


[[email protected] ~]$ sqlplus / as sysdba
SQL> set line 200
SQL> col DATABASE_MODE for a30
SQL> col PROTECTION_MODE for a30
SQL> col RECOVERY_MODE for a30
SQL> select DEST_ID , DATABASE_MODE , RECOVERY_MODE , PROTECTION_MODE from v$archive_dest_status where DEST_ID=2;
   DEST_ID DATABASE_MODE                  RECOVERY_MODE                  PROTECTION_MODE
---------- ------------------------------ ------------------------------ ------------------------------
         2 OPEN_READ-ONLY                 MANAGED REAL TIME APPLY        MAXIMUM PERFORMANCE
         
SQL> col DEST_NAME for a20
SQL> col DESTINATION for a30
SQL> col ERROR for a50 
SQL> select DEST_ID,DEST_NAME,STATUS, DESTINATION, ERROR from V$ARCHIVE_DEST where DEST_ID<=2;
   DEST_ID DEST_NAME            STATUS                      DESTINATION                    ERROR
---------- -------------------- --------------------------- ------------------------------ --------------------------------------------------
         1 LOG_ARCHIVE_DEST_1   VALID                       db_recovery_file_dest
         2 LOG_ARCHIVE_DEST_2   VALID                       kings

SQL> col TYPE for a20
SQL> select DEST_NAME,DESTINATION,STATUS,TYPE,ARCHIVED_SEQ#,APPLIED_SEQ# from v$archive_dest_status where DEST_ID<=2; 

DEST_NAME            DESTINATION                    STATUS                      TYPE                 ARCHIVED_SEQ# APPLIED_SEQ#
-------------------- ------------------------------ --------------------------- -------------------- ------------- ------------
LOG_ARCHIVE_DEST_1   db_recovery_file_dest          VALID                       LOCAL                           50            0
LOG_ARCHIVE_DEST_2   kings                          VALID                       PHYSICAL                        50           49


SQL> select THREAD# , SEQUENCE# , STATUS from v$log;

   THREAD#  SEQUENCE# STATUS
---------- ---------- ------------------------------------------------
         1         49 INACTIVE
         1         50 INACTIVE
         1         51 CURRENT


[[email protected] ~]$ sqlplus / as sysdba
SQL> set line 200
col ARCHIVED for a10
SQL> select THREAD# , SEQUENCE# , ARCHIVED , STATUS from v$standby_log;
   THREAD#  SEQUENCE# ARCHIVED   STATUS
---------- ---------- ---------- ------------------------------
         1         51 YES        ACTIVE
         1          0 NO         UNASSIGNED
         0          0 YES        UNASSIGNED
         0          0 YES        UNASSIGNED
         
SQL> select PROCESS , STATUS , THREAD# , SEQUENCE# , BLOCK# , BLOCKS  from v$managed_standby where process != 'ARCH';
PROCESS                     STATUS                                  THREAD#  SEQUENCE#     BLOCK#     BLOCKS
--------------------------- ------------------------------------ ---------- ---------- ---------- ----------
RFS                         IDLE                                          0          0          0          0
RFS                         IDLE                                          0          0          0          0
RFS                         IDLE                                          1         51       4381          1
MRP0                        APPLYING_LOG                                  1         51       4381     102400


以上是关于Oracle数据库容灾解决方案:Oracle DataGuard部署实录的主要内容,如果未能解决你的问题,请参考以下文章

常见数据库容灾技术的直观比较

Oracle DataGuard如何升级?看这篇就够了

实战篇:生产库升级,容灾库 Oracle DataGuard 如何升级?

Oracle大连/深圳职位机会,把握就是现在

物流行业-云上Oracle数据库备份容灾方案

Oracle数据库集群容灾实施与维护(RAC+DataGuard+GoldenGate)培训教程