激活dg库,供开发测试使用。
----1, 确认备库已关闭job参数: job_queue_processes=0,一定要设成0!!
----2, 主库不用做操作。
----3, 激活备库后,备库成了一个独立的可读写库,与主库无关联。
----4, 主库暂时修改log_archive_stat_2=defer.
----5, 特殊情况:如果是激活二级备库,LOG_FILE_NAME_CONVERT要有主库到二级备库的路径转换对应,否则报ORA-16157错误,处理方法:把主库的路径加到LOG_FILE_NAME_CONVERT参数里
1.查看是否备库是否managed real time apply(in primary)
SQL> SELECT RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID=2;
RECOVERY_MODE
-----------------------
MANAGED REAL TIME APPLY
如果不是,设置如下(in standby):
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
2.备库禁止job(in standby):<<<<<!!!!!
alter system set job_queue_processes=0 scope=both sid='*';
3.确定主备间没有gap存在
(in primary)
select thread#, sequence# from v$thread;
SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID = 2;
(in standby)
select process, status, thread#, sequence# from v$managed_standby where process='MRP0';
4.备库切换成主库(in standby)
4.1 查看备库状态是否是 TO PRIMARY
set line 300
col db_unique_name for a30
col open_mode for a20
col switchover_status for a30
col database_role for a20
select db_unique_name, database_role, open_mode,switchover_status from v$database;
DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE SWITCHOVER_STATUS
------------------------------ -------------------- -------------------- ------------------------------
oradg PHYSICAL STANDBY READ ONLY WITH APPLY NOT ALLOWED
4.2 激活备库(failover方式)
alter database recover managed standby database cancel;
alter database recover managed standby database finish; ---------> 等待所有日志应用完成
select db_unique_name,database_role,open_mode,switchover_status from v$database;
DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE SWITCHOVER_STATUS
------------------------------ -------------------- -------------------- ------------------------------
oradg PHYSICAL STANDBY READ ONLY TO PRIMARY
alter database commit to switchover to primary with session shutdown;
4.3 再次检查job,确保关闭
show parameter job_queue_processes
4.4 open新主库
alter database open;
4.5 查询新主库状态
select db_unique_name, database_role, open_mode,switchover_status from v$database;
DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE SWITCHOVER_STATUS
------------------------------ ---------------- -------------------- --------------------
oradg PRIMARY READ WRITE FAILED DESTINATION
4.6 删除dblink
select case when owner <> 'PUBLIC' then 'create or replace procedure ' ||owner||'.drop_link as' || chr(10) ||
'begin execute immediate ''drop database link '||db_link ||''';' || chr(10) ||
'end;' ||chr(10) ||
'/' || chr(10) ||
'exec '||owner||'.drop_link;' || chr(10) ||
'drop procedure ' ||owner||'.drop_link;'
else 'drop public database link ' || db_link || ';' end from dba_db_links;