RAC資料庫建立STANDBY(一)

yangtingkun發表於2009-05-25

這篇文章描述為RAC環境建立STANDBY資料庫。

由於篇幅限制,加上碰到了很多的bug,只能將文章拆分成多篇。

這章介紹STANDBY資料庫的準備和建立過程。

 

 

STANDBY資料庫同樣是RAC環境,不過和主資料庫採用VOLUMN CLUSTER MANAGER不同,STANDBY資料庫採用ASM

在源資料庫中設定FORCE_LOGGING和相應的初始化引數:

SQL> SELECT DBID, NAME, LOG_MODE, FORCE_LOGGING FROM V$DATABASE;

      DBID NAME      LOG_MODE     FOR
---------- --------- ------------ ---
1712482917 RAC11G    ARCHIVELOG   NO

SQL> ALTER DATABASE FORCE LOGGING;

資料庫已更改。

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(rac11g,rac11g_s)';

系統已更改。

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_1=
  2  'LOCATION=/data/oracle/oradata/rac11g/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=rac11g';

系統已更改。

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=rac11g_s LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac11g_s';

系統已更改。

SQL> ALTER SYSTEM SET FAL_SERVER=rac11g_s;

系統已更改。

SQL> ALTER SYSTEM SET FAL_CLIENT=rac11g;

系統已更改。

SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

系統已更改。

手工在源資料庫的兩個節點分別新增訪問STANDBY資料庫的服務名,以及在STANDBY資料庫恢復過程中臨時使用的服務名:

RAC11G_S =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.68)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.69)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac11g_s.us.oracle.com)
    )
  )

RAC11G1_S =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.62)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = rac11g1)
    )
  )

同樣,在STANDBY資料庫的TNSNAMES.ORA中也要新增STANDBYPRIMARY資料庫的服務名。

STANDBY資料庫的Oracle rac環境已經建立,ASM也已經啟動,資料庫版本時11g,本打算採用FROM ACTIVE DATABASE方式建立STANDBY,但是這種方式對於源資料庫為裸裝置,目標資料庫使用ASM的情況存在很多的bug,所以仍然使用備份恢復的方法。

首先檢查當前環境:

$ env|grep ORA
ORACLE_BASE=/data/oracle
ORACLE_HOME=/data/oracle/product/11.1/database
ORACLE_SID=rac11g1

編輯初始化引數,建立spfile,啟動AUXILIARY例項:

rac11g1.__db_cache_size=13757317120
rac11g2.__db_cache_size=13623099392
rac11g2.__java_pool_size=67108864
rac11g1.__java_pool_size=134217728
rac11g2.__large_pool_size=67108864
rac11g1.__large_pool_size=67108864
rac11g1.__oracle_base='/data/oracle'#ORACLE_BASE set from environment
rac11g2.__oracle_base='/data/oracle'#ORACLE_BASE set from environment
rac11g2.__pga_aggregate_target=2147483648
rac11g1.__pga_aggregate_target=2147483648
rac11g2.__sga_target=15032385536
rac11g1.__sga_target=15032385536
rac11g2.__shared_io_pool_size=0
rac11g1.__shared_io_pool_size=0
rac11g1.__shared_pool_size=1006632960
rac11g2.__shared_pool_size=1207959552
rac11g2.__streams_pool_size=0
rac11g1.__streams_pool_size=0
*.audit_file_dest='/data/oracle/admin/rac11g/adump'
*.audit_trail='db'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='11.1.0.0.0'
*.control_files='+DATA/RAC11G/rac11g_control_1','+DATA/RAC11G/rac11g_control_2','+DATA/RAC11G/rac11g_control_3'
*.db_block_size=16384
*.db_domain='us.oracle.com'
*.db_name='rac11g'
*.diagnostic_dest='/data/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=rac11gXDB)'
fal_client='RAC11G_S'
fal_server='RAC11G'
log_archive_dest_1='LOCATION=+DATA/RAC11G VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=rac11g_s'
log_archive_dest_2='SERVICE=rac11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac11g'
db_unique_name='rac11g_s'
rac11g2.instance_number=2
rac11g1.instance_number=1
rac11g1.local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=172.0.2.62)(PORT=1521))'
rac11g2.local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=172.0.2.63)(PORT=1521))'
*.log_archive_config='DG_CONFIG=(rac11g,rac11g_s)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=17179869184
*.open_cursors=300
*.pga_aggregate_target=2147483648
*.processes=600
*.remote_listener='LISTENERS_RAC11G'
*.remote_login_passwordfile='exclusive'
*.sessions=600
rac11g1.sga_target=15032385536
*.sga_target=15032385536
rac11g2.sga_target=15032385536
*.standby_file_management='AUTO'
rac11g2.thread=2
rac11g1.thread=1
rac11g2.undo_tablespace='UNDOTBS2'
rac11g1.undo_tablespace='UNDOTBS1'
db_file_name_convert=('/dev/vx/rdsk/datavg', '+DATA/RAC11G')
log_file_name_convert=('/dev/vx/rdsk/datavg', '+DATA/RAC11G')

下面透過這個初始化引數啟動例項:

bash-3.00$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on 星期二 9 9 18:29:34 2008

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

已連線到空閒例程。

SQL> create spfile from pfile='/data/initrac11g.ora';

檔案已建立。

SQL> startup nomount
ORACLE
例程已經啟動。

Total System Global Area 1.7108E+10 bytes
Fixed Size                  2101632 bytes
Variable Size            3344420480 bytes
Database Buffers         1.3757E+10 bytes
Redo Buffers                4431872 bytes
SQL> exit
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
斷開

DUPLICATE RAC環境一樣的問題,由於本地備份集是存放在ASM中,因此只能透過CATALOG方式,手工修改CATALOGBACKUP PIECEHANDLE記錄,將其改為目標資料庫上ASM中備份集的全路徑:

SQL> conn catalog_user/catalog_user
已連線。
SQL> col handle format a60
SQL> select bp_key, handle from rc_backup_piece;

    BP_KEY HANDLE
---------- ------------------------------------------------------------
      1475 /data/01jpk0bj_1_1

SQL> update rc_backup_piece set handle = '+DATA/backup/01jpk0bj_1_1'            
  2  where bp_key = 1475;

已更新 1 行。

SQL> commit;

提交完成。

確保源資料庫的歸檔日誌,在STANDBY資料庫中的相同目錄下可以被訪問,然後透過RMAN來執行DUPLICATE命令:

bash-3.00$ rman target sys/test@172.0.2.54/rac11g.us.oracle.com catalog catalog_user/catalog_user@172.0.2.61/test11g.netdb auxiliary /

Recovery Manager: Release 11.1.0.6.0 - Production on Wed Sep 10 10:02:15 2008

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

connected to target database: RAC11G (DBID=1712482917)
connected to recovery catalog database
connected to auxiliary database: RAC11G (not mounted)

RMAN> duplicate target database for standby
2> dorecover;

Starting Duplicate Db at 10-SEP-08
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=660 instance=rac11g1 device type=DISK

contents of Memory Script.:
{
   set until scn  29148537;
   restore clone standby controlfile;
   sql clone 'alter database mount standby database';
}
executing Memory Script

executing command: SET until clause

Starting restore at 10-SEP-08
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: restoring control file
ORA-19625: error identifying file /data/oracle/product/11.1/database/dbs/snapcf_rac11g1.f
ORA-27037: unable to obtain file status
SVR4 Error: 2: No such file or directory
Additional information: 3
ORA-19600: input file is control file  (/data/oracle/product/11.1/database/dbs/snapcf_rac11g1.f)
ORA-19601: output file is control file  (+DATA/rac11g/rac11g_control_1)

failover to previous backup

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/01jpk0bj_1_1
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/01jpk0bj_1_1 tag=TAG20080902T204539
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=+DATA/rac11g/rac11g_control_1
output file name=+DATA/rac11g/rac11g_control_2
output file name=+DATA/rac11g/rac11g_control_3
Finished restore at 10-SEP-08

sql statement: alter database mount standby database

contents of Memory Script.:
{
   set until scn  29148537;
   set newname for tempfile  1 to
 "+DATA/rac11g/rac11g_temp_1_4g";
   set newname for tempfile  2 to
 "+DATA/rac11g/rac11g_temp_2_16g";
   switch clone tempfile all;
   set newname for datafile  1 to
 "+DATA/rac11g/rac11g_system_1_1g";
   set newname for datafile  2 to
 "+DATA/rac11g/rac11g_sysaux_1_1g";
   set newname for datafile  3 to
 "+DATA/rac11g/rac11g_undotbs1_1_4g";
   set newname for datafile  4 to
 "+DATA/rac11g/rac11g_undotbs2_1_4g";
   set newname for datafile  5 to
 "+DATA/rac11g/rac11g_users_1_4g";
   set newname for datafile  6 to
 "+DATA/rac11g/rac11g_ndmain_1_32g";
   set newname for datafile  7 to
 "+DATA/rac11g/rac11g_ndmain_2_32g";
   set newname for datafile  8 to
 "+DATA/rac11g/rac11g_ndmain_3_32g";
   set newname for datafile  9 to
 "+DATA/rac11g/rac11g_ndmain_4_32g";
   set newname for datafile  10 to
 "+DATA/rac11g/rac11g_ndmain_5_32g";
   set newname for datafile  11 to
 "+DATA/rac11g/rac11g_ndmain_6_32g";
   set newname for datafile  12 to
 "+DATA/rac11g/rac11g_undotbs1_2_32g";
   set newname for datafile  13 to
 "+DATA/rac11g/rac11g_undotbs2_2_32g";
   set newname for datafile  14 to
 "+DATA/rac11g/rac11g_perfstat_1_8g";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to +DATA/rac11g/rac11g_temp_1_4g in control file
renamed tempfile 2 to +DATA/rac11g/rac11g_temp_2_16g in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 10-SEP-08
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to +DATA/rac11g/rac11g_system_1_1g
channel ORA_AUX_DISK_1: restoring datafile 00002 to +DATA/rac11g/rac11g_sysaux_1_1g
channel ORA_AUX_DISK_1: restoring datafile 00003 to +DATA/rac11g/rac11g_undotbs1_1_4g
channel ORA_AUX_DISK_1: restoring datafile 00004 to +DATA/rac11g/rac11g_undotbs2_1_4g
channel ORA_AUX_DISK_1: restoring datafile 00005 to +DATA/rac11g/rac11g_users_1_4g
channel ORA_AUX_DISK_1: restoring datafile 00006 to +DATA/rac11g/rac11g_ndmain_1_32g
channel ORA_AUX_DISK_1: restoring datafile 00007 to +DATA/rac11g/rac11g_ndmain_2_32g
channel ORA_AUX_DISK_1: restoring datafile 00008 to +DATA/rac11g/rac11g_ndmain_3_32g
channel ORA_AUX_DISK_1: restoring datafile 00009 to +DATA/rac11g/rac11g_ndmain_4_32g
channel ORA_AUX_DISK_1: restoring datafile 00010 to +DATA/rac11g/rac11g_ndmain_5_32g
channel ORA_AUX_DISK_1: restoring datafile 00011 to +DATA/rac11g/rac11g_ndmain_6_32g
channel ORA_AUX_DISK_1: restoring datafile 00012 to +DATA/rac11g/rac11g_undotbs1_2_32g
channel ORA_AUX_DISK_1: restoring datafile 00013 to +DATA/rac11g/rac11g_undotbs2_2_32g
channel ORA_AUX_DISK_1: restoring datafile 00014 to +DATA/rac11g/rac11g_perfstat_1_8g
channel ORA_AUX_DISK_1: reading from backup piece +DATA/backup/01jpk0bj_1_1
channel ORA_AUX_DISK_1: piece handle=+DATA/backup/01jpk0bj_1_1 tag=TAG20080902T204539
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 01:02:59
Finished restore at 10-SEP-08

contents of Memory Script.:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=665060742 file name=+DATA/rac11g/rac11g_system_1_1g
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=665060742 file name=+DATA/rac11g/rac11g_sysaux_1_1g
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=665060743 file name=+DATA/rac11g/rac11g_undotbs1_1_4g
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=665060743 file name=+DATA/rac11g/rac11g_undotbs2_1_4g
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=665060743 file name=+DATA/rac11g/rac11g_users_1_4g
datafile 6 switched to datafile copy
input datafile copy RECID=6 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_1_32g
datafile 7 switched to datafile copy
input datafile copy RECID=7 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_2_32g
datafile 8 switched to datafile copy
input datafile copy RECID=8 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_3_32g
datafile 9 switched to datafile copy
input datafile copy RECID=9 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_4_32g
datafile 10 switched to datafile copy
input datafile copy RECID=10 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_5_32g
datafile 11 switched to datafile copy
input datafile copy RECID=11 STAMP=665060743 file name=+DATA/rac11g/rac11g_ndmain_6_32g
datafile 12 switched to datafile copy
input datafile copy RECID=12 STAMP=665060743 file name=+DATA/rac11g/rac11g_undotbs1_2_32g
datafile 13 switched to datafile copy
input datafile copy RECID=13 STAMP=665060743 file name=+DATA/rac11g/rac11g_undotbs2_2_32g
datafile 14 switched to datafile copy
input datafile copy RECID=14 STAMP=665060743 file name=+DATA/rac11g/rac11g_perfstat_1_8g

contents of Memory Script.:
{
   set until scn  29148537;
   recover
   standby
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 10-SEP-08
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 528 is already on disk as file /data/oracle/oradata/rac11g/archivelog/1_528_660235173.dbf
archived log for thread 1 with sequence 529 is already on disk as file /data/oracle/oradata/rac11g/archivelog/1_529_660235173.dbf
archived log for thread 1 with sequence 530 is already on disk as file /data/oracle/oradata/rac11g/archivelog/1_530_660235173.dbf
archived log for thread 1 with sequence 531 is already on disk as file /data/oracle/oradata/rac11g/archivelog/1_531_660235173.dbf
archived log for thread 1 with sequence 532 is already on disk as file /data/oracle/oradata/rac11g/archivelog/1_532_660235173.dbf
archived log for thread 2 with sequence 193 is already on disk as file /data/oracle/oradata/rac11g/archivelog/2_193_660235173.dbf
archived log for thread 2 with sequence 194 is already on disk as file /data/oracle/oradata/rac11g/archivelog/2_194_660235173.dbf
archived log for thread 2 with sequence 195 is already on disk as file /data/oracle/oradata/rac11g/archivelog/2_195_660235173.dbf
archived log for thread 2 with sequence 196 is already on disk as file /data/oracle/oradata/rac11g/archivelog/2_196_660235173.dbf
archived log for thread 2 with sequence 197 is already on disk as file /data/oracle/oradata/rac11g/archivelog/2_197_660235173.dbf
archived log file name=/data/oracle/oradata/rac11g/archivelog/1_528_660235173.dbf thread=1 sequence=0
archived log file name=/data/oracle/oradata/rac11g/archivelog/2_193_660235173.dbf thread=2 sequence=0
archived log file name=/data/oracle/oradata/rac11g/archivelog/1_529_660235173.dbf thread=1 sequence=529
archived log file name=/data/oracle/oradata/rac11g/archivelog/2_194_660235173.dbf thread=2 sequence=194
archived log file name=/data/oracle/oradata/rac11g/archivelog/1_530_660235173.dbf thread=1 sequence=530
archived log file name=/data/oracle/oradata/rac11g/archivelog/1_531_660235173.dbf thread=1 sequence=531
archived log file name=/data/oracle/oradata/rac11g/archivelog/2_195_660235173.dbf thread=2 sequence=195
archived log file name=/data/oracle/oradata/rac11g/archivelog/1_532_660235173.dbf thread=1 sequence=532
archived log file name=/data/oracle/oradata/rac11g/archivelog/2_196_660235173.dbf thread=2 sequence=196
archived log file name=/data/oracle/oradata/rac11g/archivelog/2_197_660235173.dbf thread=2 sequence=197
media recovery complete, elapsed time: 00:04:27
Finished recover at 10-SEP-08
Finished Duplicate Db at 10-SEP-08

至此STANDBY資料庫的恢復過程已經完成,下一篇繼續介紹STANDBY資料庫的後續處理已經檢查過程。

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-604155/,如需轉載,請註明出處,否則將追究法律責任。

相關文章