分类: Oracle
2017-03-14 08:20:33
原文地址:RAC数据库建立STANDBY(一) 作者:TOMSYAN
这篇文章描述为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中也要添加STANDBY和PRIMARY数据库的服务名。
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方式,手工修改CATALOG中BACKUP PIECE的HANDLE记录,将其改为目标数据库上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数据库的后续处理已经检查过程。