实验课题:备库数据库重启后,自动开启实时应用.
主备库系统:CentOS 7.9
主备库数据库:oracle 11.2.0.4
实例名:orcl150(主),orcl151(备)
1、 部署触发器
在主库端部署触发器.
SQL> create or replace trigger dg_apply_log
after startup on database
begin
declare
database_role varchar(20);
begin
select database_role
into database_role
from v$database;
/* dbms_output.put_line('aa');*/
if database_role = 'PHYSICAL STANDBY'
then
execute immediate 'alter database recover managed standby database using current logfile disconnect from session';
dbms_output.put_line('bb');
else
dbms_output.put_line(database_role);
end if;
end;
end dg_apply_log;
/
说明:通过视图all_triggers可以查询创建的触发器.
2、备库测试
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 2455228416 bytes
Fixed Size 2255712 bytes
Variable Size 620758176 bytes
Database Buffers 1811939328 bytes
Redo Buffers 20275200 bytes
Database mounted.
Database opened.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
备库日志记录:
Completed: ALTER DATABASE MOUNT
ALTER DATABASE OPEN
AUDIT_TRAIL initialization parameter is changed to OS, as DB is NOT compatible for database opened with read-only access
SMON: enabling cache recovery
Dictionary check beginning
Dictionary check complete
Database Characterset is WE8MSWIN1252
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Physical standby database opened for read only access.
alter database recover managed standby database using current logfile disconnect from session
Attempt to start background Managed Standby Recovery process (orcl151)
MRP0 started with pid=25, OS id=59478
MRP0: Background Managed Standby Recovery process started (orcl151)
db_recovery_file_dest_size of 4182 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
2022-08-23 10:52:23.039000 +08:00
ARC3: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
Using STANDBY_ARCHIVE_DEST parameter default value as /u01/app/oracle/fast_recovery_area/archivelog
2022-08-23 10:52:24.798000 +08:00
RFS[1]: Assigned to RFS process 59484
RFS[1]: Selected log 12 for thread 1 sequence 35 dbid -244204776 branch 1101942938
Archived Log entry 8 added for thread 1 sequence 35 ID 0xf1722e18 dest 1:
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: Assigned to RFS process 59486
RFS[2]: Selected log 11 for thread 1 sequence 36 dbid -244204776 branch 1101942938
2022-08-23 10:52:27.201000 +08:00
started logmerger process
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 4 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log /u01/app/oracle/fast_recovery_area/archivelog1_35_1101942938.dbf
Media Recovery Waiting for thread 1 sequence 36 (in transit)
Recovery of Online Redo Log: Thread 1 Group 11 Seq 36 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/orcl151/redo11_standby.log
Completed: alter database recover managed standby database using current logfile disconnect from session
Completed: ALTER DATABASE OPEN
以上主库的触发器会在重启备库的时候会被触发,数据库的自动重启可以做如下设置:
a、备库OS如果为windows,则可以选择服务自动启动.
b、如果备库OS为Linux,则可以通过书写脚本部署定时任务,对数据库进行启动操作.
c、如果备库使用了GI,则GI会随着操作系统的启动数据库.