Oracle11g Data Guard物理备用数据库搭建与配置(第2部分 配置物理备用数据库)

前端之家收集整理的这篇文章主要介绍了Oracle11g Data Guard物理备用数据库搭建与配置(第2部分 配置物理备用数据库)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

环境准备

接着上一篇文章 Oracle11g Data Guard物理备用数据库搭建与配置(第1部分 主数据库实例创建)


在我的测试环境中,我准备了两台CentOS7.4虚拟机,并同时都安装了Oracle11gR211.2.0.1.0企业版的数据库软件,其中只有主服务器创建一个数据库实例,备用服务器仅安装Oracle数据库软件。

数据库:

OS: CentOS7.4

Hostname: hmdb11dg-db1

Oracle Version: 11.2.0.1.0

Oracle SID: HMDG(使用DBCA工具创建的一个数据库)

数据库:

OS: CentOS7.4

Hostname: hmdb11dg-db2

Oracle Version: 11.2.0.1.0

Oracle SID: HMDG2

注意: 在开始之前,备用服务上还没有将要与主服务器同步备份的数据库实例。



一、主服务器前提配置


1. 启用归档日志

检查主数据是否处于归档日志模式

sql>selectlog_modefromv$database;

LOG_MODE
------------
ARCHIVELOG

如果是NOARCHIVELOG模式,则将其修改ARCHIVELOG模式

sql>SHUTDOWNIMMEDIATE;
sql>STARTUPMOUNT;
sql>ALTERDATABASEARCHIVELOG;
sql>ALTERDATABASEOPEN;


2.启用强制日志

sql>ALTERDATABASEFORCELOGGING;

Databasealtered.

sql>SELECTNAME,FORCE_LOGGINGFROMV$DATABASE;

NAMEFOR
------------
HMDGYES


3.创建备用重做日志


备用重做日志文件的大小要与当前主数据库的在线重做日志文件大小完全匹配。

确定备用重做日志文件组的数量,建议的数量(每个线程最大的日志数 + 1) * 最大线程数


查看联机重做日志

sql>setpagesize100
sql>setlinesize200
sql>colGROUP#format99
sql>colSTATUSformata10
sql>colTYPEformata10
sql>colMEMBERformata50
sql>colIS_RECOVERY_DEST_FILEformata10

sql>select*fromv$logfile;

GROUP#STATUSTYPEMEMBERIS_RECOVER
--------------------------------------------------------------------------------------
1ONLINE/u01/app/oracle/oradata/HMDG/redo01.logNO
2ONLINE/u01/app/oracle/oradata/HMDG/redo02.logNO
3ONLINE/u01/app/oracle/oradata/HMDG/redo03.logNO
4ONLINE/u01/app/oracle/oradata/HMDG/redo04.logNO


这里将创建10组备用重做日志

ALTERDATABASEADDSTANDBYLOGFILEGROUP5'/u01/app/oracle/oradata/HMDG/redo05.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP6'/u01/app/oracle/oradata/HMDG/redo06.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP7'/u01/app/oracle/oradata/HMDG/redo07.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP8'/u01/app/oracle/oradata/HMDG/redo08.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP9'/u01/app/oracle/oradata/HMDG/redo09.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP10'/u01/app/oracle/oradata/HMDG/redo10.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP11'/u01/app/oracle/oradata/HMDG/redo11.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP12'/u01/app/oracle/oradata/HMDG/redo12.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP13'/u01/app/oracle/oradata/HMDG/redo13.log'SIZE500M;
ALTERDATABASEADDSTANDBYLOGFILEGROUP14'/u01/app/oracle/oradata/HMDG/redo14.log'SIZE500M;


查看备用重做日志

sql>SELECTGROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUSFROMV$STANDBY_LOG;

GROUP#THREAD#SEQUENCE#ARCSTATUS
---------------------------------------
500YESUNASSIGNED
600YESUNASSIGNED
700YESUNASSIGNED
800YESUNASSIGNED
900YESUNASSIGNED
1000YESUNASSIGNED
1100YESUNASSIGNED
1200YESUNASSIGNED
1300YESUNASSIGNED
1400YESUNASSIGNED

10rowsselected.



4. 开启闪回日志

sql>alterdatabaseflashbackon;
sql>selectflashback_onfromv$database;

FLASHBACK_ON
------------------
YES



二、监听与TNS配置


1.监听配置

主备数据库必须注册静态监听服务(listener.ora)

$cat/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora

LISTENER=
(DESCRIPTION_LIST=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=hmdb11dg-db1)(PORT=1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=HMDG.DB)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME=HMDG)
)
)

ADR_BASE_LISTENER=/u01/app/oracle


#备数据库
LISTENER=
(DESCRIPTION_LIST=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=hmdb11dg-db2)(PORT=1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=HMDG2.DB)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME=HMDG2)
)
)

ADR_BASE_LISTENER=/u01/app/oracle



2. 主备数据库TNS别名连接信息配置

修改两台服务器上的$ORACLE_HOME/network/admin/tnsnames.ora配置文件,主备使用相同的配置

HMDG=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=hmdb11dg-db1)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=HMDG.DB)
)
)

HMDG2=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=hmdb11dg-db2)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=HMDG2.DB)
)
)


3. 测试使用TNS别名连接数据库

[oracle@hmdb11dg-db1~]$sqlplussystem/oracle@HMDG

sql*Plus:Release11.2.0.1.0ProductiononThuMar2220:47:282018

Copyright(c)1982,2009,Oracle.Allrightsreserved.


Connectedto:
OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bitProduction
WiththePartitioning,OLAP,DataMiningandRealApplicationTestingoptions

sql>


三、主数据库初始化参数配置


1. 创建PFILE参数文件

使用如下语句创建PFILE配置文件,该文件自动生成/u01/app/oracle/product/11.2.0/db_1/dbs目录下

sql>CREATEPFILEFROMSPFILE;


2. 修改PFILE配置

使用刚刚生成PFILE文件修改如下配置

HMDG.__db_cache_size=1023410176
HMDG.__java_pool_size=16777216
HMDG.__large_pool_size=16777216
HMDG.__oracle_base='/u01/app/oracle'#ORACLE_BASEsetfromenvironment
HMDG.__pga_aggregate_target=1325400064
HMDG.__sga_target=1962934272
HMDG.__shared_io_pool_size=0
HMDG.__shared_pool_size=872415232
HMDG.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/HMDG/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/HMDG/control01.ctl','/u01/app/oracle/flash_recovery_area/HMDG/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='HMDG'

*.db_unique_name='HMDG'
*.log_archive_config='DG_CONFIG=(HMDG,HMDG2)'

LOG_ARCHIVE_DEST_1=
'LOCATION=/u01/app/oracle/oradata/HMDG/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=HMDG'

LOG_ARCHIVE_DEST_2=
'SERVICE=HMDG2ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=HMDG2'

LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
LOG_ARCHIVE_MAX_PROCESSES=30

FAL_SERVER=HMDG2
FAL_CLIENT=HMDG
DB_FILE_NAME_CONVERT='HMDG2','HMDG'
LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/HMDG2/','/u01/app/oracle/oradata/HMDG/'
STANDBY_FILE_MANAGEMENT=AUTO

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=21474836480
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP)(SERVICE=HMDGXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=3277848576
*.open_cursors=300
*.processes=5000
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=5505
*.undo_tablespace='UNDOTBS1'


3. 使用刚刚创建的PFILE文件重新启动数据库,并且重新创建一个SPFILE文件

sql>shutdownimmediate
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
sql>startuppfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initHMDG.ora';
ORACLEinstancestarted.

TotalSystemGlobalArea3273641984bytes
FixedSize2217792bytes
VariableSize2315258048bytes
DatabaseBuffers939524096bytes
RedoBuffers16642048bytes
Databasemounted.
DatabaSEOpened.
sql>createspfilefrompfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initHMDG.ora';#创建SPFILE文件

Filecreated.

sql>shutdownimmediate
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
sql>startup
ORACLEinstancestarted.

TotalSystemGlobalArea3273641984bytes
FixedSize2217792bytes
VariableSize2315258048bytes
DatabaseBuffers939524096bytes
RedoBuffers16642048bytes
Databasemounted.
DatabaSEOpened.


注意:一旦由于PFILE参数配置信息错误或者使用PFILE文件启动报错需要修改PFILE文件参数的时候,都必须要重新创建SPFILE文件(主备数据库都是一样)


4. 备份数据库(在这里是非必须的,因为在本次操作中我使用的是RMAN复制到备用数据库)

[oracle@hmdb11dg-db1dbs]$rmantarget=/

RecoveryManager:Release11.2.0.1.0-ProductiononThuMar2221:12:062018

Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved.

connectedtotargetdatabase:HMDG(DBID=787192145)

RMAN>BACKUPDATABASEPLUSARCHIVELOG;


5. 创建备用数据库控制文件

sql>ALTERDATABASECREATESTANDBYCONTROLFILEAS'/tmp/HMDG2.ctl';


6. 创建备用数据库PFILE文件

sql>CREATEPFILE='/tmp/initHMDG2.ora'FROMSPFILE;


7. 创建备用数据的密码文件

[oracle@hmdb11dg-db1~]$cp/u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMDG/tmp/orapwHMDG2



四、备用数据库服务器设置


1.备用数据库上创建必要的数据库文件目录

$mkdir/u01/app/oracle/admin
$mkdir/u01/app/oracle/admin/HMDG2
$mkdir/u01/app/oracle/admin/HMDG2/{adump,dpdump,pfile,scripts}
$mkdir-p/u01/app/oracle/oradata/HMDG2
$mkdir-p/u01/app/oracle/flash_recovery_area/HMDG2


2. 从主数据库上拷贝配置文件到备用数据库(备用服务器上操作)


将控制文件、参数文件和密码文件从主服务器上复制到备用服务器上

$scporacle@hmdb11dg-db1:/tmp/HMDG2.ctl/u01/app/oracle/oradata/HMDG2/control01.ctl
$cp/u01/app/oracle/oradata/HMDG2/control01.ctl/u01/app/oracle/flash_recovery_area/HMDG2/control02.ctl
$scporacle@hmdb11dg-db1:/tmp/orapwHMDG2/u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMDG2
$scporacle@hmdb11dg-db1:/tmp/initHMDG2.ora/u01/app/oracle/product/11.2.0/db_1/dbs/initHMDG2.ora


3. 修改备用数据库初始化参数


修改备用服务器的PFILE文件$ORACLE_HOME/dbs/initHMDG2.ora

HMDG.__db_cache_size=939524096
HMDG.__java_pool_size=16777216
HMDG.__large_pool_size=16777216
HMDG.__oracle_base='/u01/app/oracle'#ORACLE_BASEsetfromenvironment
HMDG.__pga_aggregate_target=1325400064
HMDG.__sga_target=1962934272
HMDG.__shared_io_pool_size=0
HMDG.__shared_pool_size=956301312
HMDG.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/HMDG2/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/HMDG2/control01.ctl','/u01/app/oracle/flash_recovery_area/HMDG2/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.DB_FILE_NAME_CONVERT='HMDG','HMDG2'
*.db_name='HMDG'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=21474836480
*.db_unique_name='HMDG2'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP)(SERVICE=HMDGXDB)'
*.FAL_CLIENT='HMDG2'
*.FAL_SERVER='HMDG'
*.log_archive_config='DG_CONFIG=(HMDG,HMDG2)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/HMDG2/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=HMDG2'
*.LOG_ARCHIVE_DEST_2='SERVICE=HMDGASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=HMDG'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/HMDG/','/u01/app/oracle/oradata/HMDG2/'
*.memory_target=3277848576
*.open_cursors=300
*.processes=5000
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=5505
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.undo_tablespace='UNDOTBS1'



4. 使用刚刚创建的PFILE参数文件启动备用数据库

[oracle@hmdb11dg-db2~]$sqlplus/assysdba

sql*Plus:Release11.2.0.1.0ProductiononThuMar2221:42:242018

Copyright(c)1982,Oracle.Allrightsreserved.

Connectedtoanidleinstance.

sql>STARTUPNOMOUNTPFILE='/u01/app/oracle/product/11.2.0/db_1/dbs/initHMDG2.ora';
ORACLEinstancestarted.

TotalSystemGlobalArea3273641984bytes
FixedSize2217792bytes
VariableSize2197817536bytes
DatabaseBuffers1056964608bytes
RedoBuffers16642048bytes


5. 创建SPFILE文件

sql>CREATESPFILEFROMPFILE;

Filecreated.

注意:一旦由于PFILE参数配置信息错误或者使用PFILE文件启动报错需要修改PFILE文件参数的时候,都必须要重新使用该语句创建SPFILE文件(主备数据库都是一样)



五、在备用数据库上使用rman恢复数据到备用数据库(DUPLICATE)


1. 建立连接

[oracle@hmdb11dg-db2~]$rmanTARGETsys/oracle@HMDGAUXILIARYsys/oracle@HMDG2

RecoveryManager:Release11.2.0.1.0-ProductiononThuMar2221:46:422018

Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved.

connectedtotargetdatabase:HMDG(DBID=787192145)
connectedtoauxiliarydatabase:HMDG(notmounted)


2. 将主数据库复制到备用数据库


RMAN模式下,发出以下语句将主数据库复制到备数据库

DUPLICATETARGETDATABASEFORSTANDBYFROMACTIVEDATABASE;


[oracle@hmdb11dg-db2 dbs]$ rman TARGET sys/oracle@HMDG AUXILIARY sys/oracle@HMDG2

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Mar 23 09:50:19 2018

Copyright (c) 1982,Oracle and/or its affiliates. All rights reserved.

connected to target database: HMDG (DBID=787214401)

connected to auxiliary database: HMDG (not mounted)

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE;

Starting Duplicate Db at 23-MAR-18

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=4708 device type=DISK

contents of Memory Script:

{

backup as copy reuse

targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMDG' auxiliary format

'/u01/app/oracle/product/11.2.0/db_1/dbs/orapwHMDG2' ;

}

executing Memory Script

Starting backup at 23-MAR-18

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=3773 device type=DISK

Finished backup at 23-MAR-18

contents of Memory Script:

{

backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/HMDG2/control01.ctl';

restore clone controlfile to '/u01/app/oracle/flash_recovery_area/HMDG2/control02.ctl' from

'/u01/app/oracle/oradata/HMDG2/control01.ctl';

}

executing Memory Script

Starting backup at 23-MAR-18

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

copying standby control file

output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_HMDG.f tag=TAG20180323T095223 RECID=3 STAMP=971517146

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:15

Finished backup at 23-MAR-18

Starting restore at 23-MAR-18

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: copied control file copy

Finished restore at 23-MAR-18

contents of Memory Script:

{

sql clone 'alter database mount standby database';

}

executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:

{

set newname for tempfile 1 to

"/u01/app/oracle/oradata/HMDG2/temp01.dbf";

switch clone tempfile all;

set newname for datafile 1 to

"/u01/app/oracle/oradata/HMDG2/system01.dbf";

set newname for datafile 2 to

"/u01/app/oracle/oradata/HMDG2/sysaux01.dbf";

set newname for datafile 3 to

"/u01/app/oracle/oradata/HMDG2/undotbs01.dbf";

set newname for datafile 4 to

"/u01/app/oracle/oradata/HMDG2/users01.dbf";

backup as copy reuse

datafile 1 auxiliary format

"/u01/app/oracle/oradata/HMDG2/system01.dbf" datafile

2 auxiliary format

"/u01/app/oracle/oradata/HMDG2/sysaux01.dbf" datafile

3 auxiliary format

"/u01/app/oracle/oradata/HMDG2/undotbs01.dbf" datafile

4 auxiliary format

"/u01/app/oracle/oradata/HMDG2/users01.dbf" ;

sql 'alter system archive log current';

}

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/HMDG2/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 23-MAR-18

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/HMDG/undotbs01.dbf

output file name=/u01/app/oracle/oradata/HMDG2/undotbs01.dbf tag=TAG20180323T095246

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:15

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u01/app/oracle/oradata/HMDG/system01.dbf

output file name=/u01/app/oracle/oradata/HMDG2/system01.dbf tag=TAG20180323T095246

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:35

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/HMDG/sysaux01.dbf

output file name=/u01/app/oracle/oradata/HMDG2/sysaux01.dbf tag=TAG20180323T095246

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/HMDG/users01.dbf

output file name=/u01/app/oracle/oradata/HMDG2/users01.dbf tag=TAG20180323T095246

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:15

Finished backup at 23-MAR-18

sql statement: alter system archive log current

contents of Memory Script:

{

switch clone datafile all;

}

executing Memory Script

datafile 1 switched to datafile copy

input datafile copy RECID=3 STAMP=971517318 file name=/u01/app/oracle/oradata/HMDG2/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=4 STAMP=971517318 file name=/u01/app/oracle/oradata/HMDG2/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=5 STAMP=971517318 file name=/u01/app/oracle/oradata/HMDG2/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=6 STAMP=971517319 file name=/u01/app/oracle/oradata/HMDG2/users01.dbf

Finished Duplicate Db at 23-MAR-18


如果复制过程中没有报错,就可以立即开启日志重做应用


3. 开启日志重做应用

发出如下命令指示备库开始使用备用日志进行在备库上同步数据(恢复数据)

sql>ALTERDATABASERECOVERMANAGEDSTANDBYDATABASEDISCONNECTFROMSESSION;
#或者
sql>ALTERDATABASERECOVERMANAGEDSTANDBYDATABASEUSINGCURRENTLOGFILEDISCONNECTFROMSESSION;

#取消申请重做(该命令用于停止恢复)
sql>ALTERDATABASERECOVERMANAGEDSTANDBYDATABASECANCEL;


4.测试备用数据的存档操作

默认情况下,当在线重做日志文件变满时,会发送日志切换。要强制进行日志切换以便立即传输重做数据,则在主数据库上使用如下语句强制日志切换

sql>ALTERSYSTEMSWITCHLOGFILE;

Systemaltered.


5.在备用数据库查询现有的归档重做日志文件

sql>SELECTSEQUENCE#,FIRST_TIME,NEXT_TIMEFROMV$ARCHIVED_logoRDERBYSEQUENCE#;

SEQUENCE#FIRST_TIMNEXT_TIME
----------------------------
1923-MAR-1823-MAR-18
2023-MAR-1823-MAR-18
2123-MAR-1823-MAR-18
2223-MAR-1823-MAR-18


6.再次在数据库上强制日志切换

sql>ALTERSYSTEMSWITCHLOGFILE;

Systemaltered.


7.验证在备用数据库中是否接收了新的重做日志

sql>SELECTSEQUENCE#,NEXT_TIMEFROMV$ARCHIVED_logoRDERBYSEQUENCE#;

SEQUENCE#FIRST_TIMNEXT_TIME
----------------------------
1923-MAR-1823-MAR-18
2023-MAR-1823-MAR-18
2123-MAR-1823-MAR-18
2223-MAR-1823-MAR-18
2323-MAR-1823-MAR-18


8. 验证备用数据库是否应用了新的重做日志

sql>SELECTSEQUENCE#,APPLIEDFROMV$ARCHIVED_logoRDERBYSEQUENCE#;

SEQUENCE#APPLIED
-------------------
19YES
20YES
21YES
22YES
23YES


9.查询主备状态

#在当前主数据库查询
sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
TOSTANDBY

#在当前备用数据库查询
sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
NOTALLOWED

此时,说明当前主备数据库状态都为正常。其中主数据状态TO STANDBY说明可以随时切换为备用数据库


五、手动切换测试(主备切换)


在主数据库(DB1)上操作


在当前主数据库查询主备状态

sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
TOSTANDBY

当主数据库的状态为TO STANDBY时,表示可以切换到备用数据库


在当前主数据库(DB1)上发出切换到备数据库角色申请

sql>ALTERDATABASECOMMITTOSWITCHOVERTOPHYSICALSTANDBYWITHSESSIONSHUTDOWN;

Databasealtered.



在备数据库(DB2)上操作


此时查看备数据库(DB2)的状态

sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
TOPRIMARY

当此时备数据库的状态为TO PRIMARY时,表示可以切换到主数据库角色


在当前备数据库(DB2)上发出切换到主数据库角色申请

sql>ALTERDATABASECOMMITTOSWITCHOVERTOPRIMARYWITHSESSIONSHUTDOWN;

Databasealtered.


继续在备数据(DB2)上完成以下指令

sql>ALTERDATABASEOPEN;
--或者
sql>SHUTDOWNIMMEDIATE;
sql>STARTUP;


在原来的主数据(DB1)上继续执行以下命令

sql>SHUTDOWNIMMEDIATE;
ORA-01507:databasenotmounted


ORACLEinstanceshutdown.
sql>STARTUPNOMOUNT;
ORACLEinstancestarted.

TotalSystemGlobalArea3273641984bytes
FixedSize2217792bytes
VariableSize2264926400bytes
DatabaseBuffers989855744bytes
RedoBuffers16642048bytes
sql>ALTERDATABASEMOUNTSTANDBYDATABASE;

Databasealtered.

发出如下命令让当前备库(DB1)开始使用备用日志进行同步数据(恢复数据)

sql>ALTERDATABASERECOVERMANAGEDSTANDBYDATABASEUSINGCURRENTLOGFILEDISCONNECTFROMSESSION;

Databasealtered.


最后查看切换以后的主备状态与主备角色


--DB2上
sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
TOSTANDBY

sql>selectdatabase_rolefromv$database;

DATABASE_ROLE
----------------
PHYSICALSTANDBY

--DB1上
sql>SELECTSWITCHOVER_STATUSFROMV$DATABASE;

SWITCHOVER_STATUS
--------------------
NOTALLOWED

sql>selectdatabase_rolefromv$database;

DATABASE_ROLE
----------------
PRIMARY

以上状态说明主备角色已经正常切换


注意:在正常切换后,主数据库状态可能需要等待几分钟时间才显示TO STANDBY状态,这是因为主数据在执行日志切换,需要等待切换完成


在当前主数据库(DB2)上强制日志切换

sql>ALTERSYSTEMSWITCHLOGFILE;

Systemaltered.

至此主备切换测试完成

猜你在找的Oracle相关文章