备用服务器的管理模式与只读模式
1.1备库启动到管理恢复模式
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session;
1.2备库启动到只读方式
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database open read only;
1.3从管理恢复模式下到只读模式
SQL>recover managed standby database cancel;
SQL>alter database open read only;
这个时候,可以给数据库增加临时数据文件(这个在热备份的时候是没有备份过来的)如
alter tablespace temp add tempfile '/u02/oradata/BOSS/temp01.dbf' size 100M;
但注意DG模式下文件有两种管理方式(show parameter standby可以查),自动和手动管理,如果是自动管理,是没法做增加和重命名操作的。
例如笔者昨天发的文章中有
SQL> alter database rename file '/bak/datafile/namin_data.dbf' to '/usr/datafile/namin_data.dbf';
alter database rename file '/bak/datafile/namin_data.dbf' to '/usr/datafile/namin_data.dbf'
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01275: Operation RENAME is not allowed if standby file management is
automatic.
上ORACLE查了下,在DG模式下文件有两种管理方式(show parameter standby可以查),自动和手动管理,如果是自动管理,是没法重命名的, 需要改成手动模式。
SQL> show parameter standby
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest string ?/dbs/arch
standby_file_management string AUTO
SQL> alter system set standby_file_management=MANUAL;
System altered.
SQL> show parameter standby
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest string ?/dbs/arch
standby_file_management string MANUAL
SQL> alter database rename file '/bak/datafile/namin_data.dbf' to '/usr/datafile/namin_data.dbf';
Database altered.
1.4从只读方式到管理恢复方式
SQL>recover managed standby database disconnect from session;
打开实时应用功能
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;
1.5查看Data Guard数据库运行在哪种模式下:
在主数据库上:
sql>select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
在备用数据库上:
sql>select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
1.6在备机查看日志序列和被应用的状态
Sql>select sequence#,applied from v$archived_log where applied=’YES’;
1.7查看Data Guard Standby 后台恢复进程是否正常
在备机上:
$ps -ef |grep mrp
输出结果应该有mrp的后台进程
1.8查看主机和备机归档目录
Sql>archive log list;
1.9在备机查看ALERT文件,查看杯恢复的日志序列
$tail -f $ORACLE_BASA/admin/standby /bdump/alert_standby.log
Media Recovery Log /archivelog/invest_arch_log/1_1042_650380049.dbf
Media Recovery Waiting for thread 1 sequence 1043 (in transit)
2主备数据库之间失败切换
2.1在备机查看日志序列和被应用的状态
a)如果在备库有活动的未归档的日志,或者有从主数据库拷贝过来的联机日志,可以采用如下的办法注册并恢复
SQL>ALTER DATABASE REGISTER LOGFILE ‘/home/oracle/archlog/1_87.dbf';
SQL>recover standby database;
2.2在备用数据库执行最后的恢复操作
Sql>alter database recover managed standby database finish;
2.3执行失败切换操作
Sql>alter database commit to switchover to primary;
2.4 重新启动数据库,并成为新的主数据库
Sql>shutdown immediate;
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
Sql>startup;
ORACLE instance started.
Total System Global Area 1610612736 bytes
Fixed Size 2073192 bytes
Variable Size 385879448 bytes
Database Buffers 1207959552 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL>
2.5 为新的主数库生成一个全备份 :
RMAN>connect target /
RMAN> backup database format='/backup/%U_%s.bak';
RMAN> sql "Alter System Archive Log Current";
RMAN> Backup filesperset 10 ArchiveLog all format='/backup/%U_%s.bak';
3强行激活备库 为主库
$sqlpus /nolog
Sql>conn /as sysdba
Sql> alter system archive log current;
Sql>recover managed standby database cancel;
Sql>alter database activate standby database;
Sql>shutdown immediate;
Sql>startup;
$lsnrctl stop
$lsnrctl start
本文转自zylhsy 51CTO博客,原文链接:http://blog.51cto.com/yunlongzheng/579167,如需转载请自行联系原作者