oracle dg 的日常维护
DG 环境重启过程
DataGuard环境的重启原则是:先关主库再关备库,先开备库再开主库
1、关闭DG
1> 关闭主库
SQL>shutdown immediate
$ lsnrctl start
2> 关闭备库
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL>SHUTDOWN IMMEDIATE;
$lsnrctl stop
2、启动DG
1>启动备库
SQL>STARTUP MOUNT/OPEN;
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM
SESSION;
$ lsnrctl start
2>启动主库
SQL> STARTUP;
SQL> exit
$ lsnrctl start
(2)启动DataGuard后的检查
1、检查主备库的归档日志号
在主库执行check:
SQL> archive log list;
在备库执行check
SQL> archive log list;
看到主库备库当前的 Current log sequence 都是1样的,备库上面最新的归档日志applied都是YES,就表明主库备库数据同步1致了
2. 检查备库的归档日志同步情况
在备库执行:
select thread#,sequence#,first_time,next_time,applied from v$archived_log where
applied='YES';
select thread#,sequence#,first_time,next_time,applied from v$archived_log where
applied='NO';
检查主备库之间的日志同步情况,如是是YES表示同步成功的,如果是NO表示没同步同成的日志,
根据主备库与具体时间来确定.
(3)DG物理备库的启动
1、启动到Active DataGuard模式
SQL>STARTUP MOUNT
SQL>ALTER DATABASE OPEN;
SQL>alter database recover managed standby database disconnect from session;
之后你就可以登录备库,并执行查询。你可以执行如下查询确认:
SQL> SELECT name status, database_role, open_mode logins, log_mode FROM
v$instance, v$database;
状态“ READ ONLY WITH APPLY”即表示此时备库处于Read Only状态的同时可以接受
库传过来的日志进行恢复,以便达到备库可以即时查看到主库变化的目的。
2、using current logfile区别
在11g中,如要使用real time apply,需要加using current logfile,使用redo日志恢复备库。
在12c中,如果要不使用real time apply,需要加using archived log,using current logfile 已经废弃。
不带using语句,在11g中,默认是不使用real time apply,而在12c中是默认使用real time apply
3、启动备库real-time apply
SQL> alter database recover managed standby database cancel;
Database altered.
SQL>ALTER DATABASE OPEN;
Database altered.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
4、备库取消数据恢复
SQL> alter database recover managed standby database cancel
(一)DG 备份和归档
DG主备份主库,备库不需要备份
//修改参数:备用没应用日志主库不允许删除
CONFIGURE ARCHIVELOG DELETION POLICY TO applied on all standby;
删除归档脚本:
run{
allocate channel d1 type disk;
delete noprompt archivelog all completed before 'sysdate-7';
delete noprompt obsolete;
release channel d1;
}
(二)检查并解决 redo gap
1、gap产生原因
当redo data传送发生中断就会产生redo gap。当redo data传送恢复正常以后,redo transport service 会自动检测redo gap并发送缺失的redo到 destination
当网络不好的时候,有两个参数可以提高传送速度:
1> redo transport compression
redo data压缩传输,在log_archive_dest_n中设置,会消耗CPU资源
2>parallel redo transport network sessions
max_connections属性也是在log_archive_dest_n中设置,可以指定多个sessionl来同时发送redo data .
2、手工解决解决物理standby gap问题
1>备库查看是否存在gap:
select * from v$archive_gap;
2>到主库查询,确认1下:
select name from v$archived_log where thread#= ? and sequence# between ? and ?;
(?用上面查出来结果填充.)
3>手工注册归档
把查出来的归档 COPY到备库,并使用alter database register logfile应用这些归档:
alter database register logfile '/oracle/arch01/1_1871_913856999.dbf';
3、手工解决逻辑standby gap问题
select thread#,sequence#,file_name from dba_logstdby_log l where next_change# not in
(select first_change# from dba_logstdby_log where l.thread# = thread#) order by thread#,sequence#;
copy 缺失的log file 到 logical standby database,然后注册:
alter database register logical logfile '/oracle/arch01/1_1871_913856999.dbf';