一、环境准备

1、数据库软件准备

(1)、在主节点,安装单机数据库软件并创建数据库。
(2)、在备库, 安装单机数据库软件, 但是不创建数据库。


2、操作系统配置

在/etc/hosts下面配置主机名。
  1. $ cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.56.31 xiaohe_dg1
  5. 192.168.56.32 xiaohe_dg2

3、数据库部分参数

角色 主机名 数据库实例 db_domain
主库 xiaohe_dg1 xiaohe xiaohe.com
备库 xiaohe_dg2 xiaohedg xiaohe.com


二、配置数据库

1、主库打开数据库

  1. SQL> startup

2、配置监听

(1)、设置db_domain
  1. SQL> show parameter db_domain;
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. db_domain string
  5. SQL>
  6. SQL> alter system set db_domain='xiaohe.com' scope=spfile;
  7. SQL> shutdown immediate
  8. SQL> startup
  9. SQL> show parameter db_domain;
  10. NAME TYPE VALUE
  11. ------------------------------------ ----------- ------------------------------
  12. db_domain string xiaohe.com

(2)、在主/备库设置监听

路径:$ORACLE_HOME/network/admin

主库配置:
  1. $ cat listener.ora
  2. LISTENER=
  3. (DESCRIPTION=
  4. (ADDRESS_LIST=
  5. (ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg1)(PORT=1521))))
  6. SID_LIST_LISTENER=
  7. (SID_LIST=
  8. (SID_DESC=
  9. (GLOBAL_DBNAME=xiaohe_DGMGRL.xiaohe.com)
  10. (ORACLE_HOME=/u01/app/oracle/product/11.2.0)
  11. (SID_NAME=xiaohe))
  12. )



备库配置:
  1. $ cat listener.ora
  2. LISTENER=
  3. (DESCRIPTION=
  4. (ADDRESS_LIST=
  5. (ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg2)(PORT=1521))))
  6. SID_LIST_LISTENER=
  7. (SID_LIST=
  8. (SID_DESC=
  9. (GLOBAL_DBNAME=xiaohedg_DGMGRL.xiaohe.com)
  10. (ORACLE_HOME=/u01/app/oracle/product/11.2.0)
  11. (SID_NAME=xiaohedg))
  12. )


说明:GLOBAL_DBNAME为db_unique_name_DGMGRL.db_domain

(3)、启动主备库的监听
下面是备库的监听:
  1. [oracle@xiaohe_dg2 admin]$ lsnrctl start
  2. LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 18-MAR-2017 18:32:48
  3. Copyright (c) 1991, 2011, Oracle. All rights reserved.
  4. Starting /u01/app/oracle/product/11.2.0/bin/tnslsnr: please wait...
  5. TNSLSNR for Linux: Version 11.2.0.3.0 - Production
  6. System parameter file is /u01/app/oracle/product/11.2.0/network/admin/listener.ora
  7. Log messages written to /u01/app/oracle/diag/tnslsnr/xiaohe_dg2/listener/alert/log.xml
  8. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg2)(PORT=1521)))
  9. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg2)(PORT=1521)))
  10. STATUS of the LISTENER
  11. ------------------------
  12. Alias LISTENER
  13. Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
  14. Start Date 18-MAR-2017 18:32:49
  15. Uptime 0 days 0 hr. 0 min. 1 sec
  16. Trace Level off
  17. Security ON: Local OS Authentication
  18. SNMP OFF
  19. Listener Parameter File /u01/app/oracle/product/11.2.0/network/admin/listener.ora
  20. Listener Log File /u01/app/oracle/diag/tnslsnr/xiaohe_dg2/listener/alert/log.xml
  21. Listening Endpoints Summary...
  22. (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg2)(PORT=1521)))
  23. Services Summary...
  24. Service "xiaohedg_DGMGRL.xiaohe.com" has 1 instance(s).
  25. Instance "xiaohedg", status UNKNOWN, has 1 handler(s) for this service...
  26. The command completed successfully

监听实例必须是静态的, 因为数据库没有启动, 监听也是能够启动的。


3、配置tnsnames

(1)、监听的内容
  1. $ cat tnsnames.ora
  2. xiaohe_dg1=
  3. (DESCRIPTION=
  4. (ADDRESS_LIST=
  5. (ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg1)(PORT=1521)))
  6. (CONNECT_DATA=
  7. (SERVICE_NAME=xiaohe_DGMGRL.xiaohe.com))
  8. )
  9. xiaohe_dg2=
  10. (DESCRIPTION=
  11. (ADDRESS_LIST=
  12. (ADDRESS=(PROTOCOL=tcp)(HOST=xiaohe_dg2)(PORT=1521)))
  13. (CONNECT_DATA=
  14. (SERVICE_NAME=xiaohedg_DGMGRL.xiaohe.com))
  15. )

SERVICE_NAME可以通过lsnrctl status来查看。

(2)、在主库验证监听是否配置成功
  1. [oracle@xiaohe_dg1 admin]$ sqlplus sys/oracle123@xiaohe_dg1 as sysdba
  2. SQL*Plus: Release 11.2.0.3.0 Production on Sat Mar 18 19:02:30 2017
  3. Copyright (c) 1982, 2011, Oracle. All rights reserved.
  4. Connected to:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  7. SQL>

(3)、将主库的tnsnames配置文件传到备库
  1. $ scp tnsnames.ora xiaohe_dg2:/u01/app/oracle/product/11.2.0/network/admin/
  2. oracle@xiaohe_dg2's password:
  3. tnsnames.ora 100% 333 0.3KB/s 00:00


4、开启主库的归档模式

(1)、新建归档目录
  1. [oracle@xiaohe_dg1 oradata]$ mkdir archive
  2. [oracle@xiaohe_dg1 oradata]$ cd archive/
  3. [oracle@xiaohe_dg1 archive]$ pwd
  4. /oradata/archive

(2)、开启归档
  1. SQL> shutdown immediate
  2. SQL> startup mount

  3. SQL> alter database archivelog;  
  4.  
  5. SQL> alter system set log_archive_dest_1='location=/oradata/archive' scope=spfile;
  6. SQL> shutdown immediate;
  7. SQL> startup
  8. SQL> archive log list;
  9. Database log mode Archive Mode
  10. Automatic archival Enabled
  11. Archive destination /oradata/archive
  12. Oldest online log sequence 10
  13. Next log sequence to archive 12
  14. Current log sequence 12


5、配置主备库数据、日志目录转换

  1. SQL> alter system set db_file_name_convert='/oradata/xiaohedg','/oradata/xiaohe' scope=spfile;
  2. SQL> alter system set log_file_name_convert='/oradata/xiaohedg','/oradata/xiaohe' scope=spfile;
注意格式:alter system set log_file_name_convert='对端库的目录','当前库目录' scope=spfile;


6、设置闪回

设置闪回, 后面测试建立测试库。
(1)、新建闪回目录
  1. [oracle@xiaohe_dg1 oradata]$ mkdir flash
  2. [oracle@xiaohe_dg1 oradata]$ cd flash/
  3. [oracle@xiaohe_dg1 flash]$ pwd
  4. /oradata/flash

(2)、设置闪回参数
  1. SQL> show parameter recover;
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. db_recovery_file_dest string
  5. db_recovery_file_dest_size big integer 0
  6. db_unrecoverable_scn_tracking boolean TRUE
  7. recovery_parallelism integer 0

  8. SQL> alter system set db_recovery_file_dest_size=500M;
  9. SQL> alter system set db_recovery_file_dest='/oradata/flash';
  10. SQL> show parameter recover;
  11. NAME TYPE VALUE
  12. ------------------------------------ ----------- ------------------------------
  13. db_recovery_file_dest string /oradata/flash
  14. db_recovery_file_dest_size big integer 500M
  15. db_unrecoverable_scn_tracking boolean TRUE
  16. recovery_parallelism

7、设置standby的文件传输参数

如果设置为手动, 那么主库新建的表空间文件无法传到备库。
  1. SQL> show parameter standby 
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. standby_archive_dest string ?/dbs/arch
  5. standby_file_management string MANUAL
  6. SQL> alter system set standby_file_management=AUTO;
  7. SQL> show parameter standby;
  8. NAME TYPE VALUE
  9. ------------------------------------ ----------- ------------------------------
  10. standby_archive_dest string ?/dbs/arch
  11. standby_file_management string AUTO

8、开启强制日志

  1. SQL> alter database force logging;

9、开启闪回

  1. SQL> shutdown immediate
  2. SQL> startup mount;
  3. SQL> alter database flashback on;
  4. SQL> alter database open;

10、配置standby log参数

创建4组standby 日志, 比原日志数目多一个。
  1. SQL> alter database add standby logfile group 4 '/oradata/xiaohe/std_redo04.log' size 50M;
  2. SQL> alter database add standby logfile group 5 '/oradata/xiaohe/std_redo05.log' size 50M;
  3. SQL> alter database add standby logfile group 6 '/oradata/xiaohe/std_redo06.log' size 50M;
  4. SQL> alter database add standby logfile group 7 '/oradata/xiaohe/std_redo07.log' size 50M;

11、生成参数文件pfile

(1)、生成pfile文件
  1. SQL> create pfile='/oradata/initxiaohedg.ora' from spfile;
(2)、传送pfile到备库的dbs目录下面
  1. $ scp initxiaohedg.ora xiaohe_dg2:/u01/app/oracle/product/11.2.0/dbs/
  2. oracle@xiaohe_dg2's password:
  3. initxiaohedg.ora

12、传送密码文件到备库


  1. $ cd $ORACLE_HOME/dbs
  2. [oracle@xiaohe_dg1 dbs]$ scp orapwxiaohe xiaohe_dg2:/u01/app/oracle/product/11.2.0/dbs/orapwxiaohedg
  3. oracle@xiaohe_dg2's password:
  4. orapwxiaohe
注意:密码文件传过去, 一定要改名字。


13、在备库修改pfile文件

  1. [oracle@xiaohe_dg2 dbs]$ cat initxiaohedg.ora
  2. xiaohe.__db_cache_size=327155712
  3. xiaohe.__java_pool_size=4194304
  4. xiaohe.__large_pool_size=4194304
  5. xiaohe.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
  6. xiaohe.__pga_aggregate_target=339738624
  7. xiaohe.__sga_target=503316480
  8. xiaohe.__shared_io_pool_size=0
  9. xiaohe.__shared_pool_size=155189248
  10. xiaohe.__streams_pool_size=4194304
  11. *.audit_file_dest='/u01/app/oracle/admin/xiaohe/adump'
  12. *.audit_trail='db'
  13. *.compatible='11.2.0.0.0'
  14. *.control_files='/oradata/xiaohedg/control01.ctl','/oradata/xiaohedg/control02.ctl'
  15. *.db_block_size=8192
  16. *.db_domain='xiaohe.com'
  17. *.db_file_name_convert='/oradata/xiaohe','/oradata/xiaohedg'
  18. *.db_name='xiaohe'
  19. *.db_unique_name='xiaohedg'
  20. *.db_recovery_file_dest_size=524288000
  21. *.db_recovery_file_dest='/oradata/flash'
  22. *.diagnostic_dest='/u01/app/oracle'
  23. *.dispatchers='(PROTOCOL=TCP) (SERVICE=xiaoheXDB)'
  24. *.log_archive_dest_1='location=/oradata/archive'
  25. *.log_file_name_convert='/oradata/xiaohe','/oradata/xiaohedg'
  26. *.memory_target=839909376
  27. *.open_cursors=300
  28. *.processes=150
  29. *.remote_login_passwordfile='EXCLUSIVE'
  30. *.standby_file_management='AUTO'
  31. *.undo_tablespace='UNDOTBS1'
修改的地方:
(1)、*.audit_file_dest:目录不存在, 重新创建
(2)、*.control_files:修改控制文件的目录,并创建目录/oradata/xiaohedg
(3)、*.db_file_name_convert 和 *.log_file_name_convert的对端库和当前库的目录位置互换。
(4)、*.log_archive_dest_1目录不存在, 需要创建。
(4)、新增一个条目:*.db_unique_name='xiaohedg'


14、在备库启动实例

生成启动文件spfile, 下次启动时候能自动选择spfile启动。
将数据库启动到nomount。
  1. SQL> startup
  2. ORACLE instance started.
  3. Total System Global Area 839282688 bytes
  4. Fixed Size 2233000 bytes
  5. Variable Size 494931288 bytes
  6. Database Buffers 339738624 bytes
  7. Redo Buffers 2379776 bytes
  8. ORA-00205: error in identifying control file, check alert log for more info
  9. SQL> show parameter spfile;
  10. NAME TYPE VALUE
  11. ------------------------------------ ----------- ------------------------------
  12. spfile string
  13. SQL> create spfile from pfile;
  14. File created.
  15. SQL> shutdown immediate;
  16. ORA-01507: database not mounted
  17. ORACLE instance shut down.
  18. SQL> startup nomount
  19. ORACLE instance started.
  20. Total System Global Area 839282688 bytes
  21. Fixed Size 2233000 bytes
  22. Variable Size 494931288 bytes
  23. Database Buffers 339738624 bytes
  24. Redo Buffers 2379776 bytes

在主库多切换几次日志:
  1. SQL> alter system switch logfile;
  2. System altered.
  3. SQL> /
  4. System altered.
  5. SQL> /
  6. System altered.
  7. SQL> /
  8. System altered.
  9. SQL> /

15、检查并重启主库


(1)、重启主库, 查看能否正常启动。

(2)、检查主备库的db_name是否一致。
db_name必须一样, db_unique_name不能一样。

(3)、检查网络:
  1. $ sqlplus sys/oracle123@xiaohe_dg1 as sysdba;
  2. $ sqlplus sys/oracle123@xiaohe_dg2 as sysdba;

(4)、检查目录转换
  1. SQL> show parameter convert;


16、使用rman

  1. [oracle@xiaohe_dg1 dbs]$ rman target sys/oracle123@xiaohe_dg1 auxiliary sys/oracle123@xiaohe_dg2
  2. Recovery Manager: Release 11.2.0.3.0 - Production on Sat Mar 18 20:21:06 2017
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  4. connected to target database: XIAOHE (DBID=4061739917)
  5. connected to auxiliary database: XIAOHE (not mounted)
  6. RMAN> duplicate target database for standby from active database;
  7. Starting Duplicate Db at 18-MAR-17
  8. using target database control file instead of recovery catalog
  9. allocated channel: ORA_AUX_DISK_1
  10. channel ORA_AUX_DISK_1: SID=20 device type=DISK
  11. contents of Memory Script:
  12. {
  13. backup as copy reuse
  14. targetfile '/u01/app/oracle/product/11.2.0/dbs/orapwxiaohe' auxiliary format
  15. '/u01/app/oracle/product/11.2.0/dbs/orapwxiaohedg' ;
  16. }
  17. executing Memory Script
  18. Starting backup at 18-MAR-17
  19. allocated channel: ORA_DISK_1
  20. channel ORA_DISK_1: SID=38 device type=DISK
  21. Finished backup at 18-MAR-17
  22. contents of Memory Script:
  23. {
  24. backup as copy current controlfile for standby auxiliary format '/oradata/xiaohedg/control01.ctl';
  25. restore clone controlfile to '/oradata/xiaohedg/control02.ctl' from
  26. '/oradata/xiaohedg/control01.ctl';
  27. }
  28. executing Memory Script
  29. Starting backup at 18-MAR-17
  30. using channel ORA_DISK_1
  31. channel ORA_DISK_1: starting datafile copy
  32. copying standby control file
  33. output file name=/u01/app/oracle/product/11.2.0/dbs/snapcf_xiaohe.f tag=TAG20170318T202332 RECID=2 STAMP=938982213
  34. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
  35. Finished backup at 18-MAR-17
  36. Starting restore at 18-MAR-17
  37. using channel ORA_AUX_DISK_1
  38. channel ORA_AUX_DISK_1: copied control file copy
  39. Finished restore at 18-MAR-17
  40. contents of Memory Script:
  41. {
  42. sql clone 'alter database mount standby database';
  43. }
  44. executing Memory Script
  45. sql statement: alter database mount standby database
  46. contents of Memory Script:
  47. {
  48. set newname for tempfile 1 to
  49. "/oradata/xiaohedg/temp01.dbf";
  50. switch clone tempfile all;
  51. set newname for datafile 1 to
  52. "/oradata/xiaohedg/system01.dbf";
  53. set newname for datafile 2 to
  54. "/oradata/xiaohedg/sysaux01.dbf";
  55. set newname for datafile 3 to
  56. "/oradata/xiaohedg/undotbs01.dbf";
  57. set newname for datafile 4 to
  58. "/oradata/xiaohedg/users01.dbf";
  59. set newname for datafile 5 to
  60. "/oradata/xiaohedg/example01.dbf";
  61. backup as copy reuse
  62. datafile 1 auxiliary format
  63. "/oradata/xiaohedg/system01.dbf" datafile
  64. 2 auxiliary format
  65. "/oradata/xiaohedg/sysaux01.dbf" datafile
  66. 3 auxiliary format
  67. "/oradata/xiaohedg/undotbs01.dbf" datafile
  68. 4 auxiliary format
  69. "/oradata/xiaohedg/users01.dbf" datafile
  70. 5 auxiliary format
  71. "/oradata/xiaohedg/example01.dbf" ;
  72. sql 'alter system archive log current';
  73. }
  74. executing Memory Script
  75. executing command: SET NEWNAME
  76. renamed tempfile 1 to /oradata/xiaohedg/temp01.dbf in control file
  77. executing command: SET NEWNAME
  78. executing command: SET NEWNAME
  79. executing command: SET NEWNAME
  80. executing command: SET NEWNAME
  81. executing command: SET NEWNAME
  82. Starting backup at 18-MAR-17
  83. using channel ORA_DISK_1
  84. channel ORA_DISK_1: starting datafile copy
  85. input datafile file number=00001 name=/oradata/xiaohe/system01.dbf
  86. output file name=/oradata/xiaohedg/system01.dbf tag=TAG20170318T202342
  87. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
  88. channel ORA_DISK_1: starting datafile copy
  89. input datafile file number=00002 name=/oradata/xiaohe/sysaux01.dbf
  90. output file name=/oradata/xiaohedg/sysaux01.dbf tag=TAG20170318T202342
  91. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
  92. channel ORA_DISK_1: starting datafile copy
  93. input datafile file number=00005 name=/oradata/xiaohe/example01.dbf
  94. output file name=/oradata/xiaohedg/example01.dbf tag=TAG20170318T202342
  95. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
  96. channel ORA_DISK_1: starting datafile copy
  97. input datafile file number=00003 name=/oradata/xiaohe/undotbs01.dbf
  98. output file name=/oradata/xiaohedg/undotbs01.dbf tag=TAG20170318T202342
  99. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
  100. channel ORA_DISK_1: starting datafile copy
  101. input datafile file number=00004 name=/oradata/xiaohe/users01.dbf
  102. output file name=/oradata/xiaohedg/users01.dbf tag=TAG20170318T202342
  103. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
  104. Finished backup at 18-MAR-17
  105. sql statement: alter system archive log current
  106. contents of Memory Script:
  107. {
  108. switch clone datafile all;
  109. }
  110. executing Memory Script
  111. datafile 1 switched to datafile copy
  112. input datafile copy RECID=2 STAMP=938982344 file name=/oradata/xiaohedg/system01.dbf
  113. datafile 2 switched to datafile copy
  114. input datafile copy RECID=3 STAMP=938982344 file name=/oradata/xiaohedg/sysaux01.dbf
  115. datafile 3 switched to datafile copy
  116. input datafile copy RECID=4 STAMP=938982344 file name=/oradata/xiaohedg/undotbs01.dbf
  117. datafile 4 switched to datafile copy
  118. input datafile copy RECID=5 STAMP=938982344 file name=/oradata/xiaohedg/users01.dbf
  119. datafile 5 switched to datafile copy
  120. input datafile copy RECID=6 STAMP=938982344 file name=/oradata/xiaohedg/example01.dbf
  121. Finished Duplicate Db at 18-MAR-17


17、在备库应用日志

  1. SQL> select status from v$instance ;
  2. STATUS
  3. ------------
  4. MOUNTED
  5. SQL> alter database recover managed standby database disconnect from session;
  6. Database altered.


18、在主、备库启用broker

  1. SQL> show parameter broker;
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. dg_broker_config_file1 string /u01/app/oracle/product/11.2.0
  5. /dbs/dr1xiaohe.dat
  6. dg_broker_config_file2 string /u01/app/oracle/product/11.2.0
  7. /dbs/dr2xiaohe.dat
  8. dg_broker_start boolean FALSE
  9. SQL> alter system set dg_broker_start=true;
  10. System altered.

19、进入broker, 并创建配置信息

  1. $ dgmgrl sys/oracle123@xiaohe_dg1;

创建配置信息并启用:
  1. DGMGRL> CREATE CONFIGURATION c1 AS
  2. PRIMARY DATABASE IS xiaohe
  3. CONNECT IDENTIFIER IS xiaohe_dg1;
  4. DGMGRL> ADD DATABASE xiaohedg
  5. AS CONNECT IDENTIFIER IS xiaohe_dg2;

  6. DGMGRL> ENABLE CONFIGURATION;

查看配置信息:
  1. DGMGRL> show configuration;
  2. Configuration - c1
  3. Protection Mode: MaxPerformance
  4. Databases:
  5. xiaohe - Primary database
  6. xiaohedg - Physical standby database
  7. Fast-Start Failover: DISABLED
  8. Configuration Status:
  9. SUCCESS
查看详细信息:
  1. DGMGRL> show configuration verbose;
  2. Configuration - c1
  3. Protection Mode: MaxPerformance
  4. Databases:
  5. xiaohe - Primary database
  6. xiaohedg - Physical standby database
  7. Properties:
  8. FastStartFailoverThreshold = '30'
  9. OperationTimeout = '30'
  10. FastStartFailoverLagLimit = '30'
  11. CommunicationTimeout = '180'
  12. FastStartFailoverAutoReinstate = 'TRUE'
  13. FastStartFailoverPmyShutdown = 'TRUE'
  14. BystandersFollowRoleChange = 'ALL'
  15. Fast-Start Failover: DISABLED
  16. Configuration Status:
  17. SUCCESS
  18. DGMGRL>



帮助信息如下:
  1. DGMGRL> help create;
  2. Creates a broker configuration
  3. Syntax:
  4. CREATE CONFIGURATION <configuration name> AS
  5. PRIMARY DATABASE IS <database name>
  6. CONNECT IDENTIFIER IS <connect identifier>;
  7. DGMGRL> help add;
  8. Adds a standby database to the broker configuration
  9. Syntax:
  10. ADD DATABASE <database name>
  11. [AS CONNECT IDENTIFIER IS <connect identifier>]
  12. [MAINTAINED AS {PHYSICAL|LOGICAL}];
  13. DGMGRL> help enable;
  14. Enables a configuration, a database, or fast-start failover
  15. Syntax:
  16. ENABLE CONFIGURATION;
  17. ENABLE DATABASE <database name>;
  18. ENABLE FAST_START FAILOVER [CONDITION <condition>];
  19. DGMGRL>


20、打开备库

(1)、关闭备库
(2)、打开备库
  1. shutdown immediate
  2. startup open read only;

查看mode信息:
select open_mode from v$database;

21、打开备库的闪回创建测试库

(1)、将备库重启到mount状态
(2)、开启闪回
  1. SQL> select flashback_on from v$database;
  2. FLASHBACK_ON
  3. ------------------
  4. NO
  5. SQL> shutdown immediate;
  6. SQL> startup mount;
  7. SQL> alter database flashback on;
  8. SQL> select flashback_on from v$database;
  9. FLASHBACK_ON
  10. ------------------
  11. YES

  12. SQL> alter database open;

  13. SQL> select open_mode from v$database; OPEN_MODE
    --------------------
    READ ONLY

  14. SQL> select open_mode from v$database; OPEN_MODE
    --------------------
    READ ONLY WITH APPLY

(3)、在broker下面切换
  1. DGMGRL> help convert;
  2. Converts a database from one type to another
  3. Syntax:
  4. CONVERT DATABASE <database name> TO
  5. {SNAPSHOT STANDBY|PHYSICAL STANDBY};
  6. DGMGRL> CONVERT DATABASE xiaohedg TO SNAPSHOT STANDBY;
  7. Converting database "xiaohedg" to a Snapshot Standby database, please wait...
  8. Database "xiaohedg" converted successfully
  9. DGMGRL> show configuration;
  10. Configuration - c1
  11. Protection Mode: MaxPerformance
  12. Databases:
  13. xiaohe - Primary database
  14. xiaohedg - Snapshot standby database
  15. Fast-Start Failover: DISABLED
  16. Configuration Status:
  17. SUCCESS

(4)、在备库当做测试库读写操作
查看备库已经可以读写了:
  1. SQL> select open_mode from v$database;
  2. OPEN_MODE
  3. --------------------
  4. READ WRITE

建表插入数据等操作:
  1. SQL> create table test(id number, name varchar2(20));
  2. SQL> insert into test values(1, 'node');
  3. SQL> commit;
  4. SQL> select * from test;
  5. ID NAME
  6. ---------- --------------------
  7. 1 node

(5)、将备库从快照切换为物理standby
  1. DGMGRL> CONVERT DATABASE xiaohedg TO PHYSICAL STANDBY;
  2. Converting database "xiaohedg" to a Physical Standby database, please wait...
  3. Operation requires shutdown of instance "xiaohedg" on database "xiaohedg"
  4. Shutting down instance "xiaohedg"...
  5. Database closed.
  6. Database dismounted.
  7. ....

(6)、备库在快照状态下的数据全部丢失


22、主备库切换

  1. DGMGRL> show configuration;
  2. Configuration - c1
  3. Protection Mode: MaxPerformance
  4. Databases:
  5. xiaohe - Primary database
  6. xiaohedg - Physical standby database
  7. Fast-Start Failover: DISABLED
  8. Configuration Status:
  9. SUCCESS
  10. DGMGRL> switchover to xiaohedg;
  11. Performing switchover NOW, please wait...
  12. New primary database "xiaohedg" is opening...
  13. Operation requires shutdown of instance "xiaohe" on database "xiaohe"
  14. Shutting down instance "xiaohe"...
  15. ORACLE instance shut down.
  16. Operation requires startup of instance "xiaohe" on database "xiaohe"
  17. Starting instance "xiaohe"...
  18. ORACLE instance started.
  19. Database mounted.
  20. Database opened.
  21. Switchover succeeded, new primary is "xiaohedg"
  22. DGMGRL>
  23. DGMGRL> show configuration;
  24. Configuration - c1
  25. Protection Mode: MaxPerformance
  26. Databases:
  27. xiaohedg - Primary database
  28. xiaohe - Physical standby database
  29. Fast-Start Failover: DISABLED
  30. Configuration Status:
  31. SUCCESS



23、几个有用的视图

(1)、主库
  1. SQL> select sequence#,applied from v$archived_log order by 1 desc;
  2. SEQUENCE# APPLIED
  3. ---------- ---------
  4. 79 NO
  5. 79 NO
  6. 78 YES
  7. 78 NO
  8. 77 NO
  9. 77 YES
  10. 76 YES
做一次日志切换后:
  1. SQL> alter system switch logfile;
  2. System altered.
  3. SQL> select sequence#,applied from v$archived_log order by 1 desc;
  4. SEQUENCE# APPLIED
  5. ---------- ---------
  6. 80 NO
  7. 80 NO
  8. 79 YES
  9. 79 NO
  10. 78 YES
  11. 78 NO
  12. 77 YES

  1. SQL> select dest_id,error from v$archive_dest;
  2. DEST_ID ERROR
  3. ---------- -----------------------------------------------------------------
  4. 1
  5. 2
  6. 3
  7. 4

  1. SQL> select database_role,open_mode from v$database;
  2. DATABASE_ROLE OPEN_MODE
  3. ---------------- --------------------
  4. PRIMARY READ WRITE


(2)、备库
  1. SQL> select sequence#,status from v$standby_log;
  2. SEQUENCE# STATUS
  3. ---------- ----------
  4. 80 ACTIVE
  5. 0 UNASSIGNED
  6. 0 UNASSIGNED
  7. 0 UNASSIGNED

  1. SQL> set lines 200
  2. SQL> col DATABASE_ROLE for a30;
  3. SQL> select database_role,open_mode from v$database;
  4. DATABASE_ROLE OPEN_MODE
  5. ------------------------------ --------------------
  6. PHYSICAL STANDBY READ ONLY WITH APPLY

  1. SQL> select process,status from v$managed_standby;
  2. PROCESS STATUS
  3. --------- ------------
  4. ARCH CLOSING
  5. ARCH CONNECTED
  6. ARCH CONNECTED
  7. ARCH CONNECTED
  8. MRP0 APPLYING_LOG
  9. RFS IDLE
  10. RFS IDLE
  11. RFS IDLE
  12. 8 rows selected.













基于RMAN搭建DataGuard,使用Broker管理DataGuard的更多相关文章

  1. (摘)DataGuard物理standby管理 - 主备切换

    DataGuard物理standby管理 - 主备切换 Dataguard的切换分为两种,switchover和failover. switchover一般用于数据库或硬件升级,这时只需要较短时间中断 ...

  2. Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架

    Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了 Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Ne ...

  3. broker监控dataguard配置

    使用broker查看dataguard信息时有告警 DGMGRL> show configuration; Configuration - DRTEST Protection Mode: Max ...

  4. 第二篇 基于.net搭建热插拔式web框架(沙箱的构建)

    上周五写了一个实现原理篇,在评论中看到有朋友也遇到了我的问题,真的是有种他乡遇知己的感觉,整个系列我一定会坚持写完,并在最后把代码开源到git中.上一篇文章很多人看了以后,都表示不解,觉得不知道我到底 ...

  5. 基于.net搭建热插拔式web框架(实现原理)

    第一节:我们为什么需要一个热插拔式的web框架? 模块之间独立开发 假设我们要做一个后台管理系统,其中包括“用户活跃度”.“产品管理”."账单管理"等模块.每个模块中有自己的业务特 ...

  6. 基于RMAN从活动数据库异机克隆(rman duplicate from active DB)

    Oracle 11g RMAN能够实现基于活动数据库进行异机克隆,从而省去需要先备份再ftp到辅助服务器的过程.这一切可以全部交给Oracle来搞定.在克隆期间,Oracle会读取Target DB的 ...

  7. 基于RMAN的异机数据库克隆(rman duplicate)

    对于基于生产环境下的数据库的版本升级或者测试新的应用程序的性能及其影响,备份恢复等等,我们可以采取从生产环境以克隆的方式将其克隆到本地而不影响生产数据库的正常使用.实现这个功能我们可以借助rman d ...

  8. Oracle 基于 RMAN 的不完全恢复(incomplete recovery by RMAN)

    Oracle 数据库可以实现数据库不完全恢复与完全恢复.完全恢复是将数据库恢复到最新时刻,也就是无损恢复,保证数据库无丢失的恢复.而不完全恢复则是根据需要特意将数据库恢复到某个过去的特定时间点或特定的 ...

  9. 分享一下我的部分毕设内容:基于Windows Phone平台的污染源管理应用

    原文:分享一下我的部分毕设内容:基于Windows Phone平台的污染源管理应用 毕业半年,又总结了一下之前的工作,发现很多知识不复习都忘记了.最近新闻总是报道北京的空气污染,各种雾霾,各种PM X ...

随机推荐

  1. Apache性能测试工具ab使用详解~转载

    Apache自带性能测试工具ab使用详解 一. Apache的下载 1. http://www.apache.org/,进入Apache的官网 2. 将页面拖到最下方“Apache Project L ...

  2. Spring中的循环依赖解决详解

    前言 说起Spring中循环依赖的解决办法,相信很多园友们都或多或少的知道一些,但当真的要详细说明的时候,可能又没法一下将它讲清楚.本文就试着尽自己所能,对此做出一个较详细的解读.另,需注意一点,下文 ...

  3. java中Long类型和long类型的大小比较

    在开发过程中老犯一些低级错误,基础还得好好加强啊...... 今天遇到这样一个问题,我用 "=="来比较两个Long类型的数据,明明数值都相等,可是结果就是false,后来仔细想想 ...

  4. 启xin宝app的token算法破解——逆向篇(二)

    启xin宝app的token算法破解--抓包分析篇(一)文章已经对该app进行了抓包分析,现在继续对它进行逆向. 对于一个app而言,我们要逆向app,需要知道什么呢? 逆向工具 Java基础,甚至c ...

  5. keras的get_value运行越来越慢的问题解决

    https://blog.csdn.net/mingshili/article/details/81941677?utm_source=blogxgwz5

  6. Java 从入门到进阶之路(四)

    之前的文章我们介绍了 Java 的运算符和表达式,本章我们来看一下 Java 的循环结构. 循环是程序设计语言中反复执行某些代码的一种计算机处理过程,是一组相同或相似语句被有规律的重复性进行. 循环的 ...

  7. ajax调用免费的天气API

    最近在做项目中要用到调用天气接口,在网上找了很多资料之后发现https://www.tianqiapi.com/的天气API挺好的,好用而且免费,调用也很简单.在此做个笔记,大家一起学习交流,如有问题 ...

  8. unity_小功能实现(碰撞检测)

    1.触发器Trigger:勾选IsTrigger属性 //当player刚进入触发区域的时刻发生触发检测,比如在靠近门的某个区域门一直处于开着状态 void OnTriggerEnter(Collid ...

  9. C++ 并发编程之互斥锁和条件变量的性能比较

    介绍 本文以最简单生产者消费者模型,通过运行程序,观察该进程的cpu使用率,来对比使用互斥锁 和 互斥锁+条件变量的性能比较. 本例子的生产者消费者模型,1个生产者,5个消费者. 生产者线程往队列里放 ...

  10. 2. Sentinel源码分析—Sentinel是如何进行流量统计的?

    这一篇我还是继续上一篇没有讲完的内容,先上一个例子: private static final int threadCount = 100; public static void main(Strin ...