• 基于RMAN搭建DataGuard,使用Broker管理DataGuard


    一、环境准备

    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_dg1xiaohexiaohe.com
    备库xiaohe_dg2xiaohedgxiaohe.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.













  • 相关阅读:
    站立会议11(冲刺二)
    站立会议10(冲刺二)
    站立会议09(冲刺二)
    站立会议08(冲刺二)
    每日站立会议(一)
    四则运算--单元测试
    四则运算安卓版
    返回二维数组最大联通子数组的和
    团队项目成员和题目
    第五周学习进度
  • 原文地址:https://www.cnblogs.com/xiaohe001/p/6576679.html
Copyright © 2020-2023  润新知