系统:redhat4
三台计算机rac1,rac2,dg.
--其中rac为主库,单实例为备库
已在虚拟机里搭建好集群环境(rac1,rac2);
dg计算机里还没有建任何数据库(只安装Oracle软件)。
二:实验步骤单实例环境部署请参考文档‘linux下安装Oracle10g(redhat4)’。
3.1:enableforcedlogging--将主库设为强制归档
SQL>selectforce_loggingfromv$database;
FOR
---
NO
SQL>alterdatabaseforcelogging;
Databasealtered.
SQL>selectforce_loggingfromv$database;
FOR
---
YES
3.2:创建密码文件在rac的两个节点上执行:
SQL>alterusersysidentifiedbyoracle;
Useraltered.
建密码文件:
cd/u01/app/oracle/PRoduct/10.2.0/db_1/dbs--注意,一定要在该路径下建密码文件
[oracle@rac1dbs]$orapwdfile=orapwprod1passWord=oracleentries=3force=y
[oracle@rac2dbs]$orapwdfile=orapwprod2password=oracleentries=3force=y
在备库上建密码文件
cd/u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@dgdbs]$orapwdfile=orapwsdyprodpassword=oracleentries=3
3.3:configureastandbyredolog在任意一个节点上查询日志情况:
SQL>selectgroup#,thread#,sequence#,bytes/1024/1024mb
2fromv$log;
GROUP#THREAD#SEQUENCE# MB
----------------------------------------
1 1 4 50
2 1 5 50
3 2 3 50
4 2 4 50
SQL>selectmemberfromv$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATA/prod/onlinelog/group_2.262.856078815
+REDOLOG/prod/onlinelog/group_2.258.856078819
+DATA/prod/onlinelog/group_1.261.856078807
+REDOLOG/prod/onlinelog/group_1.257.856078813
+DATA/prod/onlinelog/group_3.266.856079013
+REDOLOG/prod/onlinelog/group_3.259.856079015
+DATA/prod/onlinelog/group_4.267.856079017
+REDOLOG/prod/onlinelog/group_4.260.856079019
8rowsselected.
用下面这个公式决定standbyredologfilegroup的数量:
(每个节点日志组最大数+1)*节点数量
比如,这里每个节点都有两组日志,有两个节点,因此需要配置(2+1)*2=6组standbyredologfilegroup.
建立standbyredolog;
SQL>alterdatabaseaddstandbylogfilethread1group5'+DATA'size50m;
Databasealtered.
SQL>alterdatabaseaddstandbylogfilethread1group6'+DATA'size50m;
Databasealtered.
SQL>alterdatabaseaddstandbylogfilethread1group7'+DATA'size50m;
Databasealtered
SQL>alterdatabaseaddstandbylogfilethread2group8'+DATA'size50m;
Databasealtered.
SQL>alterdatabaseaddstandbylogfilethread2group9'+DATA'size50m;
Databasealtered.
SQL>alterdatabaseaddstandbylogfilethread2group10'+DATA'size50m;
Databasealtered.
在两个节点上都查看一下建的standbylogfile:
SQL>selectgroup#,thread#,status
2fromv$standby_log;
GROUP#THREAD#STATUS
------------------------------
51UNASSIGNED
61UNASSIGNED
71UNASSIGNED
82UNASSIGNED
92UNASSIGNED
102UNASSIGNED
6rowsselected.
3.4:SetPrimaryDatabaseInitializationParameters在rac1节点上创建pfile(由于它原本Pfile内容只有SPFILE='+DG1/prod/spfileprod.ora'这一句)
SQL>createpfile='/home/oracle/initprod1.ora'fromspfile;
Filecreated.
viinitprod.ora
添加如下内容:
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,sdyprod)'
LOG_ARCHIVE_DEST_1=
'LOCATION=+DATA/prod
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=prod'
LOG_ARCHIVE_DEST_2=
'SERVICE=sdyprodLGWRASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=sdyprod'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=3
FAL_SERVER=sdyprod
prod1.FAL_CLIENT=prod1
prod2.FAL_CLIENT=prod2
DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/sdyprod/','+DATA/prod/datafile/','/u01/app/oracle/oradata/sdyprod/','+DATA/prod/tempfile/'
LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/sdyprod/','+DATA/prod/onlinelog/','/u01/app/oracle/oradata/sdyprod/','+REDOLOG/prod/onlinelog/'
STANDBY_FILE_MANAGEMENT=AUTO
看以该pfile文件能否登陆成功,并创建spfile(rac里建spfile时,不指定位置的话,会默认放在本地磁盘上)
SQL>startupforcenomountpfile='/home/oracle/initprod1.ora';
ORACLEinstancestarted.
TotalSystemGlobalArea285212672bytes
FixedSize1218992bytes
VariableSize92276304bytes
DatabaseBuffers188743680bytes
RedoBuffers2973696bytes
SQL>createspfile='+DATA/prod/spfileprod.ora'frompfile='/home/oracle/initprod1.ora';
Filecreated
在打开rac1之前,先把rac2的实例关掉,因为现在spfile已经改变了。
在rac2上:shutdownimmediate;
在rac1上:startupforce;
在rac2上:startup;
/*
若rac2的库没关,rac1以修改后的spfile启动,会报错:
SQL>startupforce;
ORACLEinstancestarted.
TotalSystemGlobalArea285212672bytes
FixedSize1218992bytes
VariableSize92276304bytes
DatabaseBuffers188743680bytes
RedoBuffers2973696bytes
ORA-01105:mountisincompatiblewithmountsbyotherinstances
ORA-01677:standbyfilenameconvertparametersdifferfromotherinstance
*/
3.5:enablearchiving--若已经归档,这步可以隔过去了
3.6:CreateaBackupCopyofthePrimaryDatabaseDatafiles(由于是rac环境,只能用rman备份了)
在rac1下做一个热备份(由于rac默认备份放在ASM下,所以这里备份需要手工指定位置):
RMAN>run{
2>allocatechannelc1typedisk;
3>allocatechannelc2typedisk;
4>backupfulldatabaseformat'/home/oracle/backup/%d_%s.bak';
5>}
--在rac1下的/home/oracle/backup可以看到备份集,rac2下的/home/oracle/backup下看不到。
3.7:createacontrolfileforthestandbydatabase--在任意一个节点上皆可
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
SQL>startupmount;
ORACLEinstancestarted.
TotalSystemGlobalArea285212672bytes
FixedSize1218992bytes
VariableSize96470608bytes
DatabaseBuffers184549376bytes
RedoBuffers2973696bytes
Databasemounted.
SQL>alterdatabasecreatestandbycontrolfileas'/home/oracle/sdyprod_control01.ctl';
Databasealtered.
SQL>alterdatabaSEOpen;
Databasealtered.
3.8:PrepareanInitializationParameterFilefortheStandbyDatabase将rac1下建的初始化参数文件远程拷贝到备库192.168.8.225上:
[oracle@rac1~]$
scpinitprod1.ora192.168.8.225:/u01/app/oracle/product/10.2.0/db_1/dbs/initsdyprod.ora
Theauthenticityofhost'192.168.8.225(192.168.8.225)'can'tbeestablished.
RSAkeyfingerprintis6d:1d:6b:1a:34:63:f2:f4:4c:15:0d:eb:60:e0:13:4d.
Areyousureyouwanttocontinueconnecting(yes/no)?yes
Warning:Permanentlyadded'192.168.8.225'(RSA)tothelistofknownhosts.
oracle@192.168.8.225'spassword:
initprod1.ora100%22142.2KB/s00:00
拷贝过来的initprod1.ora文件内容:
prod1.__db_cache_size=163577856
prod2.__db_cache_size=155189248
prod1.__java_pool_size=4194304
prod2.__java_pool_size=4194304
prod1.__large_pool_size=4194304
prod2.__large_pool_size=4194304
prod1.__shared_pool_size=109051904
prod2.__shared_pool_size=117440512
prod1.__streams_pool_size=0
prod2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/prod/adump'
*.background_dump_dest='/u01/app/oracle/admin/prod/bdump'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='+DATA/prod/controlfile/current.260.856078805','+REDOLOG/prod/controlfile/current.256.856078805'
*.core_dump_dest='/u01/app/oracle/admin/prod/cdump'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='prod'
*.db_recovery_file_dest='+REDOLOG'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP)(SERVICE=prodXDB)'
prod1.instance_number=1
prod2.instance_number=2
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=+DATA/prod'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_listener='LISTENERS_PROD'
*.remote_login_passwordfile='exclusive'
*.sga_target=285212672
prod2.thread=2
prod1.thread=1
*.undo_management='AUTO'
prod2.undo_tablespace='UNDOTBS2'
prod1.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/prod/udump'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,sdyprod)'
LOG_ARCHIVE_DEST_1=
'LOCATION=+DATA/prod/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=prod'
LOG_ARCHIVE_DEST_2=
'SERVICE=sdyprodLGWRASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=sdyprod'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=3
FAL_SERVER=sdyprod
prod1.FAL_CLIENT=prod1
prod2.FAL_CLIENT=prod2
DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/sdyprod/','+DATA/prod/datafile/','/u01/app/oracle/oradata/sdyprod/','+DATA/prod/tempfile/'
LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/sdyprod/','+DATA/prod/onlinelog/','/u01/app/oracle/oradata/sdyprod/','+REDOLOG/prod/onlinelog/'
STANDBY_FILE_MANAGEMENT=AUTO
相对于修改前的参数文件,修改后的initsdyprod.ora如下(改动的地方已用黄色阴影标出):
prod1.__db_cache_size=163577856
prod2.__db_cache_size=155189248
prod1.__java_pool_size=4194304
prod2.__java_pool_size=4194304
prod1.__large_pool_size=4194304
prod2.__large_pool_size=4194304
prod1.__shared_pool_size=109051904
prod2.__shared_pool_size=117440512
prod1.__streams_pool_size=0
prod2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/sdyprod/adump'
*.background_dump_dest='/u01/app/oracle/admin/sdyprod/bdump'
#*.cluster_database_instances=2
#*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/admin/sdyprod/sdyprod_control01.ctl'
*.core_dump_dest='/u01/app/oracle/admin/sdyprod/cdump'
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='prod'
*.db_recovery_file_dest=''
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP)(SERVICE=prodXDB)'
prod.instance_number=1
*.job_queue_processes=10
#*.log_archive_dest_1='LOCATION=+DATA/prod'
#*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_listener='LISTENERS_PROD'
*.remote_login_passwordfile='exclusive'
*.sga_target=285212672
sdyprod.thread=1
*.undo_management='AUTO'
sdyprod.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/sdyprod/udump'
db_unique_name=sdyprod
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,sdyprod)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/arch/sdyprod
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=sdyprod'
LOG_ARCHIVE_DEST_2=
'SERVICE=prodLGWRASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=prod'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=3
FAL_SERVER=prod
FAL_CLIENT=sdyprod
DB_FILE_NAME_CONVERT='+DATA/prod/datafile/','/u01/app/oracle/oradata/sdyprod/','+DATA/prod/tempfile/','/u01/app/oracle/oradata/sdyprod/'
LOG_FILE_NAME_CONVERT='+DATA/prod/onlinelog/','/u01/app/oracle/oradata/sdyprod/','+REDOLOG/prod/onlinelog/','/u01/app/oracle/oradata/sdyprod/'
STANDBY_FILE_MANAGEMENT=AUTO
3.9:在备库上建立相关目录--建归档路径:/arch/sdyprod
[root@dg~]#mkdir-p/arch/sdyprod
[root@dg~]#chownoracle:dba/arch/sdyprod
[oracle@dg~]$mkdir-p/u01/app/oracle/admin/sdyprod
[oracle@dg~]$mkdir-p/u01/app/oracle/oradata/sdyprod
[oracle@dgadmin]$cdsdyprod/
[oracle@dgsdyprod]$ls
[oracle@dgsdyprod]$mkdiradumpbdumpcdumpudump
--创建备份文件夹
[oracle@dg~]$cd/home/oracle
[oracle@dg~]$ls
Desktopinitsdyprod.orasoftware
[oracle@dg~]$mkdirbackup
3.10:CopyFilesfromthePrimarySystemtotheStandbySystem(用RMAN方式)[oracle@rac1backup]$scp*.bak192.168.8.225:/home/oracle/backup/
oracle@192.168.8.225'spassword:
PROD_1.bak100%362MB14.5MB/s00:25
PROD_2.bak100%257MB13.5MB/s00:19
PROD_3.bak100%15MB14.6MB/s00:01
PROD_4.bak100%96KB96.0KB/s00:00
[oracle@rac1backup]$cd/home/oracle
[oracle@rac1~]$scPSDyprod_control01.ctl192.168.8.225:/home/oracle/
oracle@192.168.8.225'spassword:
sdyprod_control01.ctl100%15MB7.3MB/s00:02
注意:拷贝的数据文件和控制文件必须得和原来的路径一模一样,否则会出错。
3.11:Configurelistenersfortheprimaryandstandbydatabases--配监听和tnsnames.ora
[oracle@rac1admin]$cd/u01/app/oracle/product/10.2.0/db_1/network/admin
[oracle@rac1admin]$ls
listener.orasamplesshrept.lsttnsnames.ora
在rac1,rac2的tnsnames.ora中添加如下内容:
sdyprod=
(DESCRipTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.8.225)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=sdyprod)
(UR=A)
)
)
在备库192.168.8.225中添加如下内容:
LISTENERS_PROD=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=rac1-vip)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=rac2-vip)(PORT=1521))
)
PROD=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=rac1-vip)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=rac2-vip)(PORT=1521))
(LOAD_BALANCE=yes)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=prod)
)
)
PROD2=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=rac2-vip)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=prod)
(INSTANCE_NAME=prod2)
)
)
PROD1=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=rac1-vip)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=prod)
(INSTANCE_NAME=prod1)
)
)
tnsping一下,看能否Ping通,如以tnspingprod1为例:
看到‘OK’字样,表示ping通了。
在备库lsnrctlstart
lsnrctlstatus
3.12在备库上修改/etc/hosts文件#vi/etc/hosts
#Donotremovethefollowingline,orvariousprograms
#thatrequirenetworkfunctionalitywillfail.
127.0.0.1localhost
192.168.8.225dg
192.168.8.220rac1
192.168.8.222rac1-vip
10.10.10.1rac1-priv
192.168.8.221rac2
192.168.8.223rac2-vip
10.10.10.2rac2-priv
3.13:Createaserverparameterfileforthestandbydatabase--在备库上:
SQL>startupnomount;
ORACLEinstancestarted.
TotalSystemGlobalArea285212672bytes
FixedSize1218992bytes
VariableSize92276304bytes
DatabaseBuffers188743680bytes
RedoBuffers2973696bytes
SQL>createspfilefrompfile;
Filecreated
3.14:在主库恢复数据库-------在主库通过rmanduplicatestandbydb
[oracle@rac1admin]$rmantarget/
RecoveryManager:Release10.2.0.1.0-ProductiononWedDec1207:35:042012
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:PROD(DBID=212879047)
RMAN>connectauxiliarysys/oracle@sdyprod;
connectedtoauxiliarydatabase:PROD(notmounted)
RMAN>duplicatetargetdatabaseforstandby
2>;
StartingDuplicateDbat26-AUG-14
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
contentsofMemoryScript:
{
restoreclonestandbycontrolfile;
sqlclone'alterdatabasemountstandbydatabase';
}
executingMemoryScript
Startingrestoreat26-AUG-14
usingchannelORA_AUX_DISK_1
channelORA_AUX_DISK_1:restoringcontrolfile
channelORA_AUX_DISK_1:copiedcontrolfilecopy
inputfilename=/home/oracle/sdyprod_control01.ctl
outputfilename=/u01/app/oracle/admin/sdyprod/sdyprod_control01.ctl
Finishedrestoreat26-AUG-14
sqlstatement:alterdatabasemountstandbydatabase
releasedchannel:ORA_AUX_DISK_1
contentsofMemoryScript:
{
setnewnamefortempfile1to
"/u01/app/oracle/oradata/sdyprod/temp.263.856078825";
switchclonetempfileall;
setnewnamefordatafile1to
"/u01/app/oracle/oradata/sdyprod/system.256.856078713";
setnewnamefordatafile2to
"/u01/app/oracle/oradata/sdyprod/undotbs1.258.856078719";
setnewnamefordatafile3to
"/u01/app/oracle/oradata/sdyprod/sysaux.257.856078715";
setnewnamefordatafile4to
"/u01/app/oracle/oradata/sdyprod/users.259.856078719";
setnewnamefordatafile5to
"/u01/app/oracle/oradata/sdyprod/example.264.856078831";
setnewnamefordatafile6to
"/u01/app/oracle/oradata/sdyprod/undotbs2.265.856078943";
restore
checkreadonly
clonedatabase
;
}
executingMemoryScript
executingcommand:SETNEWNAME
renamedtemporaryfile1to/u01/app/oracle/oradata/sdyprod/temp.263.856078825incontrolfile
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
Startingrestoreat26-AUG-14
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
skippingdatafile2;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/undotbs1.258.856078719
skippingdatafile3;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/sysaux.257.856078715
skippingdatafile5;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/example.264.856078831
skippingdatafile1;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/system.256.856078713
skippingdatafile4;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/users.259.856078719
skippingdatafile6;alreadyrestoredtofile/u01/app/oracle/oradata/sdyprod/undotbs2.265.856078943
restorenotdone;allfilesreadonly,offline,oralreadyrestored
Finishedrestoreat26-AUG-14
contentsofMemoryScript:
{
switchclonedatafileall;
}
executingMemoryScript
datafile1switchedtodatafilecopy
inputdatafilecopyrecid=4stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/system.256.856078713
datafile2switchedtodatafilecopy
inputdatafilecopyrecid=5stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/undotbs1.258.856078719
datafile3switchedtodatafilecopy
inputdatafilecopyrecid=6stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/sysaux.257.856078715
datafile4switchedtodatafilecopy
inputdatafilecopyrecid=7stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/users.259.856078719
datafile5switchedtodatafilecopy
inputdatafilecopyrecid=8stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/example.264.856078831
datafile6switchedtodatafilecopy
inputdatafilecopyrecid=9stamp=856594930filename=/u01/app/oracle/oradata/sdyprod/undotbs2.265.856078943
FinishedDuplicateDbat26-AUG-14
RMAN>
3.15:在备库上应用日志SQL>alterdatabaserecovermanagedstandbydatabasedisconnectfromsession;
查看报警日志或者v$archived_log,看是否同步归档日志。
在主库上scott用户下的表t插入一条数据:
SQL>insertintotvalues(3);
1rowcreated.
SQL>commit;
Commitcomplete.
在备库上查看一下:
SQL>select*fromt;
select*fromt
*
ERRORatline1:
ORA-01219:databasenotopen:queriesallowedonfixedtables/viewsonly
由于,在readonly下查看,会导致应用日志的延迟,于是决定,在备库切换成主库后再查看。
3.16:角色切换在主库上关掉其他实例,只剩一个实例以切换到备库:
进rac2:
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
进rac1:
SQL>selectswitchover_statusfromv$database;
SWITCHOVER_STATUS
--------------------
SESSIONSACTIVE--表示有活动的会话,需要kill掉
SQL>selectsid,serial#,usernamefromv$sessionwhereusernameisnotnull;
SIDSERIAL#USERNAME
--------------------------------------------------
1248SYS
1313SYS
1329SYS
15117SYS
1529SYS
SQL>selectdistinctsidfromv$mystat;
SID
----------
124
SQL>altersystemkillsession'131,3';
Systemaltered.
SQL>altersystemkillsession'132,9';
Systemaltered.
SQL>altersystemkillsession'151,17';
Systemaltered.
SQL>altersystemkillsession'152,9';
Systemaltered.
SQL>alterdatabasecommittoswitchovertophysicalstandbywithsessionshutdown;
Databasealtered.
SQL>selectstatusfromv$instance;
STATUS
------------
STARTED
SQL>shutdownimmediate;
ORA-01507:databasenotmounted
ORACLEinstanceshutdown.
SQL>startupmount;
ORACLEinstancestarted.
TotalSystemGlobalArea285212672bytes
FixedSize1218992bytes
VariableSize100664912bytes
DatabaseBuffers180355072bytes
RedoBuffers2973696bytes
--必须得先关库,再startupmount,而不是alterdatabasemount;否则报错
Databasemounted.
进备库:
SQL>alterdatabasecommittoswitchovertoprimarywithsessionshutdown;
alterdatabasecommittoswitchovertoprimarywithsessionshutdown
*
ERRORatline1:
ORA-16139:mediarecoveryrequired
SQL>alterdatabaserecovermanagedstandbydatabasedisconnectfromsession;
Databasealtered.
SQL>alterdatabasecommittoswitchovertoprimarywithsessionshutdown;
Databasealtered.
SQL>alterdatabaseopen;
SQL>selectopen_mode
2fromv$database;
OPEN_MODE
----------
READWRITE
SQL>select*
2fromscott.t;
ID
----------
3
1
2
--备库切换为主库后,看到了之前的主库插入的数据3。
--原来的主库(即切换角色后的备库),应用日志:
alter database recover managed standby database disconnect from session
新闻热点
疑难解答