您好,登錄后才能下訂單哦!
本次測試環境使用的虛擬環境如下圖所示,使用VMware Workstation 11搭建的兩臺Oracle Linux 6.4 64位操作系統,通過兩臺機器橋接到一塊虛擬網卡。
服務器一(主) | 服務器二(備) |
主機名:zhanky IP: 192.168.214.10 數據庫版本: oracle 11.2.0.4 庫名:zky TNSNAME:DGZ | 主機名:zhanky IP: 192.168.214.11 數據庫版本: oracle 11.2.0.4 庫名:zky TNSNAME:DGB |
主備庫正常情況客戶端訪問流量訪問主庫,數據自動同步到備庫。當主庫出現故障時,管理員手動將備庫切換為主庫。此時客戶端訪問備庫實現業務不中斷正常訪問。
我們模仿正式環境,先將primary服務器準備好,然后在standby服務器上只安裝數據庫軟件。在本次測試中我們使用rman的方式來備份數據庫,然后在standby上面還原。關鍵實施步驟如下
Primary 1、 打開歸檔模式,開啟強制記錄日志 2、 創建日志組 3、 添加靜態監聽,添加tns 4、 生成密碼文件 5、 生成pfile添加DG內容 6、 重啟通過pfile啟動,更新spfile 7、 通過rman duplicate備份 8、 生成控制文件 | Standby 1、 將備份文件拷貝到standby對應的位置 。 2、 將密碼文件考到對應的位子 3、 將監聽文件修改后考到對應的位置,然后開啟監聽 4、 將pfile文件更改后拷貝到standby 5、 通過oradim創建實例,加載更改的pfile到nomount模式 6、 將pfile更新到spfile,然后重啟數據庫 7、 通過rman 回復數據庫,完成后open 8、 將控制文件替換 9、 然后啟用DG到備庫模式 |
查看歸檔日志是否開啟
SQL> archive log list |
上圖看出庫開啟了歸檔模式。如果沒有開啟則按照以下步驟開啟歸檔模式
SQL> shutdown immediate SQL> startup mount SQL> alter database archivelog; SQL> alter database force logging; SQL> alter database open; |
創建日志組
[oracle@zhanky /]$ mkdir /u01/archive SQL> alter database add standby logfile group 4 '/u01/archive/STAN04.LOG' size 50m; SQL> alter database add standby logfile group 5 '/u01/archive/STAN05.LOG' size 50m; SQL> alter database add standby logfile group 6 '/u01/archive/STAN06.LOG' size 50m; SQL> alter database add standby logfile group 7 '/u01/archive/STAN07.LOG' size 50m; |
密碼文件要拷貝到DG備庫,保持兩邊密碼文件一致。
[oracle@zhanky ~]$ ls /u01/app/oracle/product/11.2.0/db_1/dbs/ |
如果沒有密碼文件可以手動創建
SQL> orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky password=manager entries=10 |
建議設置密碼永不過期
SQL> alter profile default limit password_life_time unlimited; |
配置靜態監聽,在listener.ora文件中添加靜態監聽
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora SID_LIST_LISTENER= (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = zky) (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1) (SID_NAME = zky) ) ) |
注意linux環境中更改偵聽需要先stop在修改,不然會導致偵聽服務無法正常啟動關閉
配置tnsname.ora,設置DG主和DG備服務器監聽
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora DGZ = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.10)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) DGB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.11)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) |
下面開始配置dg文件了,配置完成后記得重啟數據庫。
SQL> alter system set db_unique_name=dgz scope=spfile; SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGZ,DGB)' scope=both; SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/zky/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DGZ' scope=spfile; SQL> alter system set LOG_ARCHIVE_DEST_2= 'service=DGB lgwr async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=DGB' scope=both; SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=both; SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both; SQL> alter system set FAL_SERVER='DGZ' scope=both; SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both; SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/zky/','/u01/app/oracle/oradata/zky/' scope=spfile; SQL> alter system set LOG_FILE_NAME_CONVERT='/u01/archive/','/u01/archive/' scope=spfile; |
創建參數文件供備庫用
SQL> create pfile='/u01/zk.int' from spfile; |
將密碼文件和參數文件拷貝到DG備庫對應的位置并賦予讀寫權限
[oracle@zhanky ~]$ scp oracle@192.168.214.10:/u01/zk.int /u01/bk.int [oracle@zhanky ~]$ scp oracle@192.168.214.10:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky /u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky [oracle@zhanky ~]$ chmod 777 /u01/bk.int [oracle@zhanky ~]$ chmod 777 /u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky |
[oracle@zhanky /]$ mkdir -p /u01/archive/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/admin/zky/adump/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/oradata/zky/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/fast_recovery_area/zky/ |
配置靜態監聽,在listener.ora文件中添加靜態監聽
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora SID_LIST_LISTENER= (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = zky) (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1) (SID_NAME = zky) ) ) |
注意linux環境中更改偵聽需要先stop在修改,不然會導致偵聽服務無法正常啟動關閉
配置tnsname.ora,設置DG主和DG備服務器監聽
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora DGZ = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.10 )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) DGB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.11)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) |
將復制過來的參數文件更改下列紅色標識的地方
[oracle@zhanky ~]$ vi /u01/bk.int db_unique_name=dgb scope=spfile; LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGZ,DGB)' scope=both; LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/zky/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DGZ' scope=spfile; LOG_ARCHIVE_DEST_2= 'service=DGB lgwr async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=DGB' scope=both; FAL_SERVER='DGZ' scope=both; |
完成更改后,進入數據庫創建spfile,重啟到nomount狀態準備還原數據庫
[oracle@zhanky /]$ sqlplus / as sysdba SQL> create spfile from pfile='/u01/bk.int'; SQL> startup nomount; |
[oracle@zhanky ~]$ rman target sys/manager@DGZ auxiliary sys/manager@DGB RMAN> duplicate target database for standby from active database nofilenamecheck; |
提示:還原數據庫要在nomount模式
將庫配置為standby庫,開啟到只讀模式,開啟實時應用日志。
SQL> shutdown immediate SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session; |
主庫插入
SQL> create table zkydg as(select username from dba_users where username='SYSTEM'); |
備庫查詢
SQL> select * from zkydg; |
SQL> alter database commit to switchover to physical standby with session shutdown; SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session; |
SQL> select switchover_status from v$database; |
SQL> alter database recover managed standby database cancel; SQL> alter database commit to switchover to primary; SQL> shutdown immediate SQL> startup |
新主庫插入
SQL> create table zkydgqh as(select username from dba_users where username='SYS'); |
老主庫查詢
SQL> select * from zkydgqh; |
SQL> select switchover_status from v$database; |
SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; |
當主庫掛了無法控制時,可直接在備庫上強制接管數據庫
SQL> RECOVER MANAGED STANDBY DATABASE FINISH force; |
SQL> shutdown immediate SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。