Oracle11g R2之Dataguard搭建物理standby
資料庫版本:11.2.0.4
伺服器版本:RedHat6.4
主庫Primary:安裝資料庫軟體及例項
備庫Standby: 僅安裝資料庫軟體
Database DB_NAME DB_UNIQUE_NAME Oracle Net Service Name
Primary orcl orcl orcl
Physical standby orcl dg dg
一、搭設前主備庫環境:
主庫Primary環境變數:
[oracle@oracle dbs]$ cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=orcl
export ORACLE_UNQNAME=orcl
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$CLASSPATH
?
備庫Standby環境變數:
[oracle@dg ~]$ cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=dg
export ORACLE_UNQNAME=dg
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=dg
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$CLASSPATH
二、搭設Dataguard
主庫Primary操作:
1)檢查資料庫是否支援Dataguard
SQL> select * from v$option where parameter = 'Managed Standby';
PARAMETER VALUE
---------------- ----------------
Managed Standby TRUE
?
2)檢查主庫是否開啟歸檔模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archive/orcl
Oldest online log sequence 23
Next log sequence to archive 25
Current log sequence 25
--如未開啟執行下列操作
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
3)將資料庫設為強制日誌模式
SQL> alter database force logging;
4)建立資料庫密碼檔案(如果沒有)
[oracle@oracle /]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle force=y entries=5
5)建立主庫歸檔目錄
[oracle@oracle /]$ mkdir -p /u01/archive/orcl
6)備份資料庫初始化引數檔案
SQL> create pfile='/home/oracle/pfile.ora' from spfile;
7)建立pfile檔案,該檔案方便修改初始化引數
SQL> create pfile from spfile;
--開啟pfile檔案,新增如下內容
DB_UNIQUE_NAME=orcl
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,dg)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive/orcl VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'
LOG_ARCHIVE_DEST_2='SERVICE=dg ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
FAL_SERVER=dg
DB_FILE_NAME_CONVERT='/u01/oracle/oradata/dg/','/u01/oracle/oradata/orcl/'
LOG_FILE_NAME_CONVERT='/u01/archive/dg','/u01/archive/orcl'
STANDBY_FILE_MANAGEMENT=AUTO
8)關閉資料庫,透過pfile建立spfile後,開啟資料庫
SQL> shutdown immediate
SQL> create spfile from pfile;
SQL> startup
9)建立備份目錄,進行rman備份
[oracle@oracle /]$ mkdir -p /u01/backup
--rman備份
[oracle@oracle /]$ rman target /
RMAN> backup full database format '/u01/backup/backup_%t_%s_%p.bak';
10)在主庫上建立備庫的控制檔案(2份)
SQL> alter database create standby controlfile as '/u01/backup/stdby_control01.ctl';
[oracle@oracle /]$ cd /u01/backup/
[oracle@oracle backup]$ cp stdby_control01.ctl stdby_control02.ctl
備庫Standby操作:
1)建立必要的目錄
mkdir -p /u01/archive/dg
mkdir -p /u01/oracle/admin/dg/adump
mkdir -p /u01/oracle/oradata/dg
mkdir -p /u01/oracle/oradata/orcl
mkdir -p /u01/oracle/fast_recovery_area/dg
mkdir -p /u01/backup
2)透過scp將主庫中的備份檔案傳到備庫上
[oracle@oracle backup]$ cd /u01/backup
[oracle@oracle backup]$ scp backup*.bak 192.168.8.223:/u01/backup
[oracle@oracle backup]$ scp stdby_control*.ctl 192.168.8.223:/u01/oracle/oradata/
[oracle@oracle backup]$ cd $ORACLE_HOME/dbs
[oracle@oracle dbs]$ scp initorcl.ora 192.168.8.223:$ORACLE_HOME/dbs/
傳輸好後,將控制檔案放到初始化引數中設定的目錄即可?
3)將密碼檔案從主庫scp同步過來:
[oracle@oracle dbs]$ scp $ORACLE_HOME/dbs/orapworcl 192.168.8.223:$ORACLE_HOME/dbs/
4)修改備庫初始化引數檔案(主庫初始化引數檔案為initorcl.ora需修改成initdg.ora),
將初始化檔案中新增如下內容(主庫中類似的內容刪除或進行修改,除了db_name,其他的orcl需要改成dg):
DB_UNIQUE_NAME=dg
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,dg)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive/dg VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg'
LOG_ARCHIVE_DEST_2='SERVICE=orcl ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
FAL_SERVER=orcl
DB_FILE_NAME_CONVERT='/u01/oracle/oradata/orcl/','/u01/oracle/oradata/dg/'
LOG_FILE_NAME_CONVERT='/u01/archive/orcl','/u01/archive/dg'
STANDBY_FILE_MANAGEMENT=AUTO
5)透過pfile建立spfile檔案
[oracle@dg ~]$ sqlplus / as sysdba
SQL> create spfile from pfile;
6)根據pfile中配置的控制檔案路徑及引數,將scp過來的控制檔案放置對應目錄
7)啟動物理備庫standby
SQL> startup nomount
SQL> alter database mount standby database;
8)備庫standby做rman恢復
[oracle@dg ~]$ rman target /
RMAN> restore database;
9)配置主備庫檔案(備庫沒有可以從主庫scp過來進行修改),下面僅貼出主備庫相關檔案內容
--主庫Primary的listener.ora
# listener.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/oracle
--備庫standby的listener.ora
# listener.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/oracle
?
--主庫Primary的tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.223)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg)
)
)
--備庫standby的tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.205)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
10)完成後重啟listener
lsnrctl stop
lsnrctl start
--tnsping主備庫
tnsping orcl
tnsping dg
--tnsping時可能會有linux防火牆限制,禁用防火牆命令
service iptables stop
11)配置standby redolog(如果資料庫是最佳效能模式可以忽略,如果以後變成備庫且要轉為其它兩種模式則要建立)
--主庫Primary上建立:
SQL> alter database add standby logfile
group 4 ('/u01/oracle/oradata/orcl/stdby_redo04.log') size 50m,
group 5 ('/u01/oracle/oradata/orcl/stdby_redo05.log') size 50m,
group 6 ('/u01/oracle/oradata/orcl/stdby_redo06.log') size 50m,
group 7 ('/u01/oracle/oradata/orcl/stdby_redo07.log') size 50m;
--備庫standby上建立
SQL> alter database add standby logfile
group 4 ('/u01/oracle/oradata/dg/stdby_redo04.log') size 50m,
group 5 ('/u01/oracle/oradata/dg/stdby_redo05.log') size 50m,
group 6 ('/u01/oracle/oradata/dg/stdby_redo06.log') size 50m,
group 7 ('/u01/oracle/oradata/dg/stdby_redo07.log') size 50m;
12)在備庫standby上啟動redo apply
SQL> alter database recover managed standby database disconnect from session;
到此物理standby建立完畢!
?
一些常用命令(整理中)
1)查詢角色切換狀態
select switchover_status from v$database;
2)備庫啟動順序
startup nomount
alter database mount standby database;
alter database recover managed standby database disconnect from session;
3)從正在恢復狀態只讀開啟
alter database recover managed standby database cancel;
alter database open read only;
4)主備庫實時同步
alter database recover managed standby database using current logfile disconnect from
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29812844/viewspace-1878519/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DataGuard搭建物理StandBy
- dataguard之物理standby 日誌切換
- dataguard之物理standby庫failover 切換AI
- Oracle11g的Dataguard測試,建立物理備庫(Physical Standby Database)OracleDatabase
- DataGuard---->物理StandBy的角色切換之switchover
- 配置Oracle11g的Dataguard測試,建立物理備庫(Physical Standby Database)OracleDatabase
- Dataguard物理Standby Switchover 角色轉換
- DataGuard搭建邏輯StandBy
- 【DATAGUARD】DG系列之RACtoONE物理備庫的搭建
- 一步一步學DataGuard(5)物理standby之建立示例
- Data Guard 之RMAN備份線上搭建物理standby
- oracle10g 物理standby dataguard 建立過程Oracle
- Oracle11g 搭建DataGuard(筆記)Oracle筆記
- 【DATAGUARD】DG系列之11g物理備庫的搭建
- 【DATAGUARD 學習】使用duplicate 建立物理standby 資料庫資料庫
- oracle 之dataguard standby 切換Oracle
- Oracle 11g R2之物理Dataguard 重新命名資料檔案Oracle
- 【DataGuard】Oracle 11g物理Data Guard之Snapshot Standby資料庫功能Oracle資料庫
- oracle11g單節點DataGuard搭建Oracle
- Oracle11g 搭建單例項DataGuardOracle單例
- 【轉】【DataGuard】Oracle 11g物理Data Guard之Snapshot Standby資料庫功能Oracle資料庫
- 【DataGuard】手工冷備搭建 Oracle 11g DataGuard 物理備庫Oracle
- 附錄A Oracle Dataguard 物理Standby跨平臺組合支援列表Oracle
- 【DATAGUARD】 將11g物理備庫轉換為Snapshot Standby
- 配置 Oracle 10g 單例項物理dataguard和邏輯standbyOracle 10g單例
- 【DataGuard】10g物理standby主備switchover方式切換詳述
- 【DataGuard】Oracle 11g DataGuard 新特性之 Snapshot Standby DatabaseOracleDatabase
- Oracle DataGuard環境failover後通過舊備份建立物理StandbyOracleAI
- DataGuard:Physical Standby Switchover
- 【DataGuard】物理Data Guard之Failover轉換AI
- Dataguard 物理安裝
- cp資料檔案方式搭建 11g 物理standby
- Data Guard學習之物理standby建立步驟
- Dataguard(Standby) 後臺程式
- DataGuard:Physical Standby FailoverAI
- DataGuard:Logical Standby Switchover
- dataguard 搭建 oracle_sid不同 2節點 primary+standbyOracle
- dataguard 搭建 oracle_sid相同 2節點 primary+standbyOracle