Implement Oracle snapshot database with Dataguard

简介:

11g的DataGuard提供了一个快照数据库(snapshot standby)的功能,也就是可以将物理备库临时以读写的方式打开,主库的归档日志会继续传输到备库,但备库不应用,等到将备库重新切换为physical standby的时候继续应用,从而实现主库和备库的数据一致,值得一提的是这个功能不需要开启主备库的闪回数据库功能,先前在这里存在误区,这个功能还是比较赞的,可以直接拿物理备库做下临时测试数据库!

一:确定主备库均为打开闪回数据库功能,本例中主库为dg1,备库为dg2

 
  1. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  2.  
  3. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  4. -------------------- ---------------- -------------------- ------------------  
  5. READ WRITE           PRIMARY          dg1                  NO  
  6.  
  7. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  8.  
  9. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  10. -------------------- ---------------- -------------------- ------------------  
  11. READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO 

二:重新启动备库到mount状态,进行转换操作,转换完成后可以看到闪回的进程rvwr已经自动启动

 
  1. SQL> alter database recover managed standby database cancel;  
  2. Database altered.  
  3.  
  4. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  5.  
  6. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  7. -------------------- ---------------- -------------------- ------------------  
  8. READ ONLY            PHYSICAL STANDBY dg2                  NO  
  9.  
  10. SQL> shutdown immediate  
  11. Database closed.  
  12. Database dismounted.  
  13. ORACLE instance shut down.  
  14. SQL> startup mount  
  15. ORACLE instance started.  
  16. Total System Global Area  417546240 bytes  
  17. Fixed Size                  2228944 bytes  
  18. Variable Size             343936304 bytes  
  19. Database Buffers           62914560 bytes  
  20. Redo Buffers                8466432 bytes  
  21. Database mounted.  
  22.  
  23. SQL> alter database convert to snapshot standby;  
  24. Database altered.  
  25.  
  26. SQL> !ps -ef |grep rvwr  
  27. oracle   14767     1  0 15:20 ?        00:00:00 ora_rvwr_dg  
  28. oracle   14788 14756  0 15:24 pts/4    00:00:00 /bin/bash -c ps -ef |grep rvwr  
  29. oracle   14790 14788  0 15:24 pts/4    00:00:00 grep rvwr 

四:打开数据库,期间观察切换过程日志如下,注意红色字体部分,实际上是产生了一个闪回数据库的保障点

 
  1. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  2.  
  3. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  4. -------------------- ---------------- -------------------- ------------------  
  5. MOUNTED              SNAPSHOT STANDBY dg2                  RESTORE POINT ONLY  
  6.  
  7. SQL> alter database open;  
  8. Database altered.  
  9.  
  10. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  11.  
  12. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  13. -------------------- ---------------- -------------------- ------------------  
  14. READ WRITE           SNAPSHOT STANDBY dg2                  RESTORE POINT ONLY  
  15.  
  16. [oracle@dg2 ~]$ tail -f /u01/app/oracle/diag/rdbms/dg2/dg/trace/alert_dg.log   
  17. Sat May 05 15:16:55 2012  
  18. alter database recover managed standby database cancel  
  19. Sat May 05 15:16:55 2012  
  20. MRP0: Background Media Recovery cancelled with status 16037  
  21. Errors in file /u01/app/oracle/diag/rdbms/dg2/dg/trace/dg_pr00_14678.trc:  
  22. ORA-16037: user requested cancel of managed recovery operation  
  23. Managed Standby Recovery not using Real Time Apply  
  24. Recovery interrupted!  
  25. Recovered data files to a consistent state at change 1107151  
  26. Sat May 05 15:16:56 2012  
  27. MRP0: Background Media Recovery process shutdown (dg)  
  28. Managed Standby Recovery Canceled (dg)  
  29. Completed: alter database recover managed standby database cancel  
  30. Sat May 05 15:20:03 2012  
  31. alter database convert to snapshot standby  
  32. Starting background process RVWR  
  33. Sat May 05 15:20:03 2012  
  34. RVWR started with pid=33, OS id=14767   
  35. Allocated 3981120 bytes in shared pool for flashback generation buffer  
  36. Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_05/05/2012 15:20:03  
  37. krsv_proc_kill: Killing 4 processes (all RFS)  
  38. All dispatchers and shared servers shutdown  
  39. CLOSE: killing server sessions.  
  40. CLOSE: all sessions shutdown successfully.  
  41. Sat May 05 15:20:09 2012  
  42. SMON: disabling cache recovery  
  43. Begin: Standby Redo Logfile archival  
  44. End: Standby Redo Logfile archival  
  45. RESETLOGS after incomplete recovery UNTIL CHANGE 1107151  
  46. Waiting for all non-current ORLs to be archived...  
  47. All non-current ORLs have been archived.  
  48. Resetting resetlogs activation ID 1695253094 (0x650b8266)  
  49. Online log /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_1_7s76q5w1_.log: Thread 1 Group 1 was   
  50.  
  51. previously cleared  
  52. Online log /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_2_7s76q94s_.log: Thread 1 Group 2 was   
  53.  
  54. previously cleared  
  55. Online log /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_3_7s76qbhq_.log: Thread 1 Group 3 was   
  56.  
  57. previously cleared  
  58. Standby became primary SCN: 1107149  
  59. Sat May 05 15:20:11 2012  
  60. Setting recovery target incarnation to 3  
  61. AUDIT_TRAIL initialization parameter is changed back to its original value as specified in the parameter file.  
  62. CONVERT TO SNAPSHOT STANDBY: Complete - Database mounted as snapshot standby  
  63. Completed: alter database convert to snapshot standby 

五:对快照数据库进行写数据操作

 
  1. SQL> create user test identified by test;  
  2. User created.  
  3.  
  4. SQL> grant connect,resource to test;  
  5. Grant succeeded.  
  6.  
  7. [oracle@dg1 ~]$ sqlplus test/test@dg2  
  8. SQL*Plus: Release 11.2.0.3.0 Production on Sat May 5 15:28:42 2012  
  9. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  10.  
  11. Connected to:  
  12. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  
  13. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  14.  
  15. SQL> create table t1 (id number);  
  16. Table created.  
  17.  
  18. SQL> insert into t1 values (1);  
  19. 1 row created.  
  20.  
  21. SQL> commit;  
  22. Commit complete.  
  23.  
  24. SQL> exit  
  25. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  
  26. With the Partitioning, OLAP, Data Mining and Real Application Testing options 

六:主库上执行日志切换,观察主库的日志输入,红色字体部分说明日志有继续传输到dg2

 
  1. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  2.  
  3. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  4. -------------------- ---------------- -------------------- ------------------  
  5. READ WRITE           PRIMARY          dg1                  NO  
  6.  
  7. SQL> archive log list  
  8. Database log mode              Archive Mode  
  9. Automatic archival             Enabled  
  10. Archive destination            /u01/app/oracle/standbylog  
  11. Oldest online log sequence     42  
  12. Next log sequence to archive   44  
  13. Current log sequence           44  
  14. SQL> alter system switch logfile;  
  15. System altered.  
  16.  
  17. [oracle@dg1 ~]$ tail -f /u01/app/oracle/diag/rdbms/dg1/dg/trace/alert_dg.log  
  18. Sat May 05 15:34:10 2012  
  19. LGWR: Standby redo logfile selected to archive thread 1 sequence 45  
  20. LGWR: Standby redo logfile selected for thread 1 sequence 45 for destination LOG_ARCHIVE_DEST_2  
  21. Thread 1 advanced to log sequence 45 (LGWR switch)  
  22.   Current log# 2 seq# 45 mem# 0: /u01/app/oracle/oradata/dg/redo02.log  
  23. Sat May 05 15:34:11 2012  
  24. Archived Log entry 72 added for thread 1 sequence 44 ID 0x650b8266 dest 1: 

七:查看快照数据库,已经多了一个incarnation,日志序列号从1开始

 
  1. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  2.  
  3. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  4. -------------------- ---------------- -------------------- ------------------  
  5. READ WRITE           SNAPSHOT STANDBY dg2                  RESTORE POINT ONLY  
  6.  
  7. SQL> archive log list;  
  8. Database log mode              Archive Mode  
  9. Automatic archival             Enabled  
  10. Archive destination            /u01/app/oracle/standbylog  
  11. Oldest online log sequence     1  
  12. Next log sequence to archive   1  
  13. Current log sequence           1  
  14.  
  15. [oracle@dg2 ~]$ rman target /  
  16. Recovery Manager: Release 11.2.0.3.0 - Production on Sat May 5 15:35:43 2012  
  17. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  
  18. connected to target database: DG (DBID=1694605607)  
  19.  
  20. RMAN> list incarnation;  
  21.  
  22. using target database control file instead of recovery catalog  
  23.  
  24. List of Database Incarnations  
  25. DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time  
  26. ------- ------- -------- ---------------- --- ---------- ----------  
  27. 1       1       DG       1694605607       PARENT  1          2011-09-17-09:46:04  
  28. 2       2       DG       1694605607       PARENT  995548     2012-04-22-12:43:25  
  29. 3       3       DG       1694605607       CURRENT 1107152    2012-05-05-15:20:09 

八:重新转换快照数据库到物理备库状态,查看相关的日志信息

 
  1. SQL> shutdown immediate  
  2. Database closed.  
  3. Database dismounted.  
  4. ORACLE instance shut down.  
  5.  
  6. SQL> startup mount  
  7. ORACLE instance started.  
  8.  
  9. Total System Global Area  417546240 bytes  
  10. Fixed Size                  2228944 bytes  
  11. Variable Size             348130608 bytes  
  12. Database Buffers           58720256 bytes  
  13. Redo Buffers                8466432 bytes  
  14. Database mounted.  
  15.  
  16. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  17.  
  18. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  19. -------------------- ---------------- -------------------- ------------------  
  20. MOUNTED              SNAPSHOT STANDBY dg2                  RESTORE POINT ONLY  
  21.  
  22. SQL> alter database convert to physical standby;  
  23. Database altered.  
  24.  
  25. [oracle@dg2 ~]$ tail -f /u01/app/oracle/diag/rdbms/dg2/dg/trace/alert_dg.log   
  26. Sat May 05 15:40:10 2012  
  27. alter database convert to physical standby  
  28. ALTER DATABASE CONVERT TO PHYSICAL STANDBY (dg)  
  29. krsv_proc_kill: Killing 3 processes (all RFS)  
  30. Flashback Restore Start  
  31. Flashback Restore Complete  
  32. Drop guaranteed restore point   
  33. Stopping background process RVWR  
  34. Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/DG2/flashback/o1_mf_7t9o53gj_.flb  
  35. Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/DG2/flashback/o1_mf_7t9o57qv_.flb  
  36. Guaranteed restore point  dropped  
  37. Clearing standby activation ID 1695816619 (0x65141bab)  
  38. The primary database controlfile was created using the  
  39. 'MAXLOGFILES 16' clause.  
  40. There is space for up to 13 standby redo logfiles  
  41. Use the following SQL commands on the standby database to create  
  42. standby redo logfiles that match the primary database:  
  43. ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;  
  44. ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;  
  45. ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;  
  46. ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;  
  47. Shutting down archive processes  
  48. Archiving is disabled  
  49. Sat May 05 15:40:19 2012  
  50. ARCH shutting down  
  51. ARC3: Archival stopped  
  52. Sat May 05 15:40:19 2012  
  53. ARCH shutting down  
  54. ARC2: Archival stopped  
  55. Sat May 05 15:40:19 2012  
  56. ARCH shutting downSat May 05 15:40:19 2012  
  57. ARCH shutting down  
  58. ARC0: Archival stopped  
  59. ARC1: Archival stopped  
  60. Sat May 05 15:40:20 2012  
  61. Completed: alter database convert to physical standby 

九:重新将备库置于ADG模式下,之前的测试数据已经不存在

 
  1. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  2. select open_mode,database_role,db_unique_name,flashback_on from v$database  
  3. *  
  4. ERROR at line 1:  
  5. ORA-01507: database not mounted  
  6.  
  7. SQL> shutdown immediate  
  8. ORA-01507: database not mounted  
  9. ORACLE instance shut down.  
  10.  
  11. SQL> startup  
  12. ORACLE instance started.  
  13.  
  14. Total System Global Area  417546240 bytes  
  15. Fixed Size                  2228944 bytes  
  16. Variable Size             348130608 bytes  
  17. Database Buffers           58720256 bytes  
  18. Redo Buffers                8466432 bytes  
  19. Database mounted.  
  20. Database opened.  
  21.  
  22. SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  
  23.  
  24. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  
  25. -------------------- ---------------- -------------------- ------------------  
  26. READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO  
  27.  
  28. SQL> select * from test.t1;  
  29. select * from test.t1  
  30.                    *  
  31. ERROR at line 1:  
  32. ORA-00942: table or view does not exist  
  33.  
  34. SQL> select * from dba_users where username='TEST';  
  35. no rows selected 

 本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/857363如需转载请自行联系原作者


ylw6006

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
21天前
|
Oracle 关系型数据库
19c 开启Oracle Database Vault
19c 开启Oracle Database Vault
15 1
|
5天前
|
人工智能 Oracle 关系型数据库
一篇文章弄懂Oracle和PostgreSQL的Database Link
一篇文章弄懂Oracle和PostgreSQL的Database Link
|
21天前
|
SQL Oracle 安全
Oracle Database Vault Access Control Components
Oracle Database Vault Access Control Components
9 0
|
21天前
|
Oracle 安全 关系型数据库
What Is Oracle Database Vault?
The Oracle Database Vault security controls protect application data from unauthorized access, and helps you to comply with privacy and regulatory requirements. You can deploy controls to block privileged account access to application data and control sensitive operations inside the database using
10 0
|
2月前
|
Oracle 关系型数据库 Linux
服务器Centos7 静默安装Oracle Database 12.2
服务器Centos7 静默安装Oracle Database 12.2
88 0
|
3月前
|
Oracle 关系型数据库
oracle 19c 搭建dataguard 简要命令
通过service 完成dg 搭建。
53 0
|
5月前
|
Oracle 关系型数据库 数据库
windows Oracle Database 19c 卸载教程
打开任务管理器 ctrl+Shift+Esc可以快速打开任务管理器,找到oracle所有服务然后停止。 停止数据库服务 在开始卸载之前,确保数据库服务已经停止。你可以使用以下命令停止数据库服务: net stop OracleServiceORCL Universal Installer 卸载Oracle数据库程序 一般情况运行Oracle自带的卸载程序,如使用Universal Installer 工具卸载。 点击开始菜单找到Oracle,然后点击Oracle安装产品,再点击Universal Installer。 点击之后稍等一会然后会进入进入下图界面,点击卸载产品。 选中要删除的Orac
124 1
|
6月前
|
存储 Oracle 关系型数据库
windows 使用 Oracle Database 19c
Oracle数据库是由美国Oracle Corporation(甲骨文公司)开发和提供的一种关系型数据库管理系统,它是一种强大的关系型数据库管理系统(RDBMS)。它使用表格(表)组织和存储数据,通过SQL语言进行数据管理。数据以表格形式存储,表之间可以建立关系。支持事务处理、多版本并发控制、安全性和权限控制。具有高可用性、容错性,支持分布式数据库和可扩展性。Oracle Corporation提供全面的支持和服务,使其成为企业级应用的首选数据库系统。
61 0
|
6月前
|
Oracle 关系型数据库 数据库
Flink CDC中oracle dataguard模式下,有没有cdc备库的方案?
Flink CDC中oracle dataguard模式下,有没有cdc备库的方案?
73 1
|
11月前
|
Oracle 关系型数据库 Linux
服务器Centos7 静默安装Oracle Database 12.2(下)
服务器Centos7 静默安装Oracle Database 12.2(下)
243 0

推荐镜像

更多