您好,登錄后才能下訂單哦!
一、前期準備
在準備搭建DATAGARD的時候,看過許多篇教程,按著教程去走,出現過問題,然后就不知道該如何進行下一步。
后來去看了官方文檔的,整理一下思路后事情就簡單多了。
以一主主庫一備庫為例,搭建DG的思路如下:
關閉防火墻。
配置ssh互信(非必須,減少SCP時輸入密碼的次數)
主庫上的操作:
1)開啟歸檔模式,開啟forced logging;
2)添加standby logfile,standby logfile組比logfile組多一個;
3)修改參數文件
4)配置listener.ora 和tnsnames.ora
5)備份數據庫和控制文件
備庫準備:
1)將主庫上的參數文件、密碼文件拷貝到備庫上,修改參數文件;
2)將主庫上的listener.ora 和tnsnames.ora復制到備庫上,修改listener.ora文件
3)將備份復制到備庫上
4)在備庫上創建對應的文件夾
5)啟動備庫到nomount模式
6)在備庫上使用RMAN恢復數據庫
7)備庫上添加standby logfile
8)應用歸檔
9)查看狀態
二、基本配置準備
2.1 primary服務器安裝數據庫軟件并安裝ORCL數據庫,standby服務器上安裝
2.2 關閉防火墻
primary服務器關閉防火墻:
standby服務器關閉防火墻
2.3 配置ssh互信
百度下“linux scp免密碼”,隨便找篇文章看下。
[oracle@primary dbs]$ ssh-keygen -t rsa
[oracle@primary dbs]$ scp ~/.ssh/id_rsa.pub oracle@192.168.62.202:/home/oracle/.ssh/authorized_keys
三、主庫配置
1)enable forced logging:
SQL> ALTER DATABASE FORCE LOGGING;
查看是否已經是歸檔模式,如果是未歸檔模式,則將其修改成歸檔模式。
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
3)配置standby logfile文件,當主庫變成備庫時,可以接收來自備庫的日志。
alter database add standby logfile group 4 ('/u01/app/oracle/oradata/orcl/redo_dg_021.log') size 50M;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/orcl/redo_dg_022.log') size 50M;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/orcl/redo_dg_023.log') size 50M;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/orcl/redo_dg_024.log') size 50M;
3)配置主庫的參數:這里有兩種方式,一種是使用alter system 來修改參數,另外一種是生成靜態參數文件之后修改參數;我采用的是后一種配置方式。
參數的配置參考Oracle Data Guard Concepts and Administration 11g Release 2 (11.2) E41134-03中3-3和3-4頁
initorcl.ora已經有的參數,可以不用配置。
SQL> create pfile from spfile;
[oracle@primary ~]$ cd $ORACLE_HOME/dbs
[oracle@primary dbs]$ vim initorcl.ora
#primary
#*.db_name='orcl'
*.db_unique_name=pri
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(pri,sty)'
#*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
*.LOG_ARCHIVE_DEST_1= 'LOCATION=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pri'
*.LOG_ARCHIVE_DEST_2= 'SERVICE=sty ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=sty'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.remote_login_passwordfile='EXCLUSIVE'
*.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
#standby role
*.FAL_SERVER=sty
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'
*.LOG_FILE_NAME_CONVERT= '/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'
*.STANDBY_FILE_MANAGEMENT=AUTO
SQL> shutdown immediate
SQL> create spfile from pfile;
4)主庫上配置listener.ora 和tnsnames.ora
主庫上的listener.ora :
[oracle@primary admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.62.201)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
主庫上的tnsnames.ora:
[oracle@primary admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PRI =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.62.201)(PORT = 1521))
)
(CONNECT_DATA =
(SID = orcl)
)
)
STY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.62.202)(PORT = 1521))
)
(CONNECT_DATA =
(SID = orcl)
)
)
修改完成之后要重啟監聽。
5)備份數據庫和控制文件
[oracle@primary admin]$ rman target sys/asd@pri
RMAN> backup database format '/u01/app/oracle/backup/full_db_%U';
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/u01/app/oracle/backup/sty.ctl';
四、備庫上的操作
1)將主庫上的參數文件、密碼文件拷貝到備庫上,修改參數文件;
[oracle@primary admin]$ cd $ORACLE_HOME/dbs
[oracle@primary dbs]$ scp initorcl.ora orapworcl oracle@192.168.62.202:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
修改參數文件:
vim /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora
*.db_name='orcl'
*.DB_UNIQUE_NAME=sty
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'
*.LOG_FILE_NAME_CONVERT= '/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'
*.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=sty'
*.LOG_ARCHIVE_DEST_2='SERVICE=pri ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=pri'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
*.STANDBY_FILE_MANAGEMENT=AUTO
*.FAL_SERVER=pri
標紅的是修改的部分
密碼文件說明:主庫上有授權或者收回sysdba時,要更新備庫上的密碼文件。
2)將主庫上的listener.ora 和tnsnames.ora復制到備庫上,修改listener.ora文件
主庫上執行:
[oracle@primary admin]$ scp listener.ora tnsnames.ora oracle@192.168.62.202:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
備庫上執行:
[oracle@standby ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
[oracle@standby admin]$ vim listener.ora
將host中的201 改成202,也就是將host改成備庫機器上的IP,tnsnames.ora不用修改。
修改完成之后要重啟監聽
3)將備份復制到備庫上
[oracle@primary backup]$ scp /u01/app/oracle/backup/* oracle@192.168.62.202:/u01/app/oracle/backup
4)在備庫上創建對應的文件夾
[oracle@standby oracle]$ cd $ORACLE_BASE
[oracle@standby oracle]$ ls
arch backup checkpoints database product
[oracle@standby oracle]$ mkdir -p oradata/orcl
[oracle@standby oracle]$ mkdir -p admin/orcl/adump
[oracle@standby oracle]$ mkdir -p admin/orcl/dpdump
[oracle@standby oracle]$ mkdir -p admin/orcl/pfile
5)啟動備庫到nomount模式
SQL>create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';
SQL> startup nomount;
6)在備庫上使用RMAN恢復數據庫
[oracle@standby ~]$ rman target sys/asd@pri
RMAN> connect auxiliary /
run {
allocate auxiliary channel c1 device type disk;
allocate auxiliary channel c2 device type disk;
duplicate target database for standby nofilenamecheck dorecover;
release channel c1;
release channel c2;
}
雖然最后出現了這個問題,但備庫還是可以打開的。
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 06/08/2016 17:38:36
RMAN-03015: error occurred in stored script Memory Script
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 16 and starting SCN of 1010403 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 15 and starting SCN of 1009794 found to restore
7)備庫上添加standby logfile
備庫上添加standby logfile,我做測試時,v$logfile視圖里有standby logfile group4 至group 7,而/u01/app/oracle/oradata/orcl并沒有這些文件,所以要先把這幾組日志刪除再重建:
SQL>alter database open;#未試過在mount狀態創建standby日志
SQL> alter database drop logfile group 4;
SQL> alter database drop logfile group 5;
SQL> alter database drop logfile group 6;
SQL> alter database drop logfile group 7;
SQL>alter database add standby logfile group 4 ('/u01/app/oracle/oradata/orcl/redo_dg_021.log') size 50M;
SQL>alter database add standby logfile group 5 ('/u01/app/oracle/oradata/orcl/redo_dg_022.log') size 50M;
SQL>alter database add standby logfile group 6 ('/u01/app/oracle/oradata/orcl/redo_dg_023.log') size 50M;
SQL>alter database add standby logfile group 7 ('/u01/app/oracle/oradata/orcl/redo_dg_024.log') size 50M;
8)應用歸檔
--應用歸檔
SQL>shutdown immediate;
SQL>startup mount;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
--退出歸檔
alter database recover managed standby database cancel;
9)查看狀態
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# FIRST_TIME NEXT_TIME APPLIED
---------- ------------------ ------------------ ---------
15 08-JUN-16 08-JUN-16 YES
16 08-JUN-16 08-JUN-16 YES
17 08-JUN-16 08-JUN-16 YES
18 08-JUN-16 08-JUN-16 YES
19 08-JUN-16 08-JUN-16 YES
20 08-JUN-16 08-JUN-16 YES
21 08-JUN-16 08-JUN-16 IN-MEMORY
說明DG已經搭建成功
注:如果備庫處于open狀態,告警日志中會出現:ORA-16058: 未裝載備用數據庫實例的告警信息。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。