快照standby

快照standby数据库允许在指定时间点后进行更新,支持DML和DDL操作。在A到B时间区间内,数据库作为快照备用,期间接收但不应用归档日志。转换回standby状态后,归档日志自动应用。快照备用常用于测试环境,如功能测试和压力测试。转换过程包括创建恢复点,并在确保非最大保护模式和备库未被日志应用时进行。
摘要由CSDN通过智能技术生成

快照standby

 

相关理论

 

快照standby数据库就是一个可以更新的数据库。

意思就是说,在A时间点,以读写的方式打开了standby数据库,也就是说A点以后的这个时间里可以支持各种DMLDDL操作。一段时间后到达B时间点,可以把这个库重新恢复到A时间点之前状态,并继续以standby的方式运行。于是在A点到B点这段时间内,这个数据就是快照备用数据库。

         在快照备用库期间,它会继续接受归档日志,但是不会应用。当快照数据库重新转回到备用数据之后,这些归档日志就会被自动的应用。

         如果是最大保护模式,而且只有一个standby备库,那么这个数据库则是不能转换为快照备用库的。

 

快照备用数据库的创建语法也很简单,就是把物理standby数据库做个转换操作

alter database convert to snapshot standby;

   

         这种备库主要用于测试环境比较多,比如负责测试,功能测试,压力测试等等。

 

         oracle在做转换的时候,先创建一个恢复点。而在处于快照备用数据库的阶段,日志传递,GAP检测仍然工作。一旦要回到物理备用库状态,oracle就会吧数据库闪回到这个恢复点。这些恢复点是有名字的,命令格式就是SNAPSHOT_STANDBY_REQUIRED_系统日期。

 

需要注意的是:必须先关闭MRP进程,不能再只读或者实时恢复(Real Time Apply)方式时转换

 

先确认pri是在醉倒性能模式

SQL> select NAME, DB_UNIQUE_NAME, DATABASE_ROLE, PROTECTION_MODE, SWITCHOVER_STATUS  from v$database;

 

NAME         DB_UNIQUE_NAME             DATABASE_ROLE     PROTECTION_MODE      SWITCHOVER_STATUS

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

ORCL          pri                                     PRIMARY          MAXIMUM PERFORMANCE  TO STANDBY

 

备库状态,

SQL> select NAME, DB_UNIQUE_NAME, OPEN_MODE, DATABASE_ROLE, PROTECTION_MODE, SWITCHOVER_STATUS from v$database;

 

NAME         DB_UNIQUE_NAME       OPEN_MODE             DATABASE_ROLE    PROTECTION_MODE         SWITCHOVER_STATUS

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

ORCL          std                        MOUNTED              PHYSICAL STANDBY MAXIMUM PERFORMANCE  NOT ALLOWED

备库在mounted状态下,才能做转换

SQL> alter database convert to snapshot standby;

alter database convert to snapshot standby

*

ERROR at line 1:

ORA-38784: Cannot create restore point 'SNAPSHOT_STANDBY_REQUIRED_03/08/2014 16:36:51'.

ORA-01153: an incompatible media recovery is active

 

SQL> alter database recover managed standby database cancel;

 

Database altered.

 

SQL> alter database convert to snapshot standby;

 

Database altered.

standby数据库正在被log applied的时候,是不能做这种转换的,需要先取消日志的应用。

此时日志中会有如下记录:

alter database convert to snapshot standby

Starting background process RVWR

Sat Mar 08 16:38:17 2014

RVWR started with pid=32, OS id=29613

Allocated 127504192 bytes in shared pool for flashback generation buffer

Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_03/08/2014 16:38:17

krsv_proc_kill: Killing 4 processes (all RFS)

Begin: Standby Redo Logfile archival

End: Standby Redo Logfile archival

RESETLOGS after incomplete recovery UNTIL CHANGE 1137105

Resetting resetlogs activation ID 1369442151 (0x51a00767)

Online log /u01/app/oracle/oradata/std/redo01.log: Thread 1 Group 1 was previously cleared

Online log /u01/app/oracle/oradata/std/redo02.log: Thread 1 Group 2 was previously cleared

Online log /u01/app/oracle/oradata/std/redo03.log: Thread 1 Group 3 was previously cleared

Standby became primary SCN: 1137103

Sat Mar 08 16:38:21 2014

Setting recovery target incarnation to 3

CONVERT TO SNAPSHOT STANDBY: Complete - Database mounted as snapshot standby

Completed: alter database convert to snapshot standby

此时可以以read ,write的方式打开数据库了

SQL> alter database open;

 

Database altered.

 

SQL> select open_mode from v$database;

 

OPEN_MODE

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

READ WRITE

 

此时在备库上做一些操作

SQL> create table test(id number);

 

Table created.

 

SQL> insert into test values(1);

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL> select * from test;

 

         ID

----------

          1

 

此时再主库上也做一些操作

SQL> alter system switch logfile;

 

System altered.

 

SQL> /

 

System altered.

 

SQL> /

 

System altered.

 

SQL> /

 

System altered.

 

SQL> /

 

System altered.

 

SQL> create tablespace test datafile '/u01/app/oracle/oradata/orcl/test01.dbf' size 100M;

 

Tablespace created.

 

此时再备库的日志中也可以看到如下内容,日志被传输过来了,但是没有被应用。

Sat Mar 08 16:43:20 2014

RFS[4]: Assigned to RFS process 29697

RFS[4]: Opened log for thread 1 sequence 45 dbid 1369450057 branch 841669324

Archived Log entry 34 added for thread 1 sequence 45 rlc 841669324 ID 0x51a00767 dest 2:

RFS[4]: Opened log for thread 1 sequence 46 dbid 1369450057 branch 841669324

Sat Mar 08 16:43:21 2014

RFS[5]: Assigned to RFS process 29701

RFS[5]: Selected log 5 for thread 1 sequence 43 dbid 1369450057 branch 841669324

Sat Mar 08 16:43:21 2014

RFS[6]: Assigned to RFS process 29703

RFS[6]: Opened log for thread 1 sequence 44 dbid 1369450057 branch 841669324

Archived Log entry 35 added for thread 1 sequence 46 rlc 841669324 ID 0x51a00767 dest 2:

Archived Log entry 36 added for thread 1 sequence 44 rlc 841669324 ID 0x51a00767 dest 2:

RFS[5]: Opened log for thread 1 sequence 48 dbid 1369450057 branch 841669324

RFS[4]: Opened log for thread 1 sequence 47 dbid 1369450057 branch 841669324

Sat Mar 08 16:43:21 2014

RFS[7]: Assigned to RFS process 29709

RFS[7]: Selected log 4 for thread 1 sequence 49 dbid 1369450057 branch 841669324

Sat Mar 08 16:43:21 2014

Archived Log entry 37 added for thread 1 sequence 43 ID 0x51a00767 dest 1:

Archived Log entry 38 added for thread 1 sequence 47 rlc 841669324 ID 0x51a00767 dest 2:

Archived Log entry 39 added for thread 1 sequence 48 rlc 841669324 ID 0x51a00767 dest 2:

 

 

 

 

 

现在将数据库切换到standby状态。

 

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 4.0486E+10 bytes

Fixed Size              2237088 bytes

Variable Size              3758099808 bytes

Database Buffers    3.6641E+10 bytes

Redo Buffers                84631552 bytes

Database mounted.

SQL> alter database convert to physical standby;

 

Database altered.

 

SQL> alter database recover managed standby database disconnect from session;

alter database recover managed standby database disconnect from session

*

ERROR at line 1:

ORA-01507: database not mounted

 

 

SQL> shutdown immediate;

ORA-01507: database not mounted

 

 

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 4.0486E+10 bytes

Fixed Size              2237088 bytes

Variable Size              3758099808 bytes

Database Buffers    3.6641E+10 bytes

Redo Buffers                84631552 bytes

Database mounted.

SQL> alter database recover managed standby database disconnect from session;

 

Database altered.

 

此时日志开始应用

Sat Mar 08 16:47:49 2014

Managed Standby Recovery not using Real Time Apply

Parallel Media Recovery started with 32 slaves

Waiting for all non-current ORLs to be archived...

All non-current ORLs have been archived.

Clearing online redo logfile 1 /u01/app/oracle/oradata/std/redo01.log

Clearing online log 1 of thread 1 sequence number 50

Completed: alter database recover managed standby database disconnect from session

Clearing online redo logfile 1 complete

Clearing online redo logfile 2 /u01/app/oracle/oradata/std/redo02.log

Clearing online log 2 of thread 1 sequence number 51

Clearing online redo logfile 2 complete

Media Recovery Log /u01/app/oracle/arch/std/1_43_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_44_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_45_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_46_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_47_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_48_841669324.arc

Media Recovery Log /u01/app/oracle/arch/std/1_49_841669324.arc

Recovery created file /u01/app/oracle/oradata/std/test01.dbf

Successfully added datafile 6 to media recovery

Datafile #6: '/u01/app/oracle/oradata/std/test01.dbf'

Media Recovery Log /u01/app/oracle/arch/std/1_50_841669324.arc

Media Recovery Waiting for thread 1 sequence 51 (in transit)

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值