溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

DG的搭建記錄是怎樣的

發(fā)布時(shí)間:2021-11-12 15:55:51 來源:億速云 閱讀:132 作者:柒染 欄目:關(guān)系型數(shù)據(jù)庫(kù)

DG的搭建記錄是怎樣的,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

單實(shí)例DG搭建手冊(cè)

規(guī)劃

ip

db_name

db_unique_name

sid

tns

192.168.10.103

test

test

test

test

192.168.10.104

test

dgdb

dgdb

dgdb


配置監(jiān)聽
主庫(kù)listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2/network/admin/listener.ora
# Generated by Oracle configuration tools.


SID_LIST_DG =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = test)
      (ORACLE_HOME = /u01/app/oracle/product/11.2)
      (SID_NAME = test)
    )
  )
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lzl)(PORT = 1521))
    )
  )


ADR_BASE_LISTENER = /u01/app/oracle


備庫(kù)listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2/network/admin/listener.ora
# Generated by Oracle configuration tools.


SID_LIST_DG =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = dgdb)
      (ORACLE_HOME = /u01/app/oracle/product/11.2)
      (SID_NAME = dgdb)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = l2l)(PORT = 1521))
    )
  )


ADR_BASE_LISTENER = /u01/app/oracle


主備庫(kù)的tnsnames.ora
test =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lzl)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = test)
      (SERVER = DEDICATED)
    )
  )


dgdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = l2l)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = dgdb)
      (SERVER = DEDICATED)
    )
  )




主庫(kù)準(zhǔn)備
更改日志模式
防止使用no logging子句造成主備庫(kù)數(shù)據(jù)不一致
SQL> alter database force logging
  2  /


Database altered.
SQL> select force_logging from v$database;


FOR
---
YES


是否歸檔
SQL> select log_mode from v$database;


LOG_MODE
------------
ARCHIVELOG




更改log_archive_config
SQL>  alter system set log_archive_config=‘DG_CONFIG=(test,dgdb)' scope=both ;


System altered.


SQL> show parameter archive_config


NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_config     string DG_CONFIG=(test,dgdb)
SQL> 


配置DG參數(shù)
alter system set log_archive_dest_1='location=/home/oracle/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=test' scope=both;
alter system set log_archive_dest_2 ='SERVICE=dgdb LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgdb' scope=both;
alter system set log_archive_dest_state_1 = ENABLE;                
alter system set log_archive_dest_state_2 = ENABLE;
數(shù)據(jù)文件自動(dòng)添加
alter system set standby_file_management=auto scope=both;


alter system set fal_server=dgdb scope=both;
alter system set fal_client=test scope=both;


1800s自動(dòng)切換redo log
alter system set archive_lag_target=1800;


文件位置調(diào)整
alter system set db_file_name_convert='/u01/app/oracle/oradata/test/','/u01/app/oracle/oradata/dgdb/' scope=spfile; 
alter system set log_file_name_convert='/u01/app/oracle/oradata/logfile/','/u01/app/oracle/oradata/logfile/' scope=spfile; 


2.密碼文件
使用以前的密碼文件或者直接創(chuàng)建一個(gè)密碼文件
[oracle@lzl ~]$ orapwd password=oracle file='/home/oracle/orapwd.ora' force=y ignorecase=y
[oracle@lzl ~]$ ls
orapwd.ora


3.備份數(shù)據(jù)庫(kù)
backup database


4.生成pfile
create pfile='/home/oracle/initdgdb.ora' from spfile;
修改參數(shù)
*.db_unique_name='dgdb'
*.fal_client='dgdb'
*.fal_server='test'
*.service_names='dgdb'
*.log_archive_dest_1='location=/home/oracle VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dgdb'
*.log_archive_dest_2='SERVICE=dgdb LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=test'




db_name應(yīng)與主庫(kù)保持一致


6.生成stanby controlfile
SQL> alter database create standby controlfile as '/home/oracle/control01.ctl';


Database altered.


備庫(kù)準(zhǔn)備
備庫(kù)是一個(gè)只有數(shù)據(jù)庫(kù)軟件的環(huán)境
1.拷貝stanby controlfile,pfile,orapwd 文件到備庫(kù)
控制文件拷貝到pfile指定的目錄中
密碼文件更改sid到/oracle/home/dbs中


[oracle@l2l ~]$ ls
 control01.ctl  initdgdb.ora  orapwd.ora
2.創(chuàng)建pfile中的目錄
審計(jì)目錄、控制文件目錄、數(shù)據(jù)文件目錄等


3.啟動(dòng)備庫(kù)到mount階段


[oracle@l2l ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 27 17:04:07 2017


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


Connected to an idle instance.


SQL> startup nomount pfile='/home/oracle/initdgdb.ora';
ORACLE instance started.


Total System Global Area 1048059904 bytes
Fixed Size    2235000 bytes
Variable Size  310379912 bytes
Database Buffers  729808896 bytes
Redo Buffers    5636096 bytes
SQL> alter database mount;


Database altered.


SQL> select database_role from v$database;


DATABASE_ROLE
----------------
PHYSICAL STANDBY

4.rman數(shù)據(jù)恢復(fù)
使用rman將主庫(kù)的備份應(yīng)用于備庫(kù)
RMAN> catalog start with ‘/home/oracle/liu/’
RMAN> restore database;


5.創(chuàng)建standby redo log files,數(shù)量至少是主庫(kù)的兩倍
standby redo log 與redo log是很相似的,但是standby redo log是用來在standby庫(kù)上接收主庫(kù)的redo data的。
備庫(kù)上不會(huì)使用online redo log
為了方便任意切換,最好是主備庫(kù)都創(chuàng)建standby redo log files
SQL> alter database add standby logfile group 11 ('/u01/app/oracle/oradata/test/dg_redo11.log' ) size 50M;

Database altered.
SQL> alter database add standby logfile group 12 ('/u01/app/oracle/oradata/test/dg_redo12.log' ) size 50M;


Database altered.
SQL> alter database add standby logfile group 13 ('/u01/app/oracle/oradata/test/dg_redo13.log' ) size 50M;


Database altered.
SQL> alter database add standby logfile group 14 ('/u01/app/oracle/oradata/test/dg_redo14.log' ) size 50M;


Database altered.
SQL> alter database add standby logfile group 15 ('/u01/app/oracle/oradata/test/dg_redo15.log' ) size 50M;


Database altered.
SQL> alter database add standby logfile group 16 ('/u01/app/oracle/oradata/test/dg_redo16.log' ) size 50M;


Database altered.


查看v$standby_log
SQL> select group# from v$standby_log;


    GROUP#
----------
10
11
12
13
14
15


6 rows selected.


SQL> select group# from v$log;


    GROUP#
----------
1
3
2
查看文件還是需要v$logfile
SQL> select member from v$logfile;


MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/test/redo03.log
/u01/app/oracle/oradata/test/redo02.log
/u01/app/oracle/oradata/test/redo01.log
/u01/app/oracle/oradata/test/dg_redo11.log
/u01/app/oracle/oradata/test/dg_redo12.log
/u01/app/oracle/oradata/test/dg_redo13.log
/u01/app/oracle/oradata/test/dg_redo14.log
/u01/app/oracle/oradata/test/dg_redo15.log
/u01/app/oracle/oradata/test/dg_redo16.log


9 rows selected.




建立主備庫(kù)DG關(guān)系


備庫(kù)
SQL>  alter database recover managed standby database using current logfile disconnect from session ;


Database altered.


告警日志信息:
 alter database recover managed standby database using current logfile disconnect from session 
Attempt to start background Managed Standby Recovery process (dgdb)
Sat Jul 28 19:28:48 2017
MRP0 started with pid=25, OS id=3264 
MRP0: Background Managed Standby Recovery process started (dgdb)
Serial Media Recovery started
Managed Standby Recovery starting Real Time Apply
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Waiting for thread 1 sequence 100
Completed:  alter database recover managed standby database using current logfile disconnect from session 


查看備庫(kù)角色
SQL>  select PROTECTION_MODE ,PROTECTION_LEVEL ,GUARD_STATUS,DATABASE_ROLE,to_char(current_scn) from v$database;


PROTECTION_MODE      PROTECTION_LEVEL  GUARD_S DATABASE_ROLE
-------------------- -------------------- ------- ----------------
TO_CHAR(CURRENT_SCN)
----------------------------------------
MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY NONE  PHYSICAL STANDBY
2481074


主庫(kù)檢查


備庫(kù)檢查
SQL>  select PROTECTION_MODE ,PROTECTION_LEVEL ,GUARD_STATUS,DATABASE_ROLE,to_char(current_scn) from v$database;


PROTECTION_MODE      PROTECTION_LEVEL  GUARD_S DATABASE_ROLE
-------------------- -------------------- ------- ----------------
TO_CHAR(CURRENT_SCN)
----------------------------------------
MAXIMUM AVAILABILITY RESYNCHRONIZATION  NONE  PRIMARY
2482972

看完上述內(nèi)容,你們掌握DG的搭建記錄是怎樣的的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

dg
AI