11G DG搭建--rman方式
DG建立
環境
這次建立DG的環境是
Database:11.2.0.3
主備庫的oracle軟體安裝路徑都在/u01/app/oracle下面。
主庫IP地址:20.4.1.81
備庫IP地址:20.4.1.79
準備TNS項
在主庫上編輯tns檔案,然後拷貝到備庫上。
[[email protected] ~]$ cat /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora # Generated by Oracle configuration tools.
ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 20.4.1.81)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )
#連線到主庫的tns zd_pri = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 20.4.1.81)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = pri) ) )
#連線到備庫的tns zd_std = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 20.4.1.79)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = std) ) ) |
配置好之後,將該tnsname.ora拷貝的standby庫上。
驗證一下tnsping,和使用sqlplus登陸一下,連線是通的
[[email protected] ~]$ tnsping zd_pri
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 08-MAR-2014 14:33:21
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 20.4.1.81)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = pri))) OK (0 msec) [[email protected] ~]$ sqlplus system/[email protected]_pri
SQL*Plus: Release 11.2.0.3.0 Production on Sat Mar 8 14:33:35 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> |
配置主備庫的listener.ora檔案(如果不做switch over就不需要做),新增SID_LIST
SID_LIST_LISTENER= (SID_LIST = (SID_DESC= (GLOBAL_DBNAME=pri) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db) (SID_NAME=orcl) ) ) |
新增這個的時候,需要注意的是SID_LIST_LISTENER必須定格寫,不然會報錯。
在備庫的時候也需要新增如下內容
SID_LIST_LISTENER= (SID_LIST = (SID_DESC= (GLOBAL_DBNAME=std) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db) (SID_NAME=orcl) ) ) |
修改主庫的相關項:
alter database force logging; alter database archivelog; |
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Mar 8 13:10:11 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> archive log list Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 6 Current log sequence 8 SQL> select force_logging from v$database;
FOR --- NO
SQL> alter database force logging;
Database altered.
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started.
Total System Global Area 4.0486E+10 bytes Fixed Size 2237088 bytes Variable Size 4026535264 bytes Database Buffers 3.6373E+10 bytes Redo Buffers 84631552 bytes Database mounted. SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 6 Next log sequence to archive 8 Current log sequence 8 SQL> select force_logging from v$database;
FOR --- YES |
在操作的時候,我是先將主庫引數檔案修改好
[[email protected] ~]$ cat $ORACLE_HOME/dbs/initorcl.ora *.audit_file_dest='/u01/app/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4322230272 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.nls_language='SIMPLIFIED CHINESE' *.nls_territory='CHINA' *.open_cursors=300 *.pga_aggregate_target=13519290368 *.processes=250 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=280 *.sga_target=40557871104 *.undo_tablespace='UNDOTBS1' #以上部分是資料庫原來的引數,如果有跟下面的相同的引數,就將上面的刪除 *.db_unique_name='pri' *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(pri,std)' *.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch/pri VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pri' *.LOG_ARCHIVE_DEST_2='SERVICE=zd_std LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=std' *.LOG_ARCHIVE_DEST_STATE_1=ENABLE *.LOG_ARCHIVE_DEST_STATE_2=ENABLE *.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc *.LOG_ARCHIVE_MAX_PROCESSES=5 *.FAL_SERVER=zd_std *.FAL_CLIENT=zd_pri *.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/std/','/u01/app/oracle/oradata/orcl/' *.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/std/','/u01/app/oracle/oradata/orcl/' *.STANDBY_FILE_MANAGEMENT=AUTO |
需要解釋一下這個幾個引數
db_unique_name 是資料庫的唯一名字,這個需要跟備庫有區別
LOG_ARCHIVE_CONFIG 是標註DG環境下的資料庫的unique_name
LOG_ARCHIVE_DEST_1 是資料庫歸檔的路徑,location表明歸檔的路徑。VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pri' 表明主庫的db_unique_name 為pri, valid_for表示,當該市裡的角色為all_roles的時候,all_logfiles所有的檔案都歸檔當location指定的位置上。
LOG_ARCHIVE_DEST_2='SERVICE=zd_std LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=std'
表示資料第二個歸檔路徑,其中service指定的tnsname.ora中配置的tnsname,指定的備庫的連線字串,同樣valid_for表示,該例項作為primay_role的時候,online_logfiles歸檔到service指定的路徑,db_unique_name指定的備庫的唯一名字
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE 啟動用這兩個歸檔路徑
*.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc 歸檔日誌的檔案命名格式
*.LOG_ARCHIVE_MAX_PROCESSES=5 歸檔程序的最大數量。
*.FAL_SERVER=zd_std 當在本例項是standby角色的時候取日誌的目標伺服器
*.FAL_CLIENT=zd_pri 當本例項是standby角色的時候,指定的客戶端,一般是本例項的tns
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/std/','/u01/app/oracle/oradata/orcl/' 資料檔案轉化,如果路徑一樣,就不需要轉換,如果不一樣的存放路徑就需要轉換。
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/std/','/u01/app/oracle/oradata/orcl/'
日誌檔案的路徑轉換
*.STANDBY_FILE_MANAGEMENT=AUTO 對standby檔案的管理方式
以下是備庫的引數檔案,注意標紅的部分的不同。因為角色的不同,所以這些引數就會有不同的地方。
*.audit_file_dest='/u01/app/oracle/admin/std/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/app/oracle/oradata/std/control01.ctl','/u01/app/oracle/fast_recovery_area/std/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4322230272 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.nls_language='SIMPLIFIED CHINESE' *.nls_territory='CHINA' *.open_cursors=300 *.pga_aggregate_target=13519290368 *.processes=250 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=280 *.sga_target=40557871104 *.undo_tablespace='UNDOTBS1'
*.db_unique_name='std' *.LOG_ARCHIVE_CONFIG='DG_CONFIG=(pri,std)' *.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch/std VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=std' *.LOG_ARCHIVE_DEST_2='SERVICE=zd_pri LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=pri' *.LOG_ARCHIVE_DEST_STATE_1=ENABLE *.LOG_ARCHIVE_DEST_STATE_2=ENABLE *.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc *.LOG_ARCHIVE_MAX_PROCESSES=5 *.FAL_SERVER=zd_pri *.FAL_CLIENT=zd_std *.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/std/' *.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/std/' *.STANDBY_FILE_MANAGEMENT=AUTO |
給主庫增加standby logfile
alter database add standby logfile group 4 size 50M; alter database add standby logfile group 5 size 50M; alter database add standby logfile group 6 size 50M; alter database add standby logfile group 7 size 50M; |
這個standby的日誌大小,必須跟online redo log的大小一樣,組數要比redo log多一組。
給主庫新增密碼檔案,如果主庫的密碼檔案沒有的話,需要這樣新增
[[email protected] dbs]$ orapwd file='/u01/app/oracle/product/11.2.0/db/dbs/orapworcl' password=oracle |
在備庫上補建引數檔案中的相關資料夾
[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/std/adump [[email protected] ~]$ mkdir -p /u01/app/oracle/oradata/std [[email protected] ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/std [[email protected] ~]$ mkdir -p /u01/app/oracle/arch/std |
利用備庫的引數檔案啟動備庫到nomount狀態,可以先建立spfile後,在啟動到nomount
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Mar 8 13:53:06 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount ORACLE instance started.
Total System Global Area 4.0486E+10 bytes Fixed Size 2237088 bytes Variable Size 3758099808 bytes Database Buffers 3.6641E+10 bytes Redo Buffers 84631552 bytes |
rman連線兩個庫做複製
rman target sys/[email protected]_pri auxiliary sys/[email protected]_std
duplicate target database for standby from active database;
[[email protected] admin]$ rman target sys/[email protected]_pri auxiliary sys/[email protected]_std
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Mar 8 14:10:27 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1369450057) connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby from active database;
Starting Duplicate Db at 08-MAR-14 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=313 device type=DISK
contents of Memory Script: { backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0/db/dbs/orapworcl' auxiliary format '/u01/app/oracle/product/11.2.0/db/dbs/orapworcl' ; } executing Memory Script
Starting backup at 08-MAR-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=106 device type=DISK Finished backup at 08-MAR-14
contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/std/control01.ctl'; restore clone controlfile to '/u01/app/oracle/fast_recovery_area/std/control02.ctl' from '/u01/app/oracle/oradata/std/control01.ctl'; } executing Memory Script
Starting backup at 08-MAR-14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/11.2.0/db/dbs/snapcf_orcl.f tag=TAG20140308T141113 RECID=3 STAMP=841673473 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 08-MAR-14
Starting restore at 08-MAR-14 using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: copied control file copy Finished restore at 08-MAR-14
contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script: { set newname for tempfile 1 to "/u01/app/oracle/oradata/std/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/u01/app/oracle/oradata/std/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/std/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/std/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/std/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/std/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oracle/oradata/std/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/std/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/std/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/std/users01.dbf" datafile 5 auxiliary format "/u01/app/oracle/oradata/std/example01.dbf" ; sql 'alter system archive log current'; } executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/std/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 08-MAR-14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf output file name=/u01/app/oracle/oradata/std/system01.dbf tag=TAG20140308T141120 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf output file name=/u01/app/oracle/oradata/std/sysaux01.dbf tag=TAG20140308T141120 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf output file name=/u01/app/oracle/oradata/std/example01.dbf tag=TAG20140308T141120 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf output file name=/u01/app/oracle/oradata/std/undotbs01.dbf tag=TAG20140308T141120 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf output file name=/u01/app/oracle/oradata/std/users01.dbf tag=TAG20140308T141120 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 08-MAR-14
sql statement: alter system archive log current
contents of Memory Script: { switch clone datafile all; } executing Memory Script
datafile 1 switched to datafile copy input datafile copy RECID=3 STAMP=841673486 file name=/u01/app/oracle/oradata/std/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=4 STAMP=841673486 file name=/u01/app/oracle/oradata/std/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=841673486 file name=/u01/app/oracle/oradata/std/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=6 STAMP=841673486 file name=/u01/app/oracle/oradata/std/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=7 STAMP=841673486 file name=/u01/app/oracle/oradata/std/example01.dbf Finished Duplicate Db at 08-MAR-14
RMAN> exit
Recovery Manager complete. |
此時檢視備庫的狀態
SQL> select status from v$instance ;
STATUS ------------ MOUNTED |
SQL> alter database recover managed standby database disconnect from session;
Database altered. |
此時可以在alert日誌中看到
Sat Mar 08 14:13:00 2014 alter database recover managed standby database disconnect from session Attempt to start background Managed Standby Recovery process (orcl) Sat Mar 08 14:13:00 2014 MRP0 started with pid=23, OS id=28042 MRP0: Background Managed Standby Recovery process started (orcl) started logmerger process Sat Mar 08 14:13:05 2014 Managed Standby Recovery not using Real Time Apply |
表明DG不是實時應用的,因此在主庫switch logfile的時候,在備庫的alert日誌中需要等待一段時間才能看到這個切換日誌應用操作。
將日誌的應用改為實時應用
alter database recover managed standby database cancel; alter database recover managed standby database using current logfile disconnect from session; |
此時再在備庫的日誌中可以看到
Sat Mar 08 14:19:44 2014 alter database recover managed standby database using current logfile disconnect from session Attempt to start background Managed Standby Recovery process (orcl) Sat Mar 08 14:19:44 2014 MRP0 started with pid=23, OS id=28265 MRP0: Background Managed Standby Recovery process started (orcl) started logmerger process Sat Mar 08 14:19:49 2014 Managed Standby Recovery starting Real Time Apply |
至此DG搭建完畢,可見rman搭建DG還是很快的。