【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(二)

kunlunzhiying發表於2016-11-24

 

【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(二)

 

   之前釋出過一步一步搭建 oracle 11gR2 rac + dg,這裡的dg為物理dg,但是實際自己使用過程中發現需要開3個虛擬機器,機器特卡,所以決定在同一臺機器上再搭建一臺物理和邏輯dg。

一步一步搭建 oracle 11gR2 rac + dg 之前傳(一) http://blog.itpub.net/26736162/viewspace-1290405/ 

一步一步搭建oracle 11gR2 rac+dg之環境準備(二)  http://blog.itpub.net/26736162/viewspace-1290416/

一步一步搭建oracle 11gR2 rac+dg之共享磁碟設定(三) http://blog.itpub.net/26736162/viewspace-1291144/

一步一步搭建 oracle 11gR2 rac+dg之grid安裝(四)  http://blog.itpub.net/26736162/viewspace-1297101/

一步一步搭建oracle 11gR2 rac+dg之database安裝(五) http://blog.itpub.net/26736162/viewspace-1297113/

一步一步搭建11gR2 rac+dg之安裝rac出現問題解決(六) http://blog.itpub.net/26736162/viewspace-1297128/

一步一步搭建11gR2 rac+dg之DG 機器配置(七)  http://blog.itpub.net/26736162/viewspace-1298733/

一步一步搭建11gR2 rac+dg之配置單例項的DG(八)  http://blog.itpub.net/26736162/viewspace-1298735/ 

一步一步搭建11gR2 rac+dg之DG SWITCHOVER功能(九) http://blog.itpub.net/26736162/viewspace-1328050/

 

 

【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(一): http://blog.itpub.net/26736162/viewspace-1448197/

 

 

 

 

本篇blog結構圖:

 

  1. 由物理備庫轉化為邏輯備庫

  --主庫上的資訊  

 

SQL> select name,open_mode,database_role,protection_mode from v$database;

 

NAME     OPEN_MODE     DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

ORA11G     READ WRITE     PRIMARY        MAXIMUM PERFORMANCE

 

--備庫上的資訊

 

SQL> select name,open_mode,database_role,protection_mode from v$database;

 

NAME     OPEN_MODE     DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

ORA11G     READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE

 

  1. 停用備庫MRP程式  

  對於將物理備庫切換到邏輯備庫,我們需要在主庫構建LogMiner字典及啟用補充日誌,因此應先停用邏輯備庫的MRP程式,避免產生額外的redo apply, 邏輯備用資料庫在後臺使用LogMiner來提取生成SQL Apply事務必須的重做資料,在建立Log Miner字典之前,我們必須停止備用資料庫上的管理恢復,以確保我們只應用包含LogMiner字典的重做資料:

  如果正在使用Broker管理現有的物理備庫,應先在Broker中禁用目標資料庫。  

    

SQL> alter database recover managed standby database cancel;

 

Database altered.

 

SQL>

 

  1. 修改主庫引數(搭建物理備庫已建做過,略過)

alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST db_unique_name=ora11g valid_for=(ALL_LOGFILES,ALL_ROLES)';

alter system set log_archive_dest_state_1=enable;

 

  1. 主庫構建LogMiner字典

 

SQL> create tablespace logmnrtbs datafile '/u01/app/oracle/oradata/ora11g/logmnrtbs1.dbf' size 100m;

 

Tablespace created.

 

SQL> execute dbms_logmnr_d.set_tablespace('logmnrtbs');

 

PL/SQL procedure successfully completed.

 

SQL> exec dbms_logstdby.build;

 

PL/SQL procedure successfully completed.

 

SQL>

 

 

  1. 把物理備庫恢復為邏輯備庫

SQL> select name,open_mode,database_role,protection_mode from v$database;

 

NAME     OPEN_MODE     DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

ORA11G     READ ONLY     PHYSICAL STANDBY MAXIMUM PERFORMANCE

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

 

SQL> startup mount exclusive;

ORACLE instance started.

 

Total System Global Area 417546240 bytes

Fixed Size         2228944 bytes

Variable Size         335547696 bytes

Database Buffers     71303168 bytes

Redo Buffers         8466432 bytes

Database mounted.

SQL> ALTER DATABASE RECOVER TO LOGICAL STANDBY ora11gdb parallel 10;

 

Database altered.

 

SQL> shutdown immediate;

ORA-01507: database not mounted

 

 

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 417546240 bytes

Fixed Size         2228944 bytes

Variable Size         335547696 bytes

Database Buffers     71303168 bytes

Redo Buffers         8466432 bytes

Database mounted.

SQL>

 

 

  1. 修改備庫引數、開啟邏輯備用資料庫、啟用SQL應用

 

 

SQL> alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ora11gdg' scope=both;

 

System altered.

 

SQL> alter system set log_archive_dest_state_1=enable scope=both;

 

System altered.

 

SQL> ALTER DATABASE OPEN RESETLOGS;

 

Database altered.

 

SQL> alter database start logical standby apply immediate;

 

Database altered.

 

----可以看到name自動改變,為讀寫模式,日誌序列也從1開始

 

SQL> select name,open_mode,database_role,protection_mode from v$database;

 

NAME     OPEN_MODE     DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

ORA11GDB READ WRITE     LOGICAL STANDBY    MAXIMUM PERFORMANCE

 

SQL> archive log list;

Database log mode     Archive Mode

Automatic archival     Enabled

Archive destination     USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 3

Next log sequence to archive 5

Current log sequence     5

SQL>

 

至此邏輯備用資料庫以搭建完成。

 

  1. 備庫執行DML操作

在logical standby環境下,備庫基本上是一個獨立的庫,如果要在備庫,以非sys使用者對備庫的資料進行DML修改,就會報錯 ora-16224

[oracle@rhel6_lhr orclasm]$ oerr ora 16224

16224, 00000, "Database Guard is enabled"

// *Cause: Operation could not be performed because database guard is enabled

// *Action: Verify operation is correct and disable database guard

You have new mail in /var/spool/mail/oracle

[oracle@rhel6_lhr orclasm]$

 

SQL> conn lhr/lhr

Connected.

SQL> delete from lhr.test;

delete from lhr.test

*

ERROR at line 1:

ORA-16224: Database Guard is enabled

 

 

SQL> alter database guard none;

 

Database altered.

 

SQL> delete from lhr.test;

 

5669 rows deleted.

 

SQL> rollback;

 

Rollback complete.

 

SQL> alter database guard standby;

 

Database altered.

 

SQL> delete from lhr.test;

delete from lhr.test

*

ERROR at line 1:

ORA-16224: Database Guard is enabled

 

 

SQL> select guard_status from v$database;

 

GUARD_S

-------

STANDBY

 

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2129029/,如需轉載,請註明出處,否則將追究法律責任。

相關文章