摘自ddba的文章,未经本人实验。
[@more@] 需要 online 创建 standby ,不妨看看这个, rman duplicate 功能使 standby 的创建过程极大的简单化了 ~ 前期工作都是一样的,在此并没有详细阐述,如有需要参看相关文档 ~1 。创建 standby 控制文件
[etuser@backup10 etuser]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Nov 14 09:40:56 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: PPE2 (DBID=1441027847)
RMAN> backup current controlfile for standby format '/home/etuser/control01.ctl';
Starting backup at 14-NOV-06
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=360 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including standby control file in backupset
channel ORA_DISK_1: starting piece 1 at 14-NOV-06
channel ORA_DISK_1: finished piece 1 at 14-NOV-06
piece handle=/home/etuser/control01.ctl tag=TAG20061114T094313 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 14-NOV-06
Starting Control File and SPFILE Autobackup at 14-NOV-06
piece handle=/data/dbbak/rmanbak/c-1441027847-20061114-02 comment=NONE
Finished Control File and SPFILE Autobackup at 14-NOV-06
RMAN> sql"alter system switch logfile";
sql statement: alter system switch logfile
RMAN> sql"alter system switch logfile";
sql statement: alter system switch logfile
RMAN>
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
593
创建好控制文件之后, copy 到 auxiliary 服务器上的相应位置,否则复制过程中会报错:
ORA-19870: error reading backup piece /home/etuser/control01.ctl
ORA-19505: failed to identify file "/home/etuser/control01.ctl"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
2 。在两边创建 pwdfile
orapwd file=PWDppe2.ora password=oracle entries=10
3 。创建好相应目录, dump 文件目录,数据文件目录,归档目录
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup nomount pfile=initppe2.ora
ORACLE instance started.
Total System Global Area 750780416 bytes
Fixed Size 1221636 bytes
Variable Size 197135356 bytes
Database Buffers 545259520 bytes
Redo Buffers 7163904 bytes
必须是 nomount 状态,否则无法进行 duplicate 操作
4 。进行复制 之前需要把一个完整的备份传到 auxiliary 服务器上,且两边备份文件存放的目录要一致,也就是说 target 把备份到哪,就要把备份放
在 standby 上的相同位置。
run{
set until sequence=596 thread=1;
duplicate target database for standby dorecover;
}
[etuser@ppe2bak etuser]$ rman auxiliary /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Nov 14 12:45:19 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to auxiliary database: PPE2 (not mounted)
RMAN> connect target system/oracle@ppe2
connected to target database: PPE2 (DBID=1441027847)
RMAN> run{
2> set until sequence=596 thread=1;
3> duplicate target database for standby dorecover;
4> }
executing command: SET until clause
using target database control file instead of recovery catalog
Starting Duplicate Db at 14-NOV-06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=375 devtype=DISK
contents of Memory Script:
{
set until scn 5885994467;
restore clone standby controlfile;
sql clone 'alter database mount standby database';
}
executing Memory Script
executing command: SET until clause
Starting restore at 14-NOV-06
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /home/etuser/control01.ctl
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/etuser/control01.ctl tag=TAG20061114T094313
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/home/etuser/oracle/oradata/ppe2/control01.ctl
output filename=/home/etuser/oracle/oradata/ppe2/control02.ctl
output filename=/home/etuser/oracle/oradata/ppe2/control03.ctl
Finished restore at 14-NOV-06
sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1
contents of Memory Script:
{
set until scn 5885994467;
set newname for tempfile 1 to
"/home/etuser/oracle/oradata/ppe2/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/home/etuser/oracle/oradata/ppe2/system01.dbf";
set newname for datafile 2 to
"/home/etuser/oracle/oradata/ppe2/undotbs01.dbf";
set newname for datafile 3 to
"/home/etuser/oracle/oradata/ppe2/sysaux01.dbf";
set newname for datafile 4 to
"/home/etuser/oracle/oradata/ppe2/users01.dbf";
set newname for datafile 5 to
"/home/etuser/oracle/oradata/ppe2/example01.dbf";
set newname for datafile 6 to
"/home/etuser/oracle/oradata/ppe2/perfstat.dbf";
set newname for datafile 7 to
"/home/etuser/oracle/oradata/ppe2/users02.dbf";
restore
check readonly
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
renamed temporary file 1 to /home/etuser/oracle/oradata/ppe2/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
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 14-NOV-06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=375 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /home/etuser/oracle/oradata/ppe2/system01.dbf
restoring datafile 00002 to /home/etuser/oracle/oradata/ppe2/undotbs01.dbf
restoring datafile 00003 to /home/etuser/oracle/oradata/ppe2/sysaux01.dbf
restoring datafile 00004 to /home/etuser/oracle/oradata/ppe2/users01.dbf
restoring datafile 00005 to /home/etuser/oracle/oradata/ppe2/example01.dbf
restoring datafile 00006 to /home/etuser/oracle/oradata/ppe2/perfstat.dbf
restoring datafile 00007 to /home/etuser/oracle/oradata/ppe2/users02.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/etuser/full_loi2c9qh_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/etuser/full_loi2c9qh_1_1 tag=TAG20061114T104328
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:36
Finished restore at 14-NOV-06
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy recid=9 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=10 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=11 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=12 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=13 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=14 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/perfstat.dbf
datafile 7 switched to datafile copy
input datafile copy recid=15 stamp=606487731 filename=/home/etuser/oracle/oradata/ppe2/users02.dbf
contents of Memory Script:
{
set until scn 5885994467;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 14-NOV-06
using channel ORA_AUX_DISK_1
starting media recovery
archive log thread 1 sequence 594 is already on disk as file
/home/etuser/oracle/arc_dest/ppe2_1_594_594148617.arc
archive log thread 1 sequence 595 is already on disk as file
/home/etuser/oracle/arc_dest/ppe2_1_595_594148617.arc
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=592
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=593
channel ORA_AUX_DISK_1: reading from backup piece /home/etuser/oracle/product/10.2.0/db_1/dbs/lni2c9qc_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/etuser/oracle/product/10.2.0/db_1/dbs/lni2c9qc_1_1 tag=TAG20061114T104324
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_592_594148617.arc thread=1 sequence=592
channel clone_default: deleting archive log(s)
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_592_594148617.arc recid=2 stamp=606487734
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_593_594148617.arc thread=1 sequence=593
channel clone_default: deleting archive log(s)
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_593_594148617.arc recid=1 stamp=606487734
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_594_594148617.arc thread=1 sequence=594
archive log filename=/home/etuser/oracle/arc_dest/ppe2_1_595_594148617.arc thread=1 sequence=595
media recovery complete, elapsed time: 00:00:03
Finished recover at 14-NOV-06
Finished Duplicate Db at 14-NOV-06
RMAN>
检查 standby 库:
SQL> col database_role for a20
SQL> col protection_mode for a20
SQL> col protection_level for a20
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
-------------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
SQL> alter database recover managed standby database disconnect;
Database altered.
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APPLIED
---------- ---------
593 YES
592 YES
594 NO
595 YES
596 YES
597 YES
6 rows selected.
检查 primary :
SQL> select sequence#,applied from v$archived_log where sequence#>596;
SEQUENCE# APP
---------- ---
597 NO
597 YES
检查 standby alert 日志:
[etuser@ppe2bak bdump]$ tail -f alert*.log
Errors in file /home/etuser/oracle/admin/ppe2/bdump/ppe2_mrp0_23814.trc:
ORA-19527: physical standby redo log must be renamed
ORA-00312: online log 1 thread 1: '/home/etuser/oracle/product/10.2.0/oradata/ppe2/redo01.log'
Clearing online redo logfile 1 complete
Media Recovery Log /home/etuser/oracle/arc_dest/ppe2_1_596_594148617.arc
Tue Nov 14 12:51:54 2006
Completed: alter database recover managed standby database disconnect
Tue Nov 14 12:51:56 2006
Media Recovery Log /home/etuser/oracle/arc_dest/ppe2_1_597_594148617.arc
Media Recovery Waiting for thread 1 sequence 598
在主库上进行日志切换:
SQL> alter system switch logfile;
System altered.
SQL> select sequence#,applied from v$archived_log where sequence#>596;
SEQUENCE# APP
---------- ---
597 NO
597 YES
598 NO
598 NO
SQL> select sequence#,applied from v$archived_log where sequence#>596;
SEQUENCE# APP
---------- ---
597 NO
597 YES
598 NO
598 YES
查看备机:
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APPLIED
---------- ---------
593 YES
592 YES
594 NO
595 YES
596 YES
597 YES
598 YES
7 rows selected.
SQL>
查看备机 alert 日志:
[etuser@ppe2bak bdump]$ tail -f alert*.log
Completed: alter database recover managed standby database disconnect
Tue Nov 14 12:51:56 2006
Media Recovery Log /home/etuser/oracle/arc_dest/ppe2_1_597_594148617.arc
Media Recovery Waiting for thread 1 sequence 598
Tue Nov 14 13:04:01 2006
RFS[1]: No standby redo logfiles created
RFS[1]: Archived Log: '/home/etuser/oracle/arc_dest/ppe2_1_598_594148617.arc'
Tue Nov 14 13:04:02 2006
Media Recovery Log /home/etuser/oracle/arc_dest/ppe2_1_598_594148617.arc
Media Recovery Waiting for thread 1 sequence 599
完全正常,至此 standby 创建完毕。
总结:
1 。使用 rman 创建的控制文件要传送到 standby 上的相同目录;
2 。先要在 primary 进行全备,然后传送到 standby 上的相同目录; 在这里建议使用 RMAN> backup database format '/data/dbbak/rmanbak/full_stdby_%U' plus archivelog; 进行备份,另外需要
注意的是 plus archivelog 会在备份前后进行两次日志切换,所以在 duplicate 里的 until sequence 应该是 max(sequence#)-1 。
rman 备份在 ?/dbs 下面的文件也要重送到 standby 上的相同地方,否则复制过程中会报错。
3 。做一下对比,三种创建 standby 的方法:冷备份, rman 备份, rman 复制。感觉是使用冷备份是最简单又不容易出错, rman 复制实际
上是把使用 rman 备份的恢复过程自动化了,省了很多事,使恢复过程简单化。所以如果允许停库建议使用冷备份,在线的话直接使用
rman 复制创建 standby 。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/60088/viewspace-912864/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/60088/viewspace-912864/