ITPub博客

首页 > 数据库 > Oracle > MyDataGuard之二:使用RMAN实时创建DataGuard

MyDataGuard之二:使用RMAN实时创建DataGuard

原创 Oracle 作者:ddba 时间:2019-03-12 08:54:05 0 删除 编辑

使用rman实时创建dataguard

[@more@]

http://www.itpub.net/showthread.php?s=&threadid=667371

献上我的第二篇 dataguard 文章~
需要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/7794469/viewspace-878895/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: Oracle10g ADDM AWR ASH
请登录后发表评论 登录
全部评论

注册时间:2006-09-21

  • 博文量
    31
  • 访问量
    23974