1. 程式人生 > >DATA GUARD環境搭建

DATA GUARD環境搭建

本文主要涉及到以下內容 一、安裝前環境配置 二、主庫配置 三、備庫配置 四、主庫複製資料庫到備庫 五、開啟備庫資料庫 六、備庫應用日誌檔案 七、查詢主備庫資料庫狀態 八、驗證資料同步 一、安裝前環境配置

1、一臺完整可用裝有ORACLE資料庫的虛擬機器作為主庫

2、一臺乾淨沒有安裝ORACLE資料庫的虛擬機器作為備庫,注意是沒有安裝ORACLE資料庫,但是軟體要提前安裝好 二、配置主庫 提前做好IP對應關係需要在主庫與備庫都配置 cat /etc/hosts

1、alter database force logging;開啟資料庫強制歸檔 2、設定資料庫歸檔

(1)startup nomount;

(2)alter database archivelog;

(3)alter database open;

(4)archive log list;

(5)修改歸檔路徑,路徑要提前存在

show parameter archive;

alter system set log_archive_dest_1 =’location=/u01/arch’;

alter system set log_archive_format =%t_%s_%r.arc; 3、主庫新增備庫日誌檔案,個數為當前日誌數+1

alter  database add  standby  logfile '/u01/app/oracle/oradata/orcl/stdredo01.log'  size 200M;

 alter  database add  standby  logfile '/u01/app/oracle/oradata/orcl/stdredo02.log'  size 200M;

 alter  database add  standby  logfile '/u01/app/oracle/oradata/orcl/stdredo03.log'  size 200M;

 alter  database add  standby  logfile '/u01/app/oracle/oradata/orcl/stdredo04.log'  size 200M;

注意檔案大小要與原日誌檔案大小差不多。 4、查詢新增的standby logfile SQL> select group#,thread#,sequence#,archived,status from v$standby_log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS

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

 4     0        0 YES UNASSIGNED

 5     0        0 YES UNASSIGNED

 6     0        0 YES UNASSIGNED

 7     0        0 YES UNASSIGNED

  SQL> select * from v$logfile;

 4    STANDBY /u01/app/oracle/oradata/orcl/s NO        0

   tdredo01.log

    GROUP# STATUS  TYPE    MEMBER   IS_   CON_ID

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

 5    STANDBY /u01/app/oracle/oradata/orcl/s NO        0

   tdredo02.log

 6    STANDBY /u01/app/oracle/oradata/orcl/s NO        0

   tdredo03.log

 7    STANDBY /u01/app/oracle/oradata/orcl/s NO        0

   tdredo04.log 5、配置靜態監聽引數

SID_LIST_LISTENER =

(SID_LIST =

  (SID_DESC =

    (GLOBAL_DBNAME = orcl)

    (ORACLE_HOME =/u01/app/oracle/product/12.2.0/dbhome_1)

    (SID_NAME = orcl)

   )

 )

ADR_BASE_LISTENER = /u01/app/oracle

6、配置網路連線名

ORCL_S =

 (DESCRIPTION =

   (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = wyuu)(PORT = 1521))

    )

   (CONNECT_DATA =

     (SERVICE_NAME = orcl)

    )

  )

ORCL_P =

 (DESCRIPTION =

   (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = wyu)(PORT = 1521))

    )

   (CONNECT_DATA =

     (SERVICE_NAME = orcl)

    )

  )

  配置好需要驗證是否可用,我們這裡先驗證主庫,等後續備庫配置完成再驗證備庫 tnsping orcl_p

8、後續備庫需要用到原pfile,所以這裡先將pfile拷貝到備庫一份

scp $ORACLE_HOME/dbs/initorcl.ora wyuu:`pwd` 然後修改主庫的pfile加入以下內容

*.db_name='orcl'

*.db_unique_name='orcl_p'

*.log_archive_config='dg_config=(orcl_p,orcl_s)'

*.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=orcl_p'

*.log_archive_dest_2='service=orcl_s valid_for=(online_logfiles,primary_role)  lgwr affirm sync db_unique_name=orcl_s'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='orcl_s'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl' 三、備庫配置 1、配置備庫的靜態監聽引數,直接將主庫的監聽檔案拷貝過來

scp $ORACLE_HOME/network/admin/listener.ora wyuu:`pwd` 2、配置網路連線名,同樣將主庫的檔案拷貝一份

scp $ORACLE_HOME/network/admin/tnsnames.ora wyuu:`pwd` 驗證網路連線名是否可用

需要在主庫及從庫都使用tnsping來驗證 3、將之前拷貝的引數檔案加入以下內容

*.db_name='orcl'

*.db_unique_name='orcl_s'

*.log_archive_config='dg_config=(orcl_p,orcl_s)'

*.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=orcl_s'

*.log_archive_dest_2='service=orcl_p valid_for=(online_logfiles,primary_role)  lgwr affirm sync db_unique_name=orcl_p'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='orcl_p'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl' 4、拷貝密碼檔案

scp $ORACLE_HOME/dbs/orapworcl wyuu:`pwd` 5、建立啟動需要的目錄

目錄要與pfile中路徑相同

mkdir -p $ORACLE_BASE/admin/orcl/adump 6、啟動資料庫到nomount狀態

startup nomount 四、主庫複製資料庫 rman target sys/[email protected]_p auxiliary sys/[email protected]_s duplicate target database for standby from active database nofilenamecheck dorecover; 五、開啟備庫資料庫

alter database open; 六、備庫應用日誌檔案 alter database recover managed standby database using current logfile disconnect from session;

alter database recover managed standby database cancel;(取消日誌檔案應用,不需做) 七、查詢主備庫資料庫狀態 1、主庫 SQL> select log_mode,open_mode,database_role from v$database;

LOG_MODE     OPEN_MODE   DATABASE_ROLE

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

ARCHIVELOG   READ WRITE   PRIMARY 2、備庫 SQL> select log_mode,open_mode,database_role from v$database;

LOG_MODE     OPEN_MODE     DATABASE_ROLE

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

ARCHIVELOG   READ ONLY WITH APPLY  PHYSICAL STANDBY 備庫是隻讀的 八、驗證資料同步

--------------------- 作者:吳用丶 來源:CSDN 原文:https://blog.csdn.net/weixin_42774383/article/details/82629349 版權宣告:本文為博主原創文章,轉載請附上博文連結!