Oracle 12cR2 Data Guard 搭建(Windows Server 2019 主备一对一 LGWR ASYNC CDB模式)

 admin   2023-05-15 17:03   143 人阅读  0 条评论

1 规划

规划主库备库
数据库版本12.2.0.112.2.0.1
软件情况软件 + ERP数据库仅软件
容器数据库CDBCDB
主机名host01host02
IP地址192.168.1.12192.168.1.13
DB_UNIQUE_NAMEerpdberpdbs
DB_NAMEerpdberpdb
INSTANCE_NAMEerpdberpdbs
Data FilesE:\APP\ADMINISTRATOR\ORADATA\ERPDBE:\APP\ADMINISTRATOR\ORADATA\ERPDB
Log FilesE:\APP\ADMINISTRATOR\ORADATA\ERPDBE:\APP\ADMINISTRATOR\ORADATA\ERPDB
OSWindows Server 2019Windows Server 2019

注意:主库和备库的 DB_NAME 必须一致

2 OS安装及数据库搭建

  • 主库OS安装,请参考 109 文档,注意主机名及IP设置(主)

  • 备库OS安装,请参考 109 文档,注意主机名及IP设置(备无需建库)

3 Data Guard 搭建

3.1 主库配置

3.1.1 主库强制日志

  1. C:\Users\Administrator>set nls_lang=american_america.zhs16gbk

  2. C:\Users\Administrator>sqlplus / as sysdba


  3. SQL> alter database force logging;

3.1.2 主库开启归档

SQL> alter system set db_recovery_file_dest_size=5g;SQL> alter system set db_recovery_file_dest='E:\app\Administrator\archive';SQL> shutdown immediate;SQL> startup mount;SQL> alter database archivelog;SQL> alter database open;

3.1.3 主库创建STANDBY日志组

  1. # SQL> select a.group#,a.sequence#,b.status,a.members,b.member,a.bytes/1024/1024 M from v$log a,v$logfile b where a.group#=b.group# order by a.group#;


  2. alter system set standby_file_management='manual';


  3. alter database add standby logfile group 4 'E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO04.LOG' size 200m;

  4. alter database add standby logfile group 5 'E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO05.LOG' size 200m;

  5. alter database add standby logfile group 6 'E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO06.LOG' size 200m;

  6. alter database add standby logfile group 7 'E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO07.LOG' size 200m;


  7. alter system set standby_file_management='auto';


  8. # SQL> set linesize 200

  9. # SQL> col group# for 99

  10. # SQL> col member for a50

  11. # SQL> select group#,type,member from v$logfile order by group#;


  12. GROUP# TYPE         MEMBER

  13. ------ ----------   ----------------------------------------------

  14.     1 ONLINE       E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO01.LOG

  15.     2 ONLINE       E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO02.LOG

  16.     3 ONLINE       E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO03.LOG

  17.     4 STANDBY      E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO04.LOG

  18.     5 STANDBY      E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO05.LOG

  19.     6 STANDBY      E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO06.LOG

  20.     7 STANDBY      E:\APP\ADMINISTRATOR\ORADATA\ERPDB\REDO07.LOG

3.1.4 主库修改参数文件

  1. # 通过当前动态参数文件(SPFILE)创建静态参数文件(PFILE)

  2. SQL> create pfile from spfile;

  3. # E:\app\Administrator\product\12.2.0\dbhome_1\database

  4. # 修改生成的静态参数文件 INITERPDB.ORA


  5. # 以下是原有参数 #


  6. erpdb.__data_transfer_cache_size=0

  7. erpdb.__db_cache_size=1862270976

  8. erpdb.__inmemory_ext_roarea=0

  9. erpdb.__inmemory_ext_rwarea=0

  10. erpdb.__java_pool_size=16777216

  11. erpdb.__large_pool_size=33554432

  12. erpdb.__oracle_base='E:\app\Administrator'#ORACLE_BASE set from environment

  13. erpdb.__pga_aggregate_target=872415232

  14. erpdb.__sga_target=2583691264

  15. erpdb.__shared_io_pool_size=134217728

  16. erpdb.__shared_pool_size=520093696

  17. erpdb.__streams_pool_size=0

  18. *.audit_file_dest='E:\app\Administrator\admin\erpdb\adump'

  19. *.audit_trail='db'

  20. *.compatible='12.2.0'

  21. *.control_files='E:\app\Administrator\oradata\erpdb\control01.ctl','E:\app\Administrator\oradata\erpdb\control02.ctl'

  22. *.db_block_size=8192

  23. *.db_name='erpdb'

  24. *.db_recovery_file_dest_size=5368709120

  25. *.db_recovery_file_dest='E:\app\Administrator\archive'

  26. *.diagnostic_dest='E:\app\Administrator'

  27. *.dispatchers='(PROTOCOL=TCP) (SERVICE=erpdbXDB)'

  28. *.enable_pluggable_database=true

  29. *.local_listener='LISTENER_ERPDB'

  30. *.nls_language='SIMPLIFIED CHINESE'

  31. *.nls_territory='CHINA'

  32. *.open_cursors=300

  33. *.pga_aggregate_target=819m

  34. *.processes=300

  35. *.remote_login_passwordfile='EXCLUSIVE'

  36. *.sga_target=2457m

  37. *.standby_file_management='auto'

  38. *.undo_tablespace='UNDOTBS1'


  39. # 以下是追加参数 #


  40. DB_UNIQUE_NAME='erpdb'

  41. LOG_ARCHIVE_CONFIG='DG_CONFIG=(erpdb,erpdbs)'

  42. CONTROL_FILES='E:\APP\ADMINISTRATOR\ORADATA\ERPDB\CONTROL01.CTL', 'E:\APP\ADMINISTRATOR\ORADATA\ERPDB\CONTROL02.CTL'

  43. LOG_ARCHIVE_DEST_1= 'LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=erpdb'

  44. LOG_ARCHIVE_DEST_2= 'SERVICE=erpdbs ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=erpdbs'

  45. REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

  46. LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'

  47. FAL_SERVER=erpdbs

  48. DB_FILE_NAME_CONVERT='E:\APP\ADMINISTRATOR\ORADATA\ERPDBS','E:\APP\ADMINISTRATOR\ORADATA\ERPDB'

  49. LOG_FILE_NAME_CONVERT='E:\APP\ADMINISTRATOR\ORADATA\ERPDBS','E:\APP\ADMINISTRATOR\ORADATA\ERPDB'

  50. STANDBY_FILE_MANAGEMENT=AUTO


  51. # 注意 DB_FILE_NAME_CONVERT 和 LOG_FILE_NAME_CONVERT 两个参数,指定位置必须备在前,主在后。

通过新的标准静态参数文件PFILE INITERPDB.ORA 生成新的动态参数文件SPFILE SPFILEERPDB.ORA 并重新启动数据库进行参数加载

SQL> shutdown immediate;SQL> create spfile from pfile;SQL> startup

3.1.5 主库配置TNS

  1. # E:\app\Administrator\product\12.2.0\dbhome_1\network\admin

  2. # 修改 tnsnames.ora

  3. # 主库原有连接字符串,添加备库连接字符串


  4. ERPDBS =

  5.  (DESCRIPTION =

  6.    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.13)(PORT = 1521))

  7.    (CONNECT_DATA =

  8.      (SERVER = DEDICATED)

  9.      (SERVICE_NAME = erpdbs)

  10.    )

  11.  )

3.1.6 主库配置监听(静态)

  1. # C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN

  2. # 修改 listener.ora

  3. # 在 SID_LIST 标签中添加以下描述信息


  4. (SID_DESC=

  5.    (GLOBAL_DBNAME=erpdb)

  6.    (SID_NAME=erpdb)            

  7.    (ORACLE_HOME=E:\app\Administrator\product\12.2.0\dbhome_1)

  8. )


  9. # 主库修改后内容


  10. SID_LIST_LISTENER =

  11.  (SID_LIST =

  12.    (SID_DESC =

  13.      (SID_NAME = CLRExtProc)

  14.      (ORACLE_HOME = E:\app\Administrator\product\12.2.0\dbhome_1)

  15.      (PROGRAM = extproc)

  16.      (ENVS = "EXTPROC_DLLS=ONLY:E:\app\Administrator\product\12.2.0\dbhome_1\bin\oraclr12.dll")

  17.    )

  18.    (SID_DESC=

  19.        (GLOBAL_DBNAME=erpdb)

  20.        (SID_NAME=erpdb)            

  21.        (ORACLE_HOME=E:\app\Administrator\product\12.2.0\dbhome_1)

  22.    )

  23.  )


  24. LISTENER =

  25.  (DESCRIPTION_LIST =

  26.    (DESCRIPTION =

  27.      (ADDRESS = (PROTOCOL = TCP)(HOST = host01)(PORT = 1521))

  28.      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

  29.    )

  30.  )


  31. # 重启监听测试连接


  32. # C:\Users\Administrator>lsnrctl stop

  33. # C:\Users\Administrator>lsnrctl start


  34. Service "erpdb" has 1 instance(s).

  35.  Instance "erpdb", status UNKNOWN, has 1 handler(s) for this service...

  36. The command completed successfully


  37. # C:\Users\Administrator>sqlplus sys/oracle@erpdb as sysdba

3.2 备库配置

3.2.1 备库修改参数文件

  1. # 直接拷贝主库静态参数文件 INITERPDB.ORA 到备库并更名 INITERPDBS.ORA

  2. # 备库路径 E:\app\Administrator\product\12.2.0\dbhome_1\database

  3. # 修改备库参数文件 INITERPDB.ORA 参数进行主备互换(注意 db_name 保持一致)


  4. *.audit_file_dest='E:\app\Administrator\admin\erpdbs\adump'

  5. *.audit_trail='db'

  6. *.compatible='12.2.0'

  7. *.control_files='E:\app\Administrator\oradata\erpdbs\control01.ctl','E:\app\Administrator\oradata\erpdbs\control02.ctl'

  8. *.db_block_size=8192

  9. *.db_name='erpdb'

  10. *.db_recovery_file_dest_size=5368709120

  11. *.db_recovery_file_dest='E:\app\Administrator\archive'

  12. *.diagnostic_dest='E:\app\Administrator'

  13. *.dispatchers='(PROTOCOL=TCP) (SERVICE=erpdbsXDB)'

  14. *.enable_pluggable_database=true

  15. *.local_listener='LISTENER_erpdbs'

  16. *.nls_language='SIMPLIFIED CHINESE'

  17. *.nls_territory='CHINA'

  18. *.open_cursors=300

  19. *.pga_aggregate_target=819m

  20. *.processes=300

  21. *.remote_login_passwordfile='EXCLUSIVE'

  22. *.sga_target=2457m

  23. *.standby_file_management='auto'

  24. *.undo_tablespace='UNDOTBS1'

  25. DB_UNIQUE_NAME='erpdbs'

  26. LOG_ARCHIVE_CONFIG='DG_CONFIG=(erpdbs,erpdb)'

  27. CONTROL_FILES='E:\APP\ADMINISTRATOR\ORADATA\erpdbs\CONTROL01.CTL', 'E:\APP\ADMINISTRATOR\ORADATA\erpdbs\CONTROL02.CTL'

  28. LOG_ARCHIVE_DEST_1= 'LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=erpdbs'

  29. LOG_ARCHIVE_DEST_2= 'SERVICE=erpdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=erpdb'

  30. REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

  31. LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'

  32. FAL_SERVER=erpdb

  33. DB_FILE_NAME_CONVERT='E:\APP\ADMINISTRATOR\ORADATA\erpdb','E:\APP\ADMINISTRATOR\ORADATA\erpdbs'

  34. LOG_FILE_NAME_CONVERT='E:\APP\ADMINISTRATOR\ORADATA\erpdb','E:\APP\ADMINISTRATOR\ORADATA\erpdbs'

  35. STANDBY_FILE_MANAGEMENT=AUTO


  36. # 创建对应目录


  37. E:\app\Administrator\admin\erpdbs

  38. E:\app\Administrator\admin\erpdbs\adump

  39. E:\app\Administrator\oradata\erpdbs

  40. E:\app\Administrator\archive

3.2.2 备库配置TNS

  1. # 可直接拷贝主库内容,也可以通过 Net Manager 工具进行创建

  2. # E:\app\Administrator\product\12.2.0\dbhome_1\network\admin

  3. # 修改 tnsnames.ora


  4. ERPDB =

  5.  (DESCRIPTION =

  6.    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.12)(PORT = 1521))

  7.    (CONNECT_DATA =

  8.      (SERVER = DEDICATED)

  9.      (SERVICE_NAME = erpdb)

  10.    )

  11.  )


  12. ERPDBS =

  13.  (DESCRIPTION =

  14.    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.13)(PORT = 1521))

  15.    (CONNECT_DATA =

  16.      (SERVER = DEDICATED)

  17.      (SERVICE_NAME = erpdbs)

  18.    )

  19.  )


  20. # 尝试在备库通过连接字符串登录主库

  21. # C:\Users\Administrator>sqlplus sys/oracle@erpdb as sysdba

3.2.3 备库配置监听

  1. # 参考主库内容,添加静态监听

  2. # E:\app\Administrator\product\12.2.0\dbhome_1\network\admin

  3. # 修改 listener.ora


  4. SID_LIST_LISTENER =

  5.  (SID_LIST =

  6.    (SID_DESC =

  7.      (SID_NAME = CLRExtProc)

  8.      (ORACLE_HOME = E:\app\Administrator\product\12.2.0\dbhome_1)

  9.      (PROGRAM = extproc)

  10.      (ENVS = "EXTPROC_DLLS=ONLY:E:\app\Administrator\product\12.2.0\dbhome_1\bin\oraclr12.dll")

  11.    )

  12.    (SID_DESC=

  13.        (GLOBAL_DBNAME=erpdbs)

  14.        (SID_NAME=erpdbs)          

  15.        (ORACLE_HOME=E:\app\Administrator\product\12.2.0\dbhome_1)

  16.    )

  17.  )


  18. LISTENER =

  19.  (DESCRIPTION_LIST =

  20.    (DESCRIPTION =

  21.      (ADDRESS = (PROTOCOL = TCP)(HOST = host02)(PORT = 1521))

  22.      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

  23.    )

  24.  )


  25. # 重启监听测试连接


  26. # C:\Users\Administrator>lsnrctl stop

  27. # C:\Users\Administrator>lsnrctl start

3.2.4 备库创建密码文件

  1. # 可直接拷贝主库密码文件 PWDerpdb.ora 并进行更名 PWDerpdbs.ora

  2. # 也可以通过命令创建


  3. C:\Users\Administrator>orapwd file=E:\app\Administrator\product\12.2.0\dbhome_1\database\PWDerpdbs.ora password=oracle entries=20 format=12 force=y

3.2.5 备库手工创建实例

C:\Users\Administrator>oradim -new -sid erpdbsInstance created.

3.3 在线复制创建DG备库

3.3.1 将备库启动到 nomount

  1. C:\Users\Administrator>set nls_lang=american_america.zhs16gbk


  2. C:\Users\Administrator>sqlplus sys/oracle@erpdbs as sysdba


  3. SQL*Plus: Release 12.2.0.1.0 Production on Fri Jun 26 20:23:52 2020


  4. Copyright (c) 1982, 2016, Oracle.  All rights reserved.


  5. Connected to an idle instance.


  6. SQL> startup nomount;

  7. ORACLE instance started.


  8. Total System Global Area 2583691264 bytes

  9. Fixed Size                  8922232 bytes

  10. Variable Size             687868808 bytes

  11. Database Buffers         1879048192 bytes

  12. Redo Buffers                7852032 bytes

3.3.2 在线复制

  1. # 以下命令可在 主库 中执行,也可在 备库 中执行


  2. C:\Users\Administrator>rman target sys/oracle@erpdb auxiliary sys/oracle@erpdbs


  3. Recovery Manager: Release 12.2.0.1.0 - Production on Fri Jun 26 20:26:25 2020


  4. Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.


  5. connected to target database: ERPDB (DBID=193221351)

  6. connected to auxiliary database: ERPDB (not mounted)


  7. RMAN> duplicate target database for standby from active database;


  8. # 过程记录


  9. Starting Duplicate Db at 26-JUN-20

  10. using target database control file instead of recovery catalog

  11. allocated channel: ORA_AUX_DISK_1

  12. channel ORA_AUX_DISK_1: SID=32 device type=DISK


  13. contents of Memory Script:

  14. {

  15.   backup as copy reuse

  16.   targetfile  'E:\app\Administrator\product\12.2.0\dbhome_1\DATABASE\PWDerpdb.ORA' auxiliary format

  17. 'E:\app\Administrator\product\12.2.0\dbhome_1\DATABASE\PWDerpdbs.ORA'   ;

  18. }

  19. executing Memory Script


  20. Starting backup at 26-JUN-20

  21. allocated channel: ORA_DISK_1

  22. channel ORA_DISK_1: SID=23 device type=DISK

  23. Finished backup at 26-JUN-20


  24. contents of Memory Script:

  25. {

  26.   restore clone from service  'erpdb' standby controlfile;

  27. }

  28. executing Memory Script


  29. Starting restore at 26-JUN-20

  30. using channel ORA_AUX_DISK_1


  31. channel ORA_AUX_DISK_1: starting datafile backup set restore

  32. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  33. channel ORA_AUX_DISK_1: restoring control file

  34. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

  35. output file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\CONTROL01.CTL

  36. output file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\CONTROL02.CTL

  37. Finished restore at 26-JUN-20


  38. contents of Memory Script:

  39. {

  40.   sql clone 'alter database mount standby database';

  41. }

  42. executing Memory Script


  43. sql statement: alter database mount standby database


  44. contents of Memory Script:

  45. {

  46.   set newname for tempfile  1 to

  47. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\TEMP01.DBF";

  48.   set newname for tempfile  2 to

  49. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\TEMP012020-06-26_18-02-49-653-PM.DBF";

  50.   set newname for tempfile  3 to

  51. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\TEMP01.DBF";

  52.   switch clone tempfile all;

  53.   set newname for datafile  1 to

  54. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSTEM01.DBF";

  55.   set newname for datafile  2 to

  56. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSTEM01.DBF";

  57.   set newname for datafile  3 to

  58. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSAUX01.DBF";

  59.   set newname for datafile  4 to

  60. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSAUX01.DBF";

  61.   set newname for datafile  5 to

  62. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\UNDOTBS01.DBF";

  63.   set newname for datafile  6 to

  64. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\UNDOTBS01.DBF";

  65.   set newname for datafile  7 to

  66. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\USERS01.DBF";

  67.   set newname for datafile  8 to

  68. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSTEM01.DBF";

  69.   set newname for datafile  9 to

  70. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSAUX01.DBF";

  71.   set newname for datafile  10 to

  72. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\UNDOTBS01.DBF";

  73.   set newname for datafile  11 to

  74. "E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\USERS01.DBF";

  75.   restore

  76.   from  nonsparse   from service

  77. 'erpdb'   clone database

  78.   ;

  79.   sql 'alter system archive log current';

  80. }

  81. executing Memory Script


  82. executing command: SET NEWNAME


  83. executing command: SET NEWNAME


  84. executing command: SET NEWNAME


  85. renamed tempfile 1 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\TEMP01.DBF in control file

  86. renamed tempfile 2 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\TEMP012020-06-26_18-02-49-653-PM.DBF in control file

  87. renamed tempfile 3 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\TEMP01.DBF in control file


  88. executing command: SET NEWNAME


  89. executing command: SET NEWNAME


  90. executing command: SET NEWNAME


  91. executing command: SET NEWNAME


  92. executing command: SET NEWNAME


  93. executing command: SET NEWNAME


  94. executing command: SET NEWNAME


  95. executing command: SET NEWNAME


  96. executing command: SET NEWNAME


  97. executing command: SET NEWNAME


  98. executing command: SET NEWNAME


  99. Starting restore at 26-JUN-20

  100. using channel ORA_AUX_DISK_1


  101. channel ORA_AUX_DISK_1: starting datafile backup set restore

  102. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  103. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  104. channel ORA_AUX_DISK_1: restoring datafile 00001 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSTEM01.DBF

  105. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55

  106. channel ORA_AUX_DISK_1: starting datafile backup set restore

  107. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  108. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  109. channel ORA_AUX_DISK_1: restoring datafile 00002 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSTEM01.DBF

  110. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36

  111. channel ORA_AUX_DISK_1: starting datafile backup set restore

  112. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  113. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  114. channel ORA_AUX_DISK_1: restoring datafile 00003 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSAUX01.DBF

  115. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35

  116. channel ORA_AUX_DISK_1: starting datafile backup set restore

  117. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  118. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  119. channel ORA_AUX_DISK_1: restoring datafile 00004 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSAUX01.DBF

  120. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36

  121. channel ORA_AUX_DISK_1: starting datafile backup set restore

  122. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  123. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  124. channel ORA_AUX_DISK_1: restoring datafile 00005 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\UNDOTBS01.DBF

  125. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35

  126. channel ORA_AUX_DISK_1: starting datafile backup set restore

  127. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  128. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  129. channel ORA_AUX_DISK_1: restoring datafile 00006 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\UNDOTBS01.DBF

  130. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03

  131. channel ORA_AUX_DISK_1: starting datafile backup set restore

  132. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  133. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  134. channel ORA_AUX_DISK_1: restoring datafile 00007 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\USERS01.DBF

  135. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

  136. channel ORA_AUX_DISK_1: starting datafile backup set restore

  137. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  138. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  139. channel ORA_AUX_DISK_1: restoring datafile 00008 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSTEM01.DBF

  140. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36

  141. channel ORA_AUX_DISK_1: starting datafile backup set restore

  142. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  143. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  144. channel ORA_AUX_DISK_1: restoring datafile 00009 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSAUX01.DBF

  145. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25

  146. channel ORA_AUX_DISK_1: starting datafile backup set restore

  147. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  148. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  149. channel ORA_AUX_DISK_1: restoring datafile 00010 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\UNDOTBS01.DBF

  150. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08

  151. channel ORA_AUX_DISK_1: starting datafile backup set restore

  152. channel ORA_AUX_DISK_1: using network backup set from service erpdb

  153. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

  154. channel ORA_AUX_DISK_1: restoring datafile 00011 to E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\USERS01.DBF

  155. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

  156. Finished restore at 26-JUN-20


  157. sql statement: alter system archive log current


  158. contents of Memory Script:

  159. {

  160.   switch clone datafile all;

  161. }

  162. executing Memory Script


  163. datafile 1 switched to datafile copy

  164. input datafile copy RECID=4 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSTEM01.DBF

  165. datafile 2 switched to datafile copy

  166. input datafile copy RECID=5 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSTEM01.DBF

  167. datafile 3 switched to datafile copy

  168. input datafile copy RECID=6 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SYSAUX01.DBF

  169. datafile 4 switched to datafile copy

  170. input datafile copy RECID=7 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\SYSAUX01.DBF

  171. datafile 5 switched to datafile copy

  172. input datafile copy RECID=8 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\UNDOTBS01.DBF

  173. datafile 6 switched to datafile copy

  174. input datafile copy RECID=9 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\PDBSEED\UNDOTBS01.DBF

  175. datafile 7 switched to datafile copy

  176. input datafile copy RECID=10 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\USERS01.DBF

  177. datafile 8 switched to datafile copy

  178. input datafile copy RECID=11 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSTEM01.DBF

  179. datafile 9 switched to datafile copy

  180. input datafile copy RECID=12 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\SYSAUX01.DBF

  181. datafile 10 switched to datafile copy

  182. input datafile copy RECID=13 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\UNDOTBS01.DBF

  183. datafile 11 switched to datafile copy

  184. input datafile copy RECID=14 STAMP=1044131520 file name=E:\APP\ADMINISTRATOR\ORADATA\ERPDBS\SALES\USERS01.DBF

  185. Finished Duplicate Db at 26-JUN-20

4 备库同步测试

4.1 备库 MOUNT 状态开启日志同步应用

备库创建好之后,默认状态为 MOUNT,开启同步后,仅同步日志,是无法提供业务数据查询的

  1. # 主库状态查询


  2. SQL> select database_role,open_mode,protection_mode from v$database;


  3. DATABASE_ROLE    OPEN_MODE             PROTECTION_MODE

  4. ---------------- -------------------- --------------------

  5. PRIMARY          READ WRITE            MAXIMUM PERFORMANCE


  6. # 备库状态查询


  7. SQL> select database_role,open_mode,protection_mode from v$database;


  8. DATABASE_ROLE    OPEN_MODE             PROTECTION_MODE

  9. ---------------- -------------------- --------------------

  10. PHYSICAL STANDBY MOUNTED               MAXIMUM PERFORMANCE

4.2 备库开启 ADG

ADG (Active Data Guard)作为独立产品功能包含在 EE 企业版本中,其它版本不支持。备库开启 ADG 功能后,可进行同步查询。

备库取消日志应用

SQL> alter database recover managed standby database cancel;

备库开启 ADG

  1. # 打开备库为OPEN模式


  2. SQL> alter database open;

4.2.1 实时应用(Online Redo Log)

同步查询测试

  1. # 备库开启日志应用(12c开始默认为实时应用)


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


  3. # 主库打开PDB创建用户


  4. SQL> alter pluggable database sales open;

  5. SQL> alter session set container=sales;

  6. SQL> create user scott identified by oracle;


  7. # 备库打开PDB进行查询


  8. SQL> alter pluggable database sales open;

  9. SQL> alter session set container=sales;

  10. SQL> select username from dba_users where username='SCOTT';


  11. USERNAME

  12. -----------

  13. SCOTT

4.2.2 非实时应用(Archived Log)

同步查询测试

  1. # 备库取消实时应用


  2. SQL> alter database recover managed standby database cancel;


  3. # 备库开启非实时应用


  4. SQL> alter database recover managed standby database using archived logfile disconnect;


  5. # 主库连接 PDB 创建表


  6. SQL> show pdbs


  7.    CON_ID CON_NAME      OPEN MODE  RESTRICTED

  8. ---------- ------------- ---------- ----------

  9.         3 SALES         READ WRITE NO


  10. SQL> create table scuti as select 1 as a from dual;


  11. Table created.


  12. # 备库连接 PDB 查看表


  13. SQL> show pdbs


  14.    CON_ID CON_NAME      OPEN MODE  RESTRICTED

  15. ---------- ------------- ---------- ----------

  16.         2 PDB$SEED      READ ONLY  NO

  17.         3 SALES         READ ONLY  NO


  18. SQL> alter session set container=sales;


  19. Session altered.


  20. SQL> select * from scuti;

  21. select * from scuti

  22.              *

  23. ERROR at line 1:

  24. ORA-00942: table or view does not exist


  25. # 查不到的原因是因为使用的是备库的归档日志进行的应用,所以只有当主库发生日志切换后才会应用。


  26. # 主库连接 CDB 进行日志切换(日志切换无法在PDB级别完成)


  27. SQL> conn sys/oracle@erpdb as sysdba

  28. SQL> alter system switch logfile;


  29. # 备库再次查询


  30. SQL> select * from scuti;


  31.         A

  32. ----------

  33.         1

4.2.3 关于实时应用的说明

2.5.6.5 Real-Time Apply is Default Setting for Data Guard
 In previous releases, when creating a Data Guard configuration using the SQL command line, the default configuration was to apply redo from archived log files on the standby database. In Oracle Database 12c Release 1 (12.1), the default configuration is to use real-time apply so that redo is applied directly from the standby redo log file.

  • 在12c之前版本中,MRP的默认配置是对备用数据库上的归档日志文件进行应用重做。从Oracle数据库12c Release 1(12.1)开始,默认配置是使用实时应用(real-time apply),直接从备用重做日志文件应用重做。当前版本为12cR2,备库开启同步后,默认为非实时应用。

  1. # 备库开启实时应用


  2. SQL> alter database recover managed standby database cancel;


  3. Database altered.


  4. SQL> alter database recover managed standby database disconnect [from session]; # 中括号内容可省略


  5. Database altered.


  6. # 查询是否为实时应用


  7. SQL> select dest_name,status,recovery_mode from v$archive_dest_status;


  8. DEST_NAME            STATUS    RECOVERY_MODE

  9. -------------------- --------- ----------------------------------

  10. LOG_ARCHIVE_DEST_1   VALID     MANAGED REAL TIME APPLY


  11. # MANAGED REAL TIME APPLY 代表实时应用

从12.1开始 USING CURRENT LOGFILE 子句对于开启实时应用不再是必须选项


本文地址:https://liuchunjie.top/?id=592
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!

 发表评论


表情

还没有留言,还不快点抢沙发?