DataGuard环境:
操作系统:redhat4.7
Primary数据库:
IP地址:10.85.10.1
数据库SID:orcl
DB_UNIQUE_NAME:orcl_pd
Standby数据库:
IP地址:10.85.10.2
数据库SID:orcl
DB_UNIQUE_NAME:orcl_st
OracleDataGuard理论知识
http://blog.csdn.net/tianlesoftware/archive/2010/04/22/5514082.aspx
OracleDataGuradPhysicalStandby相关说明
http://blog.csdn.net/tianlesoftware/archive/2010/05/04/5557410.aspx
OracleDataGuardLinux平台PhysicalStandby搭建实例
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5547565.aspx
之前也做过相关实验,今天这个测试主要是用RMAN来复制备份,之前一直是直接copy文件的。实验步骤都差不多。
一.Primary端的配置
1.主库设置为forcelogging模式
SQL>alterdatabaseforcelogging;
2.主库设为归档模式
SQL>archiveloglist;
SQL>shutdownimmediate
SQL>startupmount
SQL>alterdatabasearchivelog;
SQL>archiveloglist;
3.创建备库的口令文件
[oracle@localhostdbs]$orapwdfile=/u02/orapworclpassword=admin
如果已经存在,就不用创建了。缺省情况下,win下口令文件的格式是pwdsid.ora,unix下的格式是orapwSID(大小写敏感)。Linux默认位置为$ORACLE_HOME/dbs目录下下,Windows默认为$ORACLE_HOME/database目录。
用SCP命令将这个口令文件传输到备库的对应位置:
[oracle@db1dbs]$scporapworcl10.85.10.2:/u01/app/oracle/product/10.2.0/db_1/dbs
Theauthenticityofhost'10.85.10.2(10.85.10.2)'can'tbeestablished.
RSAkeyfingerprintis1a:20:7a:05:bd:e0:ac:04:21:02:b1:72:01:69:40:d6.
Areyousureyouwanttocontinueconnecting(yes/no)?yes
Warning:Permanentlyadded'10.85.10.2'(RSA)tothelistofknownhosts.
[email protected]'spassword:
orapworcl100%15361.5KB/s00:00
注意,如果不用RMAN复制的话,还需要创建备库的控制文件。RMAN复制的话,自己会创建控制文件。
4.修改初始化参数文件
Pfile默认位置在$ORACLE_HOME/dbs目录下,也可以自己指定位置:
SQL>createpfilefromspfile;
在initorcl.ora添加如下内容:
*.DB_UNIQUE_NAME='orcl_pd'
*.log_archive_dest_1='location=/u02/archivelog'
*.log_archive_dest_2='SERVICE=orcl_st'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.standby_file_management='AUTO'
*.standby_archive_dest='/u02/archivelog'
*.FAL_SERVER='orcl_st'
*.FAL_CLIENT='orcl_pd'
如果主库和备库的数据文件位置不同,还需要加如下2个参数:
*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
--注意:orcl_st,orcl_pd是在tnsnames文件中配置的
用刚修改的pfile启动数据库,并生成spfile。
SQL>shutdownimmediate
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
SQL>startuppfile=?/dbs/initorcl.ora
ORACLEinstancestarted.
TotalSystemGlobalArea247463936bytes
FixedSize1218748bytes
VariableSize75499332bytes
DatabaseBuffers163577856bytes
RedoBuffers7168000bytes
Databasemounted.
Databaseopened.
SQL>!echo$ORACLE_HOME
/u01/app/oracle/product/10.2.0/db_1
SQL>createspfilefrompfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora';
Filecreated.
5.修改listener.ora和tnsnames.ora文件
Listener.ora文件:
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=PLSExtProc)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(PROGRAM=extproc)
)
(SID_DESC=
(GLOBAL_DBNAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=orcl)
)
)
LISTENER=
(DESCRIPTION_LIST=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521))
(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0))
)
)
注意:SID_LIST_LISTENER配置的是静态注册,如果没有该参数,而且DataGuard启动顺序又不正确,那么在主库可能会报PING[ARC1]:Heartbeatfailedtoconnecttostandby'orcl_st'.Erroris12514.错误,导致归档无法完成。
OracleListener动态注册与静态注册
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx
Tnsnames.ora文件
ORCL_ST=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.85.10.2)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orcl)
)
)
ORCL_PD=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=10.85.10.1)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orcl)
)
)
二.Standby端配置
1.创建备库存放数据文件和后台跟踪目录。
这个目录可以和主库相同,如果不同,就需要在主库的初始化文件中进行转换。如:
*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
$ORACLE_BASE/ORADATA/ORCL
$ORACLE_BASE/admin/orcl
$ORACLE_BASE/admin/orcl/adump
$ORACLE_BASE/admin/orcl/bdump
$ORACLE_BASE/admin/orcl/cdump
$ORACLE_BASE/admin/orcl/dpdump
$ORACLE_BASE/admin/orcl/pfile
$ORACLE_BASE/admin/orcl/udump
$ORACLE_BASE/admin/orcl/
2.修改初始化参数文件
从主库copy过来,修改如下:
*.DB_UNIQUE_NAME='orcl_st'
*.log_archive_dest_1='location=/u01/archivelog'
*.log_archive_dest_2='SERVICE=orcl_pd'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER='orcl_pd'
*.FAL_CLIENT='orcl_st'
*.standby_file_management='AUTO'
*.standby_archive_dest='/u01/archivelog'
log_file_name_convert=('orcl','orcl')--该参数用于RMAN复制时重建redo文件。
4.修改listener.ora和tnsnames.ora文件,同主库。如果不存在,就从主库上copy过去。
5.RMAN复制数据库
5.1备份主库
[oracle@db1backup]$rmantargetsys/admin@orcl
RecoveryManager:Release10.2.0.1.0-ProductiononSunJul1818:26:162010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:ORCL(DBID=1248423599)
RMAN>RUN{
allocatechannelc1typedisk;
allocatechannelc2typedisk;
sql'altersystemarchivelogcurrent';
backupcurrentcontrolfileforstandbyformat='/u02/backup/control_%U';
BACKUPFORMAT'/u02/backup/orcl_%U_%T'skipinaccessiblefilesperset5DATABASE;
sql'altersystemarchivelogcurrent';
BACKUPFORMAT'/u02/backup/arch_%U_%T'skipinaccessiblefilesperset5ARCHIVELOGALLDELETEINPUT;
releasechannelc2;
releasechannelc1;
}
backupfulldatabaseincludecurrentcontrolfileforstandbyplusarchivelogFORMAT'/u02/backup/orcl_%U_%T'skipinaccessiblefilesperset5;
备份脚本,具体参考:
Linux平台下RMAN全备和增量备份shell脚本
http://blog.csdn.net/tianlesoftware/archive/2010/07/16/5740630.aspx
5.2 用SCP将备份集复制到备库相同的位置,或者直接用NFS挂载到相同位置。这些位置写入了控制文件,所以位置必须相同。
LinuxNFS和Samba共享配置
http://blog.csdn.net/tianlesoftware/archive/2010/07/21/5752092.aspx
如果出现:ORA-27054NFSfilesystemwherethefileiscreatedorresidesisnotmountedwithcorrectoptions的错误,可能是NFS挂载的参数使用不正确。
mount-tnfs192.168.19.219:/u01/rman-ohard,rw,noac,rsize=32768,wsize=32768,suid,proto=tcp,vers=3/u01/rman
如果用SCP复制,复制结束要后注意文件用户和权限。
5.3用pfile文件将备库启动到nomout状态
[oracle@localhostu01]$sqlplus/nolog
SQL*Plus:Release10.2.0.1.0-ProductiononWedJul2109:35:072010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
SQL>conn/assysdba
Connectedtoanidleinstance.
SQL>startupnomountpfile=?/dbs/initorcl.ora
ORACLEinstancestarted.
TotalSystemGlobalArea247463936bytes
FixedSize1218772bytes
VariableSize79693612bytes
DatabaseBuffers163577856bytes
RedoBuffers2973696bytes
5.4执行duplicate复制standby库
[oracle@db1dbs]$rmantarget/auxiliarysys/admin@orcl_st;
RecoveryManager:Release10.2.0.1.0-ProductiononTueJul2022:32:592010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:ORCL(DBID=1248423599)
connectedtoauxiliarydatabase:ORCL(notmounted)
RMAN>duplicatetargetdatabaseforstandbynofilenamecheckdorecover;
StartingDuplicateDbat21-JUL-10
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
contentsofMemoryScript:
{
setuntilscn800873;
restoreclonestandbycontrolfile;
sqlclone'alterdatabasemountstandbydatabase';
}
executingMemoryScript
executingcommand:SETuntilclause
Startingrestoreat21-JUL-10
usingchannelORA_AUX_DISK_1
channelORA_AUX_DISK_1:startingdatafilebackupsetrestore
channelORA_AUX_DISK_1:restoringcontrolfile
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/control_6mljbc6r_1_1
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/control_6mljbc6r_1_1tag=TAG20100721T115609
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:02
outputfilename=/u01/app/oracle/oradata/orcl/control01.ctl
outputfilename=/u01/app/oracle/oradata/orcl/control02.ctl
outputfilename=/u01/app/oracle/oradata/orcl/control03.ctl
Finishedrestoreat21-JUL-10
sqlstatement:alterdatabasemountstandbydatabase
releasedchannel:ORA_AUX_DISK_1
contentsofMemoryScript:
{
setuntilscn800873;
setnewnamefortempfile1to"/u01/app/oracle/oradata/orcl/temp01.dbf";
switchclonetempfileall;
setnewnamefordatafile1to"/u01/app/oracle/oradata/orcl/system01.dbf";
setnewnamefordatafile2to"/u01/app/oracle/oradata/orcl/undotbs01.dbf";
setnewnamefordatafile3to"/u01/app/oracle/oradata/orcl/sysaux01.dbf";
setnewnamefordatafile4to"/u01/app/oracle/oradata/orcl/users01.dbf";
setnewnamefordatafile5to"/u01/app/oracle/oradata/orcl/example01.dbf";
restore
checkreadonly
clonedatabase
;
}
executingMemoryScript
executingcommand:SETuntilclause
executingcommand:SETNEWNAME
renamedtemporaryfile1to/u01/app/oracle/oradata/orcl/temp01.dbfincontrolfile
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
Startingrestoreat21-JUL-10
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
channelORA_AUX_DISK_1:startingdatafilebackupsetrestore
channelORA_AUX_DISK_1:specifyingdatafile(s)torestorefrombackupset
restoringdatafile00002to/u01/app/oracle/oradata/orcl/undotbs01.dbf
restoringdatafile00003to/u01/app/oracle/oradata/orcl/sysaux01.dbf
restoringdatafile00005to/u01/app/oracle/oradata/orcl/example01.dbf
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/orcl_6oljbc7f_1_1_20100721
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/orcl_6oljbc7f_1_1_20100721tag=TAG20100721T115629
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:39
channelORA_AUX_DISK_1:startingdatafilebackupsetrestore
channelORA_AUX_DISK_1:specifyingdatafile(s)torestorefrombackupset
restoringdatafile00001to/u01/app/oracle/oradata/orcl/system01.dbf
restoringdatafile00004to/u01/app/oracle/oradata/orcl/users01.dbf
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/orcl_6nljbc7e_1_1_20100721
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/orcl_6nljbc7e_1_1_20100721tag=TAG20100721T115629
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:01:06
Finishedrestoreat21-JUL-10
contentsofMemoryScript:
{
switchclonedatafileall;
}
executingMemoryScript
datafile1switchedtodatafilecopy
inputdatafilecopyrecid=10stamp=724981117filename=/u01/app/oracle/oradata/orcl/system01.dbf
datafile2switchedtodatafilecopy
inputdatafilecopyrecid=11stamp=724981117filename=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile3switchedtodatafilecopy
inputdatafilecopyrecid=12stamp=724981117filename=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile4switchedtodatafilecopy
inputdatafilecopyrecid=13stamp=724981118filename=/u01/app/oracle/oradata/orcl/users01.dbf
datafile5switchedtodatafilecopy
inputdatafilecopyrecid=14stamp=724981118filename=/u01/app/oracle/oradata/orcl/example01.dbf
contentsofMemoryScript:
{
setuntilscn800873;
recover
standby
clonedatabase
deletearchivelog
;
}
executingMemoryScript
executingcommand:SETuntilclause
Startingrecoverat21-JUL-10
usingchannelORA_AUX_DISK_1
startingmediarecovery
channelORA_AUX_DISK_1:startingarchivelogrestoretodefaultdestination
channelORA_AUX_DISK_1:restoringarchivelog
archivelogthread=1sequence=74
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/arch_6sljbcd4_1_1_20100721
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/arch_6sljbcd4_1_1_20100721tag=TAG20100721T115930
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:04
archivelogfilename=/u01/archivelog/1_74_720642866.dbfthread=1sequence=74
channelclone_default:deletingarchivelog(s)
archivelogfilename=/u01/archivelog/1_74_720642866.dbfrecid=1stamp=724981127
channelORA_AUX_DISK_1:startingarchivelogrestoretodefaultdestination
channelORA_AUX_DISK_1:restoringarchivelog
archivelogthread=1sequence=75
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/arch_6vljbcd7_1_1_20100721
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/arch_6vljbcd7_1_1_20100721tag=TAG20100721T115930
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:04
archivelogfilename=/u01/archivelog/1_75_720642866.dbfthread=1sequence=75
channelclone_default:deletingarchivelog(s)
archivelogfilename=/u01/archivelog/1_75_720642866.dbfrecid=2stamp=724981133
mediarecoverycomplete,elapsedtime:00:00:03
Finishedrecoverat21-JUL-10
FinishedDuplicateDbat21-JUL-10
RMAN>
6.在备库添加redologfile
如果主库没有添加redologfile,可以先用copy过来的初始化文件将数据库启动到mount状态。在创建个spfile,最后添加redolog。
SQL>createspfilefrompfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora';
添加一个新的StandbyRedologs组(注意组号不要与当前存在的OnlineRedologs组重复),并为该组指定一个成员:
SQL>ALTERDATABASEADDSTANDBYLOGFILEGROUP4('/u01/app/oracle/oradata/orcl/redo04.log')size50M;
SQL>ALTERDATABASEADDSTANDBYLOGFILEGROUP5('/u01/app/oracle/oradata/orcl/redo05.log')size50M;
SQL>ALTERDATABASEADDSTANDBYLOGFILEGROUP6('/u01/app/oracle/oradata/orcl/redo06.log')size50M;
SQL>ALTERDATABASEADDSTANDBYLOGFILEGROUP7('/u01/app/oracle/oradata/orcl/redo07.log')size50M;
提示,由于从Primary数据库复制文件时并没有复制OnlineRedologs,因此物理Standby数据库在第一次启动REDO应用时,会在Alert文件中报OnlineRedoLogfile文件不存在,没有关系,物理Standby会自动重建这批文件,同时你也不用担心会丢失数据,OnlineRedologs中的数据会以归档文件的形式从Primary端接收。
至此,DataGuard的操作已经完成,下面来开始验证。
注意DataGuard启动顺序:
启动顺序:先standby,后primary;
闭顺序:先primary后standby;
在备库将实例启动到mount状态:
SQL>startupnomount;
SQL>alterdatabasemountstandbydatabase;
SQL>ALTERDATABASERECOVERMANAGEDSTANDBYDATABASECANCEL;
SQL>alterdatabaserecovermanagedstandbydatabasedisconnectfromsession;
在备库启动监听:
$lsnrctlstart
在主库启动实例:
SQL>startup;
在主库启动监听:
$lsnrctlstart
在主库验证归档目录是否有效:
SQL>SELECTSTATUS,DESTINATION,ERRORFROMV$ARCHIVE_DEST;
如果有错误,要排查原因。
SQL>altersystemswitchlogfile;
SQL>selectmax(sequence#)fromv$archived_log;
MAX(SEQUENCE#)
--------------
70
主备查询结果一致,DataGuard搭建结束。
注意:如果在主库执行alterdatabaseclearunarchivedlogfile或alterdatabaseopenresetlogs, 则dataguard要重建。
其他如DG模式切换,主备库切换等操作,参考如下blog:
OracleDataGuardLinux平台PhysicalStandby搭建实例
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5547565.aspx
------------------------------------------------------------------------------
Blog:http://blog.csdn.net/tianlesoftware
网上资源:http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
DBA1群:62697716(满);DBA2群:62697977
DBA3群:63306533;聊天群:40132017