首页 > 数据库 >[转帖]Oracle replay工具用法

[转帖]Oracle replay工具用法

时间:2024-01-26 09:05:07浏览次数:44  
标签:wcr -------------------------------------------------- db 转帖 oracle replay Oracl

一、 简介

Oracle 11g推出的神器,可以抓取生产环境真实负载(sql语句),在目标环境重演,进行对比。在核心生产环境迁移等重大变更前,尽量确定变更带来的影响。

核心步骤包括:准备工作、捕获负载、预处理负载、重演负载、对比分析,每步又包含多个子步骤,下面通过测试案例来看。

二、 准备工作

  • 源与目标库版本要一致,测试中使用19.3版本
  • 源与目标库启用AWR,并设置好采集间隔和保留时间
  • 目标库要有源库中数据,通过dump、rman、dg等同步均可
  1. -- 本例中我们只建一个表
  2. -- 源与目标库均执行
  3. create table mytab (a varchar2(2000));
  • 目标库参数等要根据日后实际需求配置好
  • 查看文档 Doc ID 560977.1,根据源和目标库版本打文档要求补丁

三、捕获源库负载

  • 建立负载过滤器
  1. --建立过滤器filter_test,用于过滤掉user为system的规则
  2. BEGIN
  3. DBMS_WORKLOAD_CAPTURE.ADD_FILTER (
  4. fname => 'filter_test',
  5. fattribute => 'USER',
  6. fvalue => 'SYSTEM');
  7. END;
  8. /
  • 建立负载文件存储目录
create directory test_dir as '/data/bak';
  • 开始捕获负载
  1. BEGIN
  2. DBMS_WORKLOAD_CAPTURE.START_CAPTURE (name => 'peak_120s',
  3. dir => 'TEST_DIR',
  4. duration => 120);
  5. END;
  6. /

注意事项

  • 目录不能有其他文件,否则会报错ORA-15505
  • dir => 'DIR_NAME' 目录名要大写,否则会报错ORA-20222
  • duration => 120,指定120秒后自动结束。如果未指定,或者想提前结束,需要使用FINISH_CAPTURE存储过程来停止。
  • 另开一个窗口,执行负载脚本
  1. declare
  2. l_stmt varchar2(2000);
  3. begin
  4. for ctr in 1..100000 loop
  5. l_stmt := 'insert into mytab values (''''||
  6. lpad(round(dbms_random.value(1,9999999999999999999)),20,0)||'''')';
  7. dbms_output.put_line(l_stmt);
  8. execute immediate l_stmt;
  9. commit;
  10. end loop;
  11. end;
  12. /
  • 停止捕获负载

等待指定时间后自动强制,或使用FINISH_CAPTURE存储过程手动停止

exec dbms_workload_capture.FINISH_CAPTURE();
  • 查看捕获的负载AWR数据
  1. [oracle@source-db ~]$ cd /data/bak/
  2. [oracle@source-db bak]$ ll -h
  3. total 0
  4. drwxr-xr-x 2 oracle oinstall 92 Jul 21 15:13 cap
  5. drwxr-xr-x 3 oracle oinstall 19 Jul 21 15:12 capfiles
  6. [oracle@source-db bak]$
  7. [oracle@source-db bak]$ cd cap
  8. [oracle@source-db cap]$ ls
  9. wcr_cr.html wcr_cr.text wcr_fcapture.wmd wcr_scapture.wmd
  10. [oracle@source-db cap]$
  11. [oracle@source-db cap]$ cd ../capfiles/
  12. [oracle@source-db capfiles]$ ls
  13. inst1
  14. [oracle@source-db capfiles]$ cd inst1/
  15. [oracle@source-db inst1]$ ls
  16. aa ab ac ad ae af ag ah ai aj
  17. [oracle@source-db inst1]$ cd aa/
  18. [oracle@source-db aa]$ ls
  19. wcr_ggk6th0000000.rec wcr_ggk8ch0000001.rec

至此源库捕获工作完成,剩下的在目标库执行

四、目标库补丁安装

适用于较低版本的目标库,可参考 Mandatory Patches for Database Testing Functionality for Current and Earlier Releases

例如 11.2.0.3版本需要安装17411249补丁,19.3版本则无需安装

安装过程与普通补丁无异,参考readme.txt即可

五、 预处理负载

  • 目标库创建目录,上传负载文件
  1. mkdir /data/bak
  2. chown ora.dba -R /data/bak/
  3. #上传文件后
  4. [oracle@dest-db bak]$ ls
  5. cap capfiles
  • 预处理负载

将捕获文件转换为重演文件,此步骤耗时耗资源,请在目标库进行,不要在生产库上进行。注意要让SYSAUX有足够的空间剩余,不然会报错ORA-1658。

  1. BEGIN
  2. DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE (capture_dir => 'TEST_DIR');
  3. END;
  4. /

预处理后会生成一个pp19.3.0.0.0文件夹,里面是待重演文件

  1. [oracle@dest-db bak]$ ls
  2. cap capfiles pp19.3.0.0.0
  3. [oracle@dest-db bak]$ cd pp19.3.0.0.0/
  4. [oracle@dest-db pp19.3.0.0.0]$ ls
  5. capfiles wcr_conn_data.extb wcr_login.extb wcr_references.extb wcr_seq_data.extb
  6. wcr_calibrate.xml wcr_data.extb wcr_login.pp wcr_schema_info.extb wcr_sqltext.extb
  7. wcr_commits.extb wcr_dep_graph.extb wcr_process.wmd wcr_scn_order.extb wcr_xa.extb

六、 重演负载

wrc(Workload Replay Client)用于模拟将原生产库上的客户端的负载请求,模拟到测试库上。

1. wrc校准

wrc mode=calibrate replaydir=/home/oracle/bak

  1. [oracle@dest-db bak]$ wrc mode=calibrate replaydir=/home/oracle/bak
  2. Workload Replay Client: Release 19.3.0.0.0 - Production on Wed Jul 21 16:51:04 2021
  3. Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
  4. Report for Workload in: /home/oracle/bak
  5. -----------------------
  6. Recommendation:
  7. Consider using at least 1 clients divided among 1 CPU(s)
  8. You will need at least 3 MB of memory per client process.
  9. If your machine(s) cannot match that number, consider using more clients.
  10. Workload Characteristics:
  11. - max concurrency: 1 sessions
  12. - total number of sessions: 2
  13. Assumptions:
  14. - 1 client process per 100 concurrent sessions
  15. - 4 client processes per CPU
  16. - 256 KB of memory cache per concurrent session
  17. - think time scale = 100
  18. - connect time scale = 100
  19. - synchronization = TRUE

2. 初始化重演

  1. BEGIN
  2. DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY (replay_name => 'peak_120s',
  3. replay_dir => 'TEST_DIR');
  4. END;
  5. /

3. 连接映射

  1. -- 映射连接
  2. select conn_id,capture_conn,replay_conn from dba_workload_connection_map where replay_id=1;
  3. -- 修改为测试库连接
  4. -- 改HOST, PORT, SERVICE_NAME
  5. select 'exec dbms_workload_replay.remap_connection('||conn_id||', ''(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.80.99)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME= PDBREPLAY)))'');' from dba_workload_connection_map where replay_id=1;

执行上面拼接出来的语句

4. 设置负载重演的选项

  1. -- synchronization 是否完全按捕获时间线replay;connect_time_scale,think_time_scale 将时间设置为源库的50%,加大压测压力
  2. BEGIN
  3. dbms_workload_replay.PREPARE_REPLAY(synchronization => false,connect_time_scale => 50,think_time_scale => 50);
  4. END;
  5. /

4. wrc重演

wrc system mode=replay replaydir=/home/oracle/bak

5. 负载重演

另开一个窗口

  1. BEGIN
  2. DBMS_WORKLOAD_REPLAY.START_REPLAY ();
  3. END;
  4. /

6. 结束负载重演

等待负载执行完或者手动结束

  1. BEGIN
  2. DBMS_WORKLOAD_REPLAY.CANCEL_REPLAY ();
  3. END;
  4. /

结束后回到wrc的窗口,会看到如下输出

  1. [oracle@dest-db bak]$ wrc system mode=replay replaydir=/home/oracle/bak
  2. Workload Replay Client: Release 19.3.0.0.0 - Production on Wed Jul 21 17:23:33 2021
  3. Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
  4. Password:
  5. Wait for the replay to start (17:23:40)
  6. Replay client 1 started (17:23:59) <--------
  7. Replay client 1 finished (17:27:10) <--------

7. 检查是否确实重演

  1. select name,status from dba_workload_replays;
  2. NAME STATUS
  3. ------------- ----------------------------
  4. peak_120s COMPLETED

也可以通过检查数据验证

  1. -- 源库
  2. SQL> select count(*) from mytab;
  3. COUNT(*)
  4. ----------
  5. 100000
  6. -- 目标库
  7. SQL> select count(*) from mytab;
  8. COUNT(*)
  9. ----------
  10. 100000

8. 查看replay报告

  1. set pagesize 0 long 30000000 longchunksize 1000
  2. select dbms_workload_replay.report(1,'TEXT') from dual;
  3. -- 输出结果
  4. DB Replay Report for test_replay_1
  5. ---------------------------------------------------------------------------
  6. | DB Name | DB Id | Release | RAC | Replay Name | Replay Status |
  7. ---------------------------------------------------------------------------
  8. | JCREPLAY | 147275354 | 11.1.0.5.0 | NO | test_replay_1 | COMPLETED |
  9. ---------------------------------------------------------------------------
  10. Replay Information
  11. --------------------------------------------------------------------------------------------------
  12. | Information | Replay | Capture |
  13. --------------------------------------------------------------------------------------------------
  14. | Name | test_replay_1 | test_capture_2 |
  15. --------------------------------------------------------------------------------------------------
  16. | Status | COMPLETED | COMPLETED |
  17. --------------------------------------------------------------------------------------------------
  18. | Database Name | JCREPLAY | V11B5 |
  19. --------------------------------------------------------------------------------------------------
  20. | Database Version | 11.1.0.5.0 | 11.1.0.5.0 |
  21. --------------------------------------------------------------------------------------------------
  22. | Start Time | 25-JUL-07 16:19:27 | 25-JUL-07 14:09:49 |
  23. --------------------------------------------------------------------------------------------------
  24. | End Time | 25-JUL-07 16:20:31 | 25-JUL-07 14:12:11 |
  25. --------------------------------------------------------------------------------------------------
  26. | Duration | 1 minute 4 seconds | 2 minutes 22 seconds |
  27. --------------------------------------------------------------------------------------------------
  28. | Directory Object | MY_WORKLOAD_DIR | MY_WORKLOAD_DIR |
  29. --------------------------------------------------------------------------------------------------
  30. | Directory Path | /home/%usernm%/my_workload_directory | /home/%usernm%/my_workload_directory |
  31. --------------------------------------------------------------------------------------------------
  32. Replay Options
  33. ---------------------------------------------------------
  34. | Option Name | Value |
  35. ---------------------------------------------------------
  36. | Synchronization | TRUE |
  37. ---------------------------------------------------------
  38. | Connect Time | 100% |
  39. ---------------------------------------------------------
  40. | Think Time | 100% |
  41. ---------------------------------------------------------
  42. | Think Time Auto Correct | TRUE |
  43. ---------------------------------------------------------
  44. | Number of WRC Clients | 1 (1 Completed, 0 Running ) |
  45. ---------------------------------------------------------
  46. Replay Statistics
  47. ------------------------------------------------
  48. | Statistic | Replay | Capture |
  49. ------------------------------------------------
  50. | DB Time | 932061 | 1006294 |
  51. ------------------------------------------------
  52. | Average Active Sessions | .01 | .01 |
  53. ------------------------------------------------
  54. | User calls | 46 | 50 |
  55. ------------------------------------------------
  56. | Network Time | 2724 | . |
  57. ------------------------------------------------
  58. | Think Time | 17159449 | . |
  59. ------------------------------------------------
  60. | Elapsed Time Difference | 148907 | . |
  61. ------------------------------------------------
  62. | New Errors | 0 | . |
  63. ------------------------------------------------
  64. | Mutated Errors | 0 | . |
  65. ------------------------------------------------
  66. ---------------------------------------------------------------------------------------------------
  67. Workload Profile Top Events (+) Show (-) Hide
  68. --------------------------------------------------
  69. | No data exists for this section of the report. |
  70. --------------------------------------------------
  71. Top Service/Module/Action (+) Show (-) Hide
  72. --------------------------------------------------
  73. | No data exists for this section of the report. |
  74. --------------------------------------------------
  75. Top SQL with Top Events (+) Show (-) Hide
  76. --------------------------------------------------
  77. | No data exists for this section of the report. |
  78. --------------------------------------------------
  79. Top Sessions with Top Events (+) Show (-) Hide
  80. --------------------------------------------------
  81. | No data exists for this section of the report. |
  82. --------------------------------------------------
  83. Replay Divergence Session Failures By Application (+) Show (-) Hide
  84. --------------------------------------------------
  85. | No data exists for this section of the report. |
  86. --------------------------------------------------
  87. Error Divergence By Application (+) Show (-) Hide
  88. --------------------------------------------------
  89. | No data exists for this section of the report. |
  90. --------------------------------------------------
  91. By SQL (+) Show (-) Hide
  92. --------------------------------------------------
  93. | No data exists for this section of the report. |
  94. --------------------------------------------------
  95. By Session (+) Show (-) Hide
  96. --------------------------------------------------
  97. | No data exists for this section of the report. |
  98. --------------------------------------------------
  99. DML Data Divergence By Application (+) Show (-) Hide
  100. --------------------------------------------------
  101. | No data exists for this section of the report. |
  102. --------------------------------------------------
  103. By SQL (+) Show (-) Hide
  104. --------------------------------------------------
  105. | No data exists for this section of the report. |
  106. --------------------------------------------------
  107. SELECT Data Divergence By Application (+) Show (-) Hide
  108. --------------------------------------------------
  109. | No data exists for this section of the report. |
  110. --------------------------------------------------
  111. End of Report.

最后,对比分析监控及AWR数据,这就属于性能优化方面的内容了,这里不再多说。

参考 

11g新特性-重演(replay) – OracleBlog

Oracle 19c迁移前,做好RAT回放测试有多重要? - 云+社区 - 腾讯云

【RAT】Oracle Real Application Testing(真用应用测试)介绍_ITPUB博客

Master Note for Real Application Testing Option (Doc ID 1464274.1)

Database Testing: Best Practices (Doc ID 1535885.1)

Mandatory Patches for Database Testing Functionality for Current and Earlier Releases (Doc ID 560977.1)

Using Workload Capture and Replay (Doc ID 445116.1)

How to Setup and Run a Database Testing Replay in an Oracle Multitenant Environment (Real Application Testing - RAT) (Doc ID 1937920.1)

文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树数据库组成78200 人正在系统学习中

标签:wcr,--------------------------------------------------,db,转帖,oracle,replay,Oracl
From: https://www.cnblogs.com/jinanxiaolaohu/p/17987521

相关文章

  • 技术解读 | KunDB助力头部金融机构关键系统的Oracle国产替代
    星环科技自主研发的分布式交易型数据库KunDB助力头部金融机构实现了关键系统的Oracle国产化替代。通过可视化迁移工具完成了对象与数据的平滑迁移,将原先两套Oracle系统(一套Oracle单机系统,一套OracleRAC系统)统一迁移到一套KunDB集群。并且基于常规国产服务器使得每日增量数据处理性......
  • [转帖]Oracle中的游标、硬解析、软解析、软软解析、解析失败
    https://developer.aliyun.com/article/283561 一、  游标的分类及共享游标游标(Cursor)是Oracle数据库中SQL解析和执行的载体,它可以分为共享游标(SharedCursor)和会话游标(SessionCursor)。共享游标可以细分为父游标(ParentCursor)和子游标(ChildCursor),可以通过视图V$SQLAREA......
  • [转帖]一文搞懂各种数据库SQL执行计划:MySQL、Oracle等
    https://zhuanlan.zhihu.com/p/99331255 14人赞同了该文章MySQL执行计划Oracle执行计划SQLServer执行计划PostgreSQL执行计划执行计划(executionplan,也叫查询计划或者解释计划)是数据库执行SQL语句的具体步骤,例如通过索引还是全表扫描访问表中的数据,连......
  • [转帖]内存(DDR/DDR2/DDR3/DDR4)的速度等级和时钟频率
    以下全部图片均来自镁光(Micron)公司产品的数据手册。DDR:以MT48LCxx型号的DDR内存芯片为例,数据手册中给出如图1所示的一个表格。从表格中可以看出它的主频(ClockFrequency)。图1不同速度等级的DDR主频它的主频与传输数据的频率相同。我们可以从时序图中观察出来。随便......
  • [转帖]3 分钟了解 NVIDIA 新出的 H200
    https://zhuanlan.zhihu.com/p/439633733内存带宽应该是9.6*1024*6算出来来的实际值4.8TB/S和内存141G应该是进行了一些删减理论上是六个24GB的HBM3e的内存.应该是为了安全和稳定进行了限速不然理论上可以达到接近6BG的带宽和144G的HBM3e的内存大小.英伟......
  • oracle PL/SQL基础介绍
    1.PL/SQL简介PL/SQL语言(ProceduralLanguage/SQL,过程化SQL语言)是Oracle推出的过程化的SQL编程语言,使用PL/SQL可以为SQL语言引入结构化的程序处理能力,例如可以在PL/SQL中定义常量、变量、游标、存储过程等,可以使用条件、循环等流程控制语句。PL/SQL的这种特性使得开发人员可以在......
  • [转帖]肿瘤治疗的疗效评估 CR、PR、SD、PD,ORR,DCR
    https://zhuanlan.zhihu.com/p/518260265 我们一起来了解一下这几个概念的定义:CR、PR、SD、PD,ORR,DCR这些都采用实体瘤疗效评价标准RECIST(不同肿瘤类型会略有差别),用于评估肿瘤治疗的疗效评估。完全缓解(Completeresponse,CR):所有肿瘤靶病灶消失,无新病灶出现,且肿瘤标志物......
  • Oracle数据类型的简单学习之一
    Oracle数据类型的简单学习之一背景因为信创安可替代的发展有很多项目提到了数据库切换到国产数据库的要求.一般情况是要求从Oracle/SQLServer迁移到国产的:达梦/瀚高/人大金仓/南大通用等数据库.但是因为Oracle作为数据库领域No.1的存在他对SQL的规范标准支持的并不......
  • [转帖]Data Types
    https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-A3C0D836-BADB-44E5-A5D4-265BA5968483EachvaluemanipulatedbyOracleDatabasehasa datatype.Thedatatypeofavalueassociatesafixedsetofpropertieswith......
  • Oracle12c 数据库 警告日志
    目录一:查看警告日志文件的位置二:警告日志内容三:告警日志监控:方案1:方案2:方案3: 正文 回到顶部一:查看警告日志文件的位置        Oracle12c环境下查询,alert日志并不在bdump目录下,看到网上和书上都写着可以通过初始化参数background_dump_dest来查看......