ORACLE之搭建DG(ADG方式)

本文详细介绍如何在两个Linux虚拟机上搭建Oracle Active Data Guard (ADG),包括准备工作、主库配置、备库创建及验证同步效果等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录(?)[+]

1.准备工作

        首先得准备两个能够PING通,并且装了Oracle软件且已经建库的Linux虚拟机。操作系统不限,至少有一个虚拟机已经建好库,最好两个都建好相同SID的库,这样少很多创建目录的麻烦,这里库的SID都是orcl,Linux严格区分大小写,所以SID的大小写得注意。

        我这里有两个名为PD和ST的Linux虚拟机。

        PD:192.168.56.42(主库)

        ST:192.168.56.43(备库)

2.在主库做一些操作

    2.1强制force logging

  1. SQL> shutdown immediate  
  2. Database closed.  
  3. Database dismounted.  
  4. ORACLE instance shut down.  
  5. SQL> startup mount  
  6. ORACLE instance started.  
  7.   
  8.   
  9. Total System Global Area 1653518336 bytes  
  10. Fixed Size          2253784 bytes  
  11. Variable Size        1006636072 bytes  
  12. Database Buffers      637534208 bytes  
  13. Redo Buffers            7094272 bytes  
  14. Database mounted.  
  15. SQL> alter database force logging;    --修改数据库为强制记日志,这是必须的操作,主库的每一步操作都得记录到日志中去。  
  16.   
  17. Database altered.  

    2.2开启主库的归档模式

  1. SQL> alter database archivelog;       --修改数据库为归档模式,因为dg是通过传送归档日志到备库然后应用来保证主备库一致的。  
  2.   
  3. Database altered.  

    2.3创建standby redo log

  1. SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/orcl/redo04.log'size 50M;   
  2. Database altered.  
  3.   
  4. SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/orcl/redo05.log'size 50M;   
  5. Database altered.  
  6.   
  7. SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/app/oracle/oradata/orcl/redo06.log'size 50M;   
  8. Database altered.  
  9.   
  10. SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/app/oracle/oradata/orcl/redo07.log'size 50M;  
  11.   
  12. Database altered.  
  1. SQL> select group#,type,member from v$logfile;  
  2.   
  3.   
  4.     GROUP# TYPE    MEMBER  
  5. ---------- ------- --------------------------------------------------  
  6.          3 ONLINE  /u01/app/oracle/oradata/orcl/redo03.log  
  7.          2 ONLINE  /u01/app/oracle/oradata/orcl/redo02.log  
  8.          1 ONLINE  /u01/app/oracle/oradata/orcl/redo01.log  
  9.          4 STANDBY  /u01/app/oracle/oradata/orcl/redo04.log  
  10.          5 STANDBY  /u01/app/oracle/oradata/orcl/redo05.log  
  11.          6 STANDBY  /u01/app/oracle/oradata/orcl/redo06.log  
  12.          7 STANDBY  /u01/app/oracle/oradata/orcl/redo07.log  

    2.4创建pfile

  1. SQL> create pfile from spfile;--这里创建pfile是为了做一些主库参数的配置,并且还得拷贝到备库再次修改成备库的配置。  
  2.   
  3. File created.  
  4.   
  5. SQL> shutdown immediate  
  6. Database closed.  
  7. Database dismounted.  
  8. ORACLE instance shut down.  

    2.5创建主库归档目录

  1. [oracle@PD orcl]$ mkdir archivelog  --建立这个目录是为了存放主库的归档日志文件,并且这个目录会和其他数据文件等等一起拷贝到备库。  
  2. [oracle@PD orcl]$ cd archivelog/  
  3. [oracle@PD archivelog]$ ls  
  4. [oracle@PD archivelog]$ pwd  
  5. /u01/app/oracle/oradata/orcl/archivelog  

    2.6在主备库同时创建静态监听listener和tnsname

建议用net manager建立

主库orcl_pd:192.168.56.42

  1. [oracle@PD admin]$ cat listener.ora   
  2. # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  3. # Generated by Oracle configuration tools.  
  4.   
  5. SID_LIST_LISTENER =  
  6.   (SID_LIST =  
  7.     (SID_DESC =  
  8.       (GLOBAL_DBNAME = orcl)  
  9.       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)  
  10.       (SID_NAME = orcl)  
  11.     )  
  12.   )  
  13.   
  14. LISTENER =  
  15.   (DESCRIPTION_LIST =  
  16.     (DESCRIPTION =  
  17.       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  
  18.     )  
  19.     (DESCRIPTION =  
  20.       (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
  21.     )  
  22.   )  
  23.   
  24. ADR_BASE_LISTENER = /u01/app/oracle  
  1. [oracle@PD admin]$ cat tnsnames.ora   
  2. # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora  
  3. # Generated by Oracle configuration tools.  
  4.   
  5. ORCL_ST =  
  6.   (DESCRIPTION =  
  7.     (ADDRESS_LIST =  
  8.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.43)(PORT = 1521))  
  9.     )  
  10.     (CONNECT_DATA =  
  11.       (SERVICE_NAME = orcl)  
  12.     )  
  13.   )  
  14.   
  15. ORCL =  
  16.   (DESCRIPTION =  
  17.     (ADDRESS_LIST =  
  18.       (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
  19.     )  
  20.     (CONNECT_DATA =  
  21.       (SERVER = DEDICATED)  
  22.       (SERVICE_NAME = orcl)  
  23.     )  
  24.   )  
  25.   
  26. ORCL_PD =  
  27.   (DESCRIPTION =  
  28.     (ADDRESS_LIST =  
  29.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.42)(PORT = 1521))  
  30.     )  
  31.     (CONNECT_DATA =  
  32.       (SERVICE_NAME = orcl)  
  33.     )  
  34.   )  
  1. [oracle@PD orcl]$ lsnrctl  
  2.   
  3. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-MAR-2016 00:59:09  
  4.   
  5. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  6.   
  7. Welcome to LSNRCTL, type "help" for information.  
  8.   
  9. LSNRCTL> status  
  10. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
  11. TNS-12541: TNS:no listener  
  12.  TNS-12560: TNS:protocol adapter error  
  13.   TNS-00511: No listener  
  14.    Linux Error: 111: Connection refused  
  15. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))  
  16. TNS-12541: TNS:no listener  
  17.  TNS-12560: TNS:protocol adapter error  
  18.   TNS-00511: No listener  
  19.    Linux Error: 111: Connection refused  
  20. LSNRCTL> start  
  21. Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...  
  22.   
  23. TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  24. System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  25. Log messages written to /u01/app/oracle/diag/tnslsnr/PD/listener/alert/log.xml  
  26. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  27. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=PD)(PORT=1521)))  
  28.   
  29.   
  30. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
  31. STATUS of the LISTENER  
  32. ------------------------  
  33. Alias                     LISTENER  
  34. Version                    TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  35. Start Date                  21-MAR-2016 00:59:16  
  36. Uptime                    0 days 0 hr. 0 min. 0 sec  
  37. Trace Level                  off  
  38. Security                   ONLocal OS Authentication  
  39. SNMP                      OFF  
  40. Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  41. Listener Log File         /u01/app/oracle/diag/tnslsnr/PD/listener/alert/log.xml  
  42. Listening Endpoints Summary...  
  43.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  44.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=PD)(PORT=1521)))  
  45. Services Summary...  
  46. Service "orcl" has 1 instance(s).  
  47.   Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
  48. The command completed successfully  
  49. LSNRCTL> exit  

备库orcl_pd:192.168.56.43

  1. [oracle@ST admin]$ cat listener.ora   
  2. # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  3. # Generated by Oracle configuration tools.  
  4.   
  5. SID_LIST_LISTENER =  
  6.   (SID_LIST =  
  7.     (SID_DESC =  
  8.       (GLOBAL_DBNAME = orcl)  
  9.       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)  
  10.       (SID_NAME = orcl)  
  11.     )  
  12.   )  
  13.   
  14. LISTENER =  
  15.   (DESCRIPTION_LIST =  
  16.     (DESCRIPTION =  
  17.       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  
  18.     )  
  19.     (DESCRIPTION =  
  20.       (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
  21.     )  
  22.   )  
  23.   
  24. ADR_BASE_LISTENER = /u01/app/oracle  
  1. [oracle@ST admin]$ cat tnsnames.ora   
  2. # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora  
  3. # Generated by Oracle configuration tools.  
  4.   
  5. ORCL_ST =  
  6.   (DESCRIPTION =  
  7.     (ADDRESS_LIST =  
  8.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.43)(PORT = 1521))  
  9.     )  
  10.     (CONNECT_DATA =  
  11.       (SERVICE_NAME = orcl)  
  12.     )  
  13.   )  
  14.   
  15. ORCL =  
  16.   (DESCRIPTION =  
  17.     (ADDRESS_LIST =  
  18.       (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
  19.     )  
  20.     (CONNECT_DATA =  
  21.       (SERVER = DEDICATED)  
  22.       (SERVICE_NAME = orcl)  
  23.     )  
  24.   )  
  25.   
  26. ORCL_PD =  
  27.   (DESCRIPTION =  
  28.     (ADDRESS_LIST =  
  29.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.42)(PORT = 1521))  
  30.     )  
  31.     (CONNECT_DATA =  
  32.       (SERVICE_NAME = orcl)  
  33.     )  
  34.   )  
  1. [oracle@ST dbs]$ lsnrctl  
  2.   
  3. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 19-MAR-2016 21:10:49  
  4.   
  5. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  6.   
  7. Welcome to LSNRCTL, type "help" for information.  
  8.   
  9. LSNRCTL> status  
  10. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
  11. TNS-12541: TNS:no listener  
  12.  TNS-12560: TNS:protocol adapter error  
  13.   TNS-00511: No listener  
  14.    Linux Error: 2: No such file or directory  
  15. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))  
  16. TNS-12541: TNS:no listener  
  17.  TNS-12560: TNS:protocol adapter error  
  18.   TNS-00511: No listener  
  19.    Linux Error: 111: Connection refused  
  20. LSNRCTL> start  
  21. Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...  
  22.   
  23.   
  24. TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  25. System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  26. Log messages written to /u01/app/oracle/diag/tnslsnr/ST/listener/alert/log.xml  
  27. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  28. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ST)(PORT=1521)))  
  29.   
  30. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
  31. STATUS of the LISTENER  
  32. ------------------------  
  33. Alias                     LISTENER  
  34. Version                    TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  35. Start Date                  19-MAR-2016 21:10:53  
  36. Uptime                    0 days 0 hr. 0 min. 0 sec  
  37. Trace Level                  off  
  38. Security                   ONLocal OS Authentication  
  39. SNMP                      OFF  
  40. Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  41. Listener Log File         /u01/app/oracle/diag/tnslsnr/ST/listener/alert/log.xml  
  42. Listening Endpoints Summary...  
  43.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  44.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ST)(PORT=1521)))  
  45. Services Summary...  
  46. Service "orcl" has 1 instance(s).  
  47.   Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
  48. The command completed successfully  

    2.7修改主库pfile文件

  1. [oracle@PD dbs]$ vi initorcl.ora   
  2. orcl.__db_cache_size=637534208  
  3. orcl.__java_pool_size=16777216  
  4. orcl.__large_pool_size=83886080  
  5. orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment  
  6. orcl.__pga_aggregate_target=671088640  
  7. orcl.__sga_target=989855744  
  8. orcl.__shared_io_pool_size=0  
  9. orcl.__shared_pool_size=234881024  
  10. orcl.__streams_pool_size=0  
  11. *.audit_file_dest='/u01/app/oracle/admin/orcl/adump'  
  12. *.audit_trail='db'  
  13. *.compatible='11.2.0.4.0'  
  14. *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'  
  15. *.db_block_size=8192  
  16. *.db_domain=''  
  17. *.db_name='orcl'  
  18. *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'  
  19. *.db_recovery_file_dest_size=4385144832  
  20. *.diagnostic_dest='/u01/app/oracle'  
  21. *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'  
  22. *.memory_target=1657798656  
  23. *.open_cursors=300  
  24. *.processes=150  
  25. *.remote_login_passwordfile='EXCLUSIVE'  
  26. *.undo_tablespace='UNDOTBS1'  
  27. --下面这个是为了搭建DG添加的配置参数,主备库是有区分的,请注意  
  28. DB_UNIQUE_NAME=orcl_pd  
  29. LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'  
  30. LOG_ARCHIVE_DEST_1=  
  31.  'LOCATION=/u01/app/oracle/oradata/orcl/archivelog  
  32.   VALID_FOR=(ALL_LOGFILES,ALL_ROLES)  
  33.   DB_UNIQUE_NAME=orcl_pd'  
  34. LOG_ARCHIVE_DEST_2=  
  35.  'SERVICE=orcl_st ASYNC  
  36.   VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  
  37.   DB_UNIQUE_NAME=orcl_st'  
  38. LOG_ARCHIVE_DEST_STATE_1=ENABLE  
  39. LOG_ARCHIVE_DEST_STATE_2=ENABLE  
  40. REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE  
  41. LOG_ARCHIVE_FORMAT=%t_%s_%r.arc  
  42. FAL_SERVER=orcl_st  
  43. STANDBY_FILE_MANAGEMENT=AUTO  

    2.8用pfile启动主库,并创建spfile

  1. SQL> shutdown immediate  
  2. ORA-01109: database not open  
  3.   
  4.   
  5. Database dismounted.  
  6. ORACLE instance shut down.  
  7. SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'  
  8. ORACLE instance started.  
  9.   
  10. Total System Global Area 1653518336 bytes  
  11. Fixed Size          2253784 bytes  
  12. Variable Size        1006636072 bytes  
  13. Database Buffers      637534208 bytes  
  14. Redo Buffers            7094272 bytes  
  15. SQL> create spfile from pfile;  
  16.   
  17. File created.  

    2.9创建主备库的备份目录

主库
  1. [oracle@PD orcl]$ mkdir /u01/app/oracle/oradata/orcl/backup  
备库
  1. [oracle@PD orcl]$ mkdir /u01/app/oracle/oradata/orcl/backup  

    2.10将口令验证文件和pfile发送到备库

  1. <pre name="code" class="sql">[oracle@PD dbs]$ pwd  
  2. /u01/app/oracle/product/11.2.0/dbhome_1/dbs  
  3. [oracle@PD dbs]$ scp orapworcl 192.168.56.43:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/  
  4. oracle@192.168.56.43's password:   
  5. orapworcl                                                                                        100% 1536     1.5KB/s   00:00      
  6. [oracle@PD dbs]$ scp initorcl.ora 192.168.56.43:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/  
  7. oracle@192.168.56.43's password:   
  8. initorcl.ora                                                                             100% 1408    1.4KB/s  00:00  

3.在主库做一些操作

    3.1在备库修改从主库拷贝来的pfile

  1. [oracle@ST dbs]$ cat initorcl.ora   
  2. orcl.__db_cache_size=637534208  
  3. orcl.__java_pool_size=16777216  
  4. orcl.__large_pool_size=83886080  
  5. orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment  
  6. orcl.__pga_aggregate_target=671088640  
  7. orcl.__sga_target=989855744  
  8. orcl.__shared_io_pool_size=0  
  9. orcl.__shared_pool_size=234881024  
  10. orcl.__streams_pool_size=0  
  11. *.audit_file_dest='/u01/app/oracle/admin/orcl/adump'  
  12. *.audit_trail='db'  
  13. *.compatible='11.2.0.4.0'  
  14. *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'  
  15. *.db_block_size=8192  
  16. *.db_domain=''  
  17. *.db_name='orcl'  
  18. *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'  
  19. *.db_recovery_file_dest_size=4385144832  
  20. *.diagnostic_dest='/u01/app/oracle'  
  21. *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'  
  22. *.memory_target=1657798656  
  23. *.open_cursors=300  
  24. *.processes=150  
  25. *.remote_login_passwordfile='EXCLUSIVE'  
  26. *.undo_tablespace='UNDOTBS1'  
  27.   
  28. DB_UNIQUE_NAME=orcl_st  
  29. LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'  
  30. LOG_ARCHIVE_DEST_1=  
  31.  'LOCATION=/u01/app/oracle/oradata/orcl/archivelog  
  32.   VALID_FOR=(ALL_LOGFILES,ALL_ROLES)  
  33.   DB_UNIQUE_NAME=orcl_st'  
  34. LOG_ARCHIVE_DEST_2=  
  35.  'SERVICE=orcl_pd ASYNC  
  36.   VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)   
  37.   DB_UNIQUE_NAME=orcl_pd'  
  38. LOG_ARCHIVE_DEST_STATE_1=ENABLE  
  39. LOG_ARCHIVE_DEST_STATE_2=ENABLE  
  40. REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE  
  41. LOG_ARCHIVE_FORMAT=%t_%s_%r.arc  
  42. FAL_SERVER=orcl_pd  
  43. STANDBY_FILE_MANAGEMENT=AUTO  

    3.2启动备库到nomount

  1. [oracle@ST dbs]$ sqlplus / as sysdba  
  2.   
  3. SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 16:52:07 2016  
  4.   
  5. Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  6.   
  7. Connected to an idle instance.  
  8.   
  9. SQL> startup nomount  
  10. ORACLE instance started.  
  11.   
  12. Total System Global Area 1653518336 bytes  
  13. Fixed Size          2253784 bytes  
  14. Variable Size        1006636072 bytes  
  15. Database Buffers      637534208 bytes  
  16. Redo Buffers            7094272 bytes  
  17. SQL>   
3.3开始使用RMAN进行ADG
  1. [oracle@ST dbs]$ sqlplus / as sysdba  
  2.   
  3. SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 17:26:13 2016  
  4.   
  5. Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  6.   
  7. Connected to an idle instance.  
  8.   
  9. SQL> startup nomount  
  10. ORACLE instance started.  
  11.   
  12. Total System Global Area 1653518336 bytes  
  13. Fixed Size          2253784 bytes  
  14. Variable Size        1006636072 bytes  
  15. Database Buffers      637534208 bytes  
  16. Redo Buffers            7094272 bytes  
  17. SQL> exit  
  18. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production  
  19. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  20. [oracle@ST dbs]$ rman target sys/sys@orcl_pd auxiliary sys/sys@orcl_st  
  21.   
  22. Recovery Manager: Release 11.2.0.4.0 - Production on Wed Mar 23 17:26:33 2016  
  23.   
  24. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  
  25.   
  26. connected to target database: ORCL (DBID=1434698509)  
  27. connected to auxiliary database: ORCL (not mounted)  
  28.   
  29. RMAN> duplicate target database for standby from active database nofilenamecheck;  
  30.   
  31. Starting Duplicate Db at 23-MAR-16  
  32. using target database control file instead of recovery catalog  
  33. allocated channel: ORA_AUX_DISK_1  
  34. channel ORA_AUX_DISK_1: SID=19 device type=DISK  
  35.   
  36. contents of Memory Script:  
  37. {  
  38.    backup as copy reuse  
  39.    targetfile  '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format   
  40.  '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl'   ;  
  41. }  
  42. executing Memory Script  
  43.   
  44. Starting backup at 23-MAR-16  
  45. allocated channel: ORA_DISK_1  
  46. channel ORA_DISK_1: SID=40 device type=DISK  
  47. Finished backup at 23-MAR-16  
  48.   
  49. contents of Memory Script:  
  50. {  
  51.    backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/oradata/orcl/control01.ctl';  
  52.    restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' from   
  53.  '/u01/app/oracle/oradata/orcl/control01.ctl';  
  54. }  
  55. executing Memory Script  
  56.   
  57. Starting backup at 23-MAR-16  
  58. using channel ORA_DISK_1  
  59. channel ORA_DISK_1: starting datafile copy  
  60. copying standby control file  
  61. output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20160323T172644 RECID=4 STAMP=907262805  
  62. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01  
  63. Finished backup at 23-MAR-16  
  64.   
  65. Starting restore at 23-MAR-16  
  66. using channel ORA_AUX_DISK_1  
  67.   
  68. channel ORA_AUX_DISK_1: copied control file copy  
  69. Finished restore at 23-MAR-16  
  70.   
  71. contents of Memory Script:  
  72. {  
  73.    sql clone 'alter database mount standby database';  
  74. }  
  75. executing Memory Script  
  76.   
  77. sql statement: alter database mount standby database  
  78.   
  79. contents of Memory Script:  
  80. {  
  81.    set newname for tempfile  1 to   
  82.  "/u01/app/oracle/oradata/orcl/temp01.dbf";  
  83.    switch clone tempfile all;  
  84.    set newname for datafile  1 to   
  85.  "/u01/app/oracle/oradata/orcl/system01.dbf";  
  86.    set newname for datafile  2 to   
  87.  "/u01/app/oracle/oradata/orcl/sysaux01.dbf";  
  88.    set newname for datafile  3 to   
  89.  "/u01/app/oracle/oradata/orcl/undotbs01.dbf";  
  90.    set newname for datafile  4 to   
  91.  "/u01/app/oracle/oradata/orcl/users01.dbf";  
  92.    set newname for datafile  5 to   
  93.  "/u01/app/oracle/oradata/orcl/example01.dbf";  
  94.    backup as copy reuse  
  95.    datafile  1 auxiliary format   
  96.  "/u01/app/oracle/oradata/orcl/system01.dbf"   datafile   
  97.  2 auxiliary format   
  98.  "/u01/app/oracle/oradata/orcl/sysaux01.dbf"   datafile   
  99.  3 auxiliary format   
  100.  "/u01/app/oracle/oradata/orcl/undotbs01.dbf"   datafile   
  101.  4 auxiliary format   
  102.  "/u01/app/oracle/oradata/orcl/users01.dbf"   datafile   
  103.  5 auxiliary format   
  104.  "/u01/app/oracle/oradata/orcl/example01.dbf"   ;  
  105.    sql 'alter system archive log current';  
  106. }  
  107. executing Memory Script  
  108.   
  109. executing command: SET NEWNAME  
  110.   
  111. renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file  
  112.   
  113. executing command: SET NEWNAME  
  114.   
  115. executing command: SET NEWNAME  
  116.   
  117. executing command: SET NEWNAME  
  118.   
  119. executing command: SET NEWNAME  
  120.   
  121. executing command: SET NEWNAME  
  122.   
  123. Starting backup at 23-MAR-16  
  124. using channel ORA_DISK_1  
  125. channel ORA_DISK_1: starting datafile copy  
  126. input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf  
  127. output file name=/u01/app/oracle/oradata/orcl/system01.dbf tag=TAG20160323T172653  
  128. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25  
  129. channel ORA_DISK_1: starting datafile copy  
  130. input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf  
  131. output file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf tag=TAG20160323T172653  
  132. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25  
  133. channel ORA_DISK_1: starting datafile copy  
  134. input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf  
  135. output file name=/u01/app/oracle/oradata/orcl/example01.dbf tag=TAG20160323T172653  
  136. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15  
  137. channel ORA_DISK_1: starting datafile copy  
  138. input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf  
  139. output file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf tag=TAG20160323T172653  
  140. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07  
  141. channel ORA_DISK_1: starting datafile copy  
  142. input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf  
  143. output file name=/u01/app/oracle/oradata/orcl/users01.dbf tag=TAG20160323T172653  
  144. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01  
  145. Finished backup at 23-MAR-16  
  146.   
  147. sql statement: alter system archive log current  
  148.   
  149. contents of Memory Script:  
  150. {  
  151.    switch clone datafile all;  
  152. }  
  153. executing Memory Script  
  154.   
  155. datafile 1 switched to datafile copy  
  156. input datafile copy RECID=4 STAMP=907262888 file name=/u01/app/oracle/oradata/orcl/system01.dbf  
  157. datafile 2 switched to datafile copy  
  158. input datafile copy RECID=5 STAMP=907262888 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf  
  159. datafile 3 switched to datafile copy  
  160. input datafile copy RECID=6 STAMP=907262888 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf  
  161. datafile 4 switched to datafile copy  
  162. input datafile copy RECID=7 STAMP=907262888 file name=/u01/app/oracle/oradata/orcl/users01.dbf  
  163. datafile 5 switched to datafile copy  
  164. input datafile copy RECID=8 STAMP=907262888 file name=/u01/app/oracle/oradata/orcl/example01.dbf  
  165. Finished Duplicate Db at 23-MAR-16  
  166.   
  167. RMAN>   

    3.3打开备库并开启apply service

  1. [oracle@ST dbs]$ sqlplus / as sysdba  
  2.   
  3. SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 17:48:47 2016  
  4.   
  5. Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  6.   
  7.   
  8. Connected to:  
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production  
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  11.   
  12. SQL> alter database open;  
  13.   
  14. Database altered.  
  15.   
  16. SQL> select open_mode from v$database;  
  17.   
  18. OPEN_MODE  
  19. --------------------  
  20. READ ONLY  
  21.   
  22. SQL> alter database recover managed standby database disconnect from session;  
  23.   
  24. Database altered.  

4.检验是否成功

主库
  1. SQL> create table Csong(id number(10),name varchar2(20));  
  2.   
  3. Table created.  
  4.   
  5. SQL> insert into Csong values(1,'Csong');  
  6.   
  7. 1 row created.  
  8.   
  9. SQL> insert into Csong values(2,'Lyuanyuan');  
  10.   
  11. 1 row created.  
  12.   
  13. SQL> commit;  
  14.   
  15. Commit complete.  
  16.   
  17. SQL> alter system switch logfile;  
  18.   
  19. System altered.  
  20.   
  21. SQL>   
备库
  1. SQL> desc Csong  
  2.  Name                      Null?    Type  
  3.  ----------------------------------------- -------- ----------------------------  
  4.  ID                         NUMBER(10)  
  5.  NAME                           VARCHAR2(20)  
  6.   
  7. SQL> select * from Csong;  
  8.   
  9.     ID NAME  
  10. ---------- --------------------  
  11.      1 Csong  
  12.      2 Lyuanyuan 
Oracle 12c ADG(Active Data Guard)库是基于Oracle Data Guard技术的一个功能,它能够提供实时的数据库备份和灾难恢复解决方案。下面是Oracle 12c ADG搭建的视频演示。 在搭建Oracle 12c ADG库之前,我们需要确保已经配置好了主数据库和备用数据库,并且它们能够通过网络互相通信。接下来,我们按照以下步骤来完成ADG库的搭建。 1. 在主数据库上,使用SQL Plus连接到数据库实例,执行以下命令创建一个备用数据库初始化参数文件 pfile: ``` SQL> CREATE PFILE='/u01/app/oracle/admin/primary/pfile/initprimary.ora' FROM SPFILE; ``` 2. 在备用数据库上,使用SQL Plus连接到数据库实例,执行以下命令创建一个备用数据库初始化参数文件 pfile: ``` SQL> CREATE PFILE='/u01/app/oracle/admin/standby/pfile/initstandby.ora' FROM SPFILE; ``` 3. 在主数据库上,使用RMAN备份主数据库并将备份传输到备用数据库: ``` RMAN> BACKUP AS COPY DATABASE FORMAT '/u01/app/oracle/backup/%U'; RMAN> RECOVER COPY OF DATABASE WITH TAG 'ADG_COPY'; RMAN> CATALOG START WITH '/u01/app/oracle/backup'; ``` 4. 在主数据库上,修改备用数据库初始化参数文件 pfile,使其指向主数据库备份所在的目录: ``` SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'; ``` 5. 在备用数据库上,修改备用数据库初始化参数文件 pfile,使其指向主数据库的控制文件和redo日志文件: ``` SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'; SQL> ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/primary/','/u01/app/oracle/oradata/standby/'; SQL> ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/u01/app/oracle/flash_recovery_area/primary/','/u01/app/oracle/flash_recovery_area/standby/'; ``` 6. 在主数据库上,使用SQL Plus连接到主数据库实例,启动主数据库的日志传输服务: ``` SQL> ALTER SYSTEM ARCHIVE LOG CURRENT; ``` 7. 在备用数据库上,使用SQL Plus连接到备用数据库实例,执行以下命令启动数据库实例: ``` SQL> STARTUP MOUNT; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; ``` 8. 在备用数据库上,使用SQL Plus连接到备用数据库实例,检查ADG库的状态: ``` SQL> SELECT DATABASE_ROLE FROM V$DATABASE; ``` 以上就是Oracle 12c ADG库的搭建过程。通过配置ADG库,我们可以实现实时的数据库备份和灾难恢复,提高数据库的可用性和数据的安全性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值