Oracle 11G Active DataGuard角色切换

1.切换前准备:

1.1主库检查:

1.1.1 FAL检查

SQL> show parameter fal;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

fal_client                           string

fal_server                           string

SQL> alter system set fal_client=‘pri_1522‘;

SQL> alter system set fal_server=‘std_1522‘;

SQL> show parameter fal;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

fal_client                           string      pri_1522

fal_server                           string      std_1522

1.1.2 Standby文件自动管理

SQL> show parameter standby_file_management;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

standby_file_management              string      MANUAL

SQL> alter system set standby_file_management=‘auto‘;

SQL> show parameter standby_file_management;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

standby_file_management              string      auto

1.1.3 Convert参数设定

设定数据文件、重做日志转换目录

SQL> show parameter convert;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_file_name_convert                 string      /u01/app/oradata/testdb, /u01/

app/oradata/testdb

log_file_name_convert                string      /u01/app/archivelog/testdb, /u

01/app/archivelog/testdb

1.1.4 Log_archive_dest参数

SQL> show parameter log_archive_dest_1;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_1                   string      location=/u01/app/archivelog/t

estdb valid_for=(all_logfiles,

all_roles) db_unique_name=pri_

db

SQL> show parameter log_archive_dest_2;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_2                   string      service=std_1522 lgwr sync val

id_for=(online_logfiles,primar

y_role) db_unique_name=std_db

1.2备库检查

1.2.1 FAL检查

SQL> show parameter fal;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

fal_client                           string      std_1522

fal_server                           string      pri_1522

1.2.2 Standby文件自动管理

SQL> show parameter standby_file_management;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

standby_file_management              string      auto

1.2.3 Convert参数设定

SQL> show parameter convert;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_file_name_convert                 string      /u01/app/oradata/testdb, /u01/

app/oradata/testdb

log_file_name_convert                string      /u01/app/archivelog/testdb, /u

01/app/archivelog/testdb

1.2.4 Log_archive_dest参数

SQL> show parameter log_archive_dest_1;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_1                   string      location=/u01/app/archivelog/t

estdb valid_for=(all_logfiles,

all_roles) db_unique_name=std_

db

SQL> show parameter log_archive_dest_2;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_2                   string      service=pri_1522 lgwr sync val

id_for=(online_logfiles,primar

y_role) db_unique_name=pri_db

1.2.5 确定日志归档、force logging打开

SQL> SELECT log_mode, force_logging, open_mode FROM v$database;

LOG_MODE     FOR OPEN_MODE

------------ --- --------------------

ARCHIVELOG   YES READONLY

2.主库切换成物理备库

2.1检查主库状态

2.1.1切换前查看主库是否有GAP

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PRIMARY          RESOLVABLEGAP        READ WRITE           MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

SQL> SELECT status, gap_status, dest_id FROM v$archive_dest_status WHERE dest_id=2;

STATUS    GAP_STATUS               DEST_ID

--------- ------------------------ ----------

VALID     RESOLVABLE GAP                    2

2.1.2有GAP,进行一次日志切换

SQL> alter system switch logfile;

SQL> SELECT status, gap_status, dest_id FROM v$archive_dest_status WHERE dest_id=2;

STATUS    GAP_STATUS               DEST_ID

--------- ------------------------ ----------

VALID     NO GAP                            2

SQL> SELECT database_role, switchover_status, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- --------------------

PRIMARY          TOSTANDBY            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

2.2备库的状态

SQL> SELECT switchover_status, database_role, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY NOT ALLOWED          READ ONLY WITH APPLY MAXIMUM PERFORMANCE   MAXIMUM PERFORMANCE

2.3备库取消应用日志

SQL> alter database recover managed standby database cancel;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY SWITCHOVER PENDING   READ ONLY            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

2.4主库切换成物理备库

SQL> alter database commit to switchover to physical standby with session shutdown;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database

*

ERROR at line 1:

ORA-01507: database not mounted

2.5原备库切换成新主库

2.5.1查看状态

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY SWITCHOVER PENDING   READ ONLY            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

2.5.2原备库需要应用日志(因原主库已发生切换产生了日志)

SQL> alter database recover managed standby database disconnect;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY TO PRIMARY           READ ONLY            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

2.5.3原备库切换成新主库

SQL> alter database commit to switchover to primary;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PRIMARY          NOTALLOWED           MOUNTED              MAXIMUM PERFORMANCE  UNPROTECTED

2.5.4新主库(原备库)置为open状态:

SQL> alter database open;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PRIMARY          FAILED DESTINATION   READ WRITE           MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

到此原备库已经切换成新的主库了,原主库已切换成新备库并关闭。

3.新备库管理

3.1启动新备库,并置于mount状态

由于原主库切换时已经关闭,需要重启实例,并置于mount状态:

SQL> ! ps -ef | grep ora_

oracle   28136     1  011:10 ?        00:00:01 ora_pmon_testdb

oracle   28138     1  011:10 ?        00:00:00 ora_vktm_testdb

oracle   28142     1  011:10 ?        00:00:00 ora_gen0_testdb

oracle   28144     1  011:10 ?        00:00:00 ora_diag_testdb

oracle   28146     1  011:10 ?        00:00:00 ora_dbrm_testdb

oracle   28148     1  011:10 ?        00:00:00 ora_psp0_testdb

oracle   28150     1  011:10 ?        00:00:01 ora_dia0_testdb

oracle   28152     1  011:10 ?        00:00:02 ora_mman_testdb

oracle   28154     1  011:10 ?        00:00:00 ora_dbw0_testdb

oracle   28156     1  011:10 ?        00:00:01 ora_lgwr_testdb

oracle   28158     1  011:10 ?        00:00:01 ora_ckpt_testdb

oracle   28160     1  011:10 ?        00:00:01 ora_smon_testdb

oracle   28162     1  011:10 ?        00:00:00 ora_reco_testdb

oracle   28164     1  011:10 ?        00:00:01 ora_mmon_testdb

oracle   28166     1  011:10 ?        00:00:00 ora_mmnl_testdb

oracle   28290     1  011:25 ?        00:00:00 ora_s001_testdb

oracle   28292     1  011:25 ?        00:00:00 ora_d000_testdb

oracle   28299 18875  0 11:29 pts/0    00:00:00 /bin/bash -c  ps -ef | grep ora_

oracle   28301 28299  0 11:29 pts/0    00:00:00 grep ora_

SQL> shutdown immediate;

ORA-01507: database not mounted

ORACLE instance shut down.

SQL> startup mount;

3.2新备库应用日志:

SQL> alter database recover managed standby database using current logfile disconnect from session;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY TO PRIMARY           MOUNTED              MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

3.3新备库状态置为open:

SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-10456: cannotopen standby database; media recovery session may be in progress

SQL> alter database recover managed standby database cancel;

SQL> alter database open;

此处报错是因为备库在应用日志

3.4新备库应用日志:

3.4.1创建standby日志组

如果不创建standby日志组,应用日志会报错。

SQL> alter database recover managed standby database using current logfile disconnect from session;

alter database recover managed standby database using current logfile disconnect from session

*

ERROR at line 1:

ORA-38500: USING CURRENT LOGFILE option not available without standby redo logs

建立Standby log来应用来自主库(原备库)日志(11G新特性redo only with apply

SQL> alter database add standby logfile thread 1 group 4 ‘/u01/app/oradata/testdb/stdredo04.rdo‘ size 50m;

SQL> alter database add standby logfile thread 1 group 5 ‘/u01/app/oradata/testdb/stdredo05.rdo‘size 50m;

SQL> alter database add standby logfile thread 1 group 6 ‘/u01/app/oradata/testdb/stdredo06.rdo‘ size 50m;

SQL> alter database add standby logfile thread 1 group 7 ‘/u01/app/oradata/testdb/stdredo07.rdo‘ size 50m;

SQL> column member format a50;

SQL> SELECT * FROM v$logfile order by group#;

GROUP# STATUS  TYPE    MEMBER                                        IS_

---------- ------- ------- --------------------------------------------- ---

1         ONLINE  /u01/app/oradata/testdb/redo01.rdo            NO

2         ONLINE  /u01/app/oradata/testdb/redo02.rdo            NO

3         ONLINE  /u01/app/oradata/testdb/redo03.rdo            NO

4         STANDBY /u01/app/oradata/testdb/stdredo04.rdo         NO

5         STANDBY /u01/app/oradata/testdb/stdredo05.rdo         NO

6         STANDBY /u01/app/oradata/testdb/stdredo06.rdo         NO

7         STANDBY /u01/app/oradata/testdb/stdredo07.rdo         NO

3.4.2新备库应用日志

SQL> alter database recover managed standby database using current logfile disconnect from session;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PHYSICAL STANDBY NOT ALLOWED          READ ONLY WITH APPLY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

4状态检查及数据验证

4.1新主库检查

当新备库(原主库)启动正常时,新主库状态就正常了。

4.1.1检查新主库是否有GAP

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PRIMARY          RESOLVABLE GAP       READ WRITE           MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

SQL> alter system switch logfile;

SQL> SELECT database_role, switchover_status, open_mode, protection_mode, protection_level FROM v$database;

DATABASE_ROLE    SWITCHOVER_STATUS    OPEN_MODE            PROTECTION_MODE      PROTECTION_LEVEL

---------------- -------------------- -------------------- -------------------- --------------------

PRIMARY          TOSTANDBY            READ WRITE           MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

4.2数据验证

4.2.1新主库建表,并插入数据

SQL> SELECT username, account_status FROM dba_users WHERE username=‘HR‘;

USERNAME                       ACCOUNT_STATUS

------------------------------ --------------------------------

HR                             OPEN

SQL> create table hr.table2(id int, name varchar2(20));

SQL> insert into hr.table2 values (01, ‘Active DataGuard‘);

1 row created.

SQL> SELECT * FROM hr.table2;

ID         NAME

---------- --------------------

1 ActiveDataGuard

SQL> commit;

4.2.2新备库(原主库)验证

SQL> SELECT * FROM hr.table2;

ID         NAME

---------- --------------------

1 ActiveDataGuard

时间: 2024-10-23 15:29:10

Oracle 11G Active DataGuard角色切换的相关文章

Oracle 11g Active Dataguard (RAC)的配置

一:环境介绍主库(RAC)IP地址:192.168.1.210,192.168.1.211操作系统版本:ole5.8 64bit数据库版本:11.2.0.4 64bit数据库sid名:MECBS1,MECBS2数据库主机名:node1,node2数据库db_unique_name:MECBS 备库1  物理备库 (只安装oracle数据库软件,无需建库)IP地址:192.168.1.219操作系统版本:ole5.8 64bit数据库版本:11.2.0.4 64bit数据库sid名:PHUB数据库

最简单的11g Active DataGuard(ADG)搭建配置过程(项目步骤)

最简单的11g Active DataGuard(ADG)搭建配置过程(项目步骤) 一.环境介绍: 我在db01和db02两台Linux虚拟机上首先分别安装了一套数据库软件,在db01主机上创建了名为woo的数据库:我们这次的实验是要搭建了一套Oracle 11g Active DataGuard:目的是为了实现数据库同步的功能,并且了解Oracle 11g DG的基本功能. db01:192.168.1.50db02:192.168.1.51 二.11g ADG部署: 1.pri端和sty端配

ORACLE 11G 之DATAGUARD搭建逻辑standby

Oracle Data Guard逻辑备库是利用主库的一个备份首先建立一个物理备库,然后再将其转换为逻辑备库.这之后主库将日志传递到备库,备库利用logminer从主库的日志中解析出主库所执行过的SQL,在备库上重新执行一遍,从而保证与主库的数据在逻辑上保持一致.与物理备库相对应的是,物理备库使用的是redo apply,逻辑备库使用的是sql apply.因此逻辑备库仅仅保证数据与主库是在逻辑上是一致的,从而逻辑备库可以处于open状态下并进行相应的DML操作. 在转换physical备库到l

ORACLE 11G Data Guard 角色转换

1,ORACLE Dataguard角色切换DataGuard已经是现今标准的主流容灾方案,由于日志传递对于网络适应程度强,且可以采用同步实时的传递方式和异步延迟的传递方式,甚至可以成为远程的异地容灾方案.不管用于何种用途,DG都免不了要进行角色转换,即将standby 数据库切换为primary数据库,角色转换分为:switchover和failover两种 2,两种方式的异同1),switchover是primary库转换成standby库.standby库转换成primary库2),fai

CentOS 5.11下Oracle 11G R2 Dataguard搭建

Datagard算是Oracle企业版的一种容灾方案,在企业中广泛应用,我就将搭建过程记录下来以作备用. 主机名    数据库版本    实例名    IP db1    Oracle 11G R2    member    172.16.1.250 db2    Oracle 11G R2    member    172.16.1.251 默认情况下以上都已经安装好了Oracle数据库,但是只在db1上建立了数据库和监听,db2只安装Oracle软件不建库,不建监听. 目录: 打开强制归档日

ORACLE 11G 之DATAGUARD搭建物理standby

1 安装环境 在Primary库上安装数据库软件,并建监听和实例,在Standby库上安装数据库软件,并建监听,但不建实例. Primary库 Standby库 操作系统 CentOS release 6.4 64位 CentOS release 6.4 64位 IP/主机名 192.183.3.17/nn 192.183.3.145/kk 数据库软件版本 oracle 11.2.0.1.0 oracle 11.2.0.1.0 ORACLE_HOME /home/oracle/product /

Oracle 11g的dataguard创建中ORA-01665解决过程

Oracle 11g在创建data guard时,恢复standby控制文件不成功.在mount standby database时告诉我,控制文件不是standby控制文件,具体信息为"ORA-01665: control file is not a standby control file". 控制文件我在主库中,使用rman生成的. backup current controlfile for standby format 'xxxxxx/ctl.stdy'; 拷贝到备库上恢复.

oracle dataguard 角色切换

备库 alter database commit to switchover to primary; media recovery required --如果报ORA-16139: media recovery required,可能是由于未应用日志引起,可先执行 ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION; 然后再执行该命令

oracle 11g Active database duplicate

测试使用 Active database duplicate在不同机器不同数据库实例复制数据库 环境: Target DB: IP:10.131.119.118 HOSTNAME:CS-SI-DG01 ORACLE_SID:orcl Auxiliary DB: IP:10.131.119.119 HOSTNAME:CS-SI-DG02 ORACLE_SID:orclaux 1.将Target DB库的参数文件和密码文件scp到Auxiliary DB库 [[email protected] db