一、检查自动任务
生产环境一般会关闭自动顾问等自动任务,可以利用rman备份恢复的环境启用自动调优助手等任务或者手工调用自动调优助手帮助识别并调整业务sql,因为rman备份环境存有awr数据,可以利用里面的生产awr数据采集业务sql并调整。
sql> select client_name, status, consumer_group, window_group
2 from dba_autotask_client
3 order by client_name;
client_name status consumer_group window_group
---------------------------------------- -------- ------------------------------ ----------------------------------------
auto optimizer stats collection disabled ora$autotask ora$at_wgrp_os
auto space advisor disabled ora$autotask ora$at_wgrp_sa
sql tuning advisor disabled ora$autotask ora$at_wgrp_sq
sql> sql> select task_name, status, to_char(execution_end,'dd-mon-yy hh24:mi')
2 from dba_advisor_executions
3 where task_name='sys_auto_sql_tuning_task'
4 order by execution_end;
no rows selected
sql> select window_name,to_char(window_next_time,'dd-mon-yy hh24:mi:ss')
2 ,sql_tune_advisor, optimizer_stats, segment_advisor
3 from dba_autotask_window_clients;
window_name to_char(window_next_t sql_tune optimize segment_
---------------------------------------- --------------------- -------- -------- --------
monday_window 06-mar-23 22:00:00 disabled disabled disabled
tuesday_window 28-feb-23 22:00:00 disabled disabled disabled
wednesday_window 01-mar-23 22:00:00 disabled disabled disabled
thursday_window 02-mar-23 22:00:00 disabled disabled disabled
friday_window 03-mar-23 22:00:00 disabled disabled disabled
saturday_window 04-mar-23 06:00:00 disabled disabled disabled
sunday_window 05-mar-23 06:00:00 disabled disabled disabled
7 rows selected.
二、启用自动调优
sql> begin
2 dbms_auto_task_admin.enable(
3 client_name => 'sql tuning advisor',
4 operation => null,
5 window_name => null);
6 end;
7 /
pl/sql procedure successfully completed.
sql> select client_name, status, consumer_group, window_group
2 from dba_autotask_client
3 order by client_name;
auto optimizer stats collection disabled ora$autotask ora$at_wgrp_os
auto space advisor disabled ora$autotask ora$at_wgrp_sa
sql tuning advisor enabled ora$autotask ora$at_wgrp_sq
查看调度窗口
sql> select window_name,to_char(window_next_time,'dd-mon-yy hh24:mi:ss')
2 ,sql_tune_advisor, optimizer_stats, segment_advisor
3 from dba_autotask_window_clients;
window_name to_char(window_next_t sql_tune optimize segment_
---------------------------------------- --------------------- -------- -------- --------
monday_window 06-mar-23 22:00:00 enabled disabled disabled
tuesday_window 28-feb-23 22:00:00 enabled disabled disabled
wednesday_window 01-mar-23 22:00:00 enabled disabled disabled
thursday_window 02-mar-23 22:00:00 enabled disabled disabled
friday_window 03-mar-23 22:00:00 enabled disabled disabled
saturday_window 04-mar-23 06:00:00 enabled disabled disabled
sunday_window 05-mar-23 06:00:00 enabled disabled disabled
7 rows selected.
sql> select window_name, to_char(start_time,'dd-mon-yy hh24:mi'), duration
2 from dba_autotask_schedule
3 order by start_time;
window_name to_char(start_time duration
---------------------------------------- ------------------ ------------------------------
tuesday_window 28-feb-23 22:00 000 04:00:00
wednesday_window 01-mar-23 22:00 000 04:00:00
thursday_window 02-mar-23 22:00 000 04:00:00
friday_window 03-mar-23 22:00 000 04:00:00
saturday_window 04-mar-23 06:00 000 20:00:00
sunday_window 05-mar-23 06:00 000 20:00:00
monday_window 06-mar-23 22:00 000 04:00:00
tuesday_window 07-mar-23 22:00 000 04:00:00
wednesday_window 08-mar-23 22:00 000 04:00:00
thursday_window 09-mar-23 22:00 000 04:00:00
friday_window 10-mar-23 22:00 000 04:00:00
window_name to_char(start_time duration
---------------------------------------- ------------------ ------------------------------
saturday_window 11-mar-23 06:00 000 20:00:00
sunday_window 12-mar-23 06:00 000 20:00:00
monday_window 13-mar-23 22:00 000 04:00:00
tuesday_window 14-mar-23 22:00 000 04:00:00
wednesday_window 15-mar-23 22:00 000 04:00:00
thursday_window 16-mar-23 22:00 000 04:00:00
friday_window 17-mar-23 22:00 000 04:00:00
saturday_window 18-mar-23 06:00 000 20:00:00
sunday_window 19-mar-23 06:00 000 20:00:00
monday_window 20-mar-23 22:00 000 04:00:00
tuesday_window 21-mar-23 22:00 000 04:00:00
window_name to_char(start_time duration
---------------------------------------- ------------------ ------------------------------
wednesday_window 22-mar-23 22:00 000 04:00:00
thursday_window 23-mar-23 22:00 000 04:00:00
friday_window 24-mar-23 22:00 000 04:00:00
saturday_window 25-mar-23 06:00 000 20:00:00
sunday_window 26-mar-23 06:00 000 20:00:00
monday_window 27-mar-23 22:00 000 04:00:00
tuesday_window 28-mar-23 22:00 000 04:00:00
wednesday_window 29-mar-23 22:00 000 04:00:00
thursday_window 30-mar-23 22:00 000 04:00:00
friday_window 31-mar-23 22:00 000 04:00:00
saturday_window 01-apr-23 06:00 000 20:00:00
33 rows selected.
三、利用awr数据创建调优集
sql> select owner, name, id, created, statement_count from dba_sqlset;
owner name id created statement_count
---------- ------------------------------ ---------- ------------------- ---------------
sys sys_auto_sts 1 2019-04-17 01:14:26 0
sql> begin
2 dbms_sqltune.create_sqlset(
3 sqlset_name => 'high_io',
4 description => 'high disk read tuning set');
5 end;
6 /
pl/sql procedure successfully completed.
sql> select owner, name, id, created, statement_count from dba_sqlset;
owner name id created statement_count
---------- ------------------------------ ---------- ------------------- ---------------
sys sys_auto_sts 1 2019-04-17 01:14:26 0
sys high_io 5 2023-02-28 09:40:25 0
四、查看awr中资源密集sql
sql> select sql_id
2 ,disk_reads, cpu_time, elapsed_time,executions,module,command_type
3 from table(dbms_sqltune.select_workload_repository(29100,29364,
4 null, null, 'disk_reads',null, null, null, 100)) where executions>20 and parsing_schema_name <> 'sys'
5 order by disk_reads desc,module;
sql_id disk_reads cpu_time elapsed_time executions module command_type
------------- -------------------- -------------------- -------------------- -------------------- -------------------------------------------------- --------------------
apmcb6fm10jsw 8099201919 178675049564 364732671309 1266 sql*plus 2
fvx120zqr7f14 1890642116 62681302576 181271628823 449 jdbc thin client 3
36sq3q4b35yyv 1812718553 58040471566 161011246393 263 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
dhj22t3vypqg6 1795108559 260677250672 1150341616658 525 jdbc thin client 3
ak3c4z1ca5njj 1465851043 32008033856 65710002220 77 jdbc thin client 3
4h5xcu5txbabu 1132984248 25639979294 53031851992 457 sql*plus 7
bh2fgcq0sw600 1114547751 52478103134 228695637975 295 locottmbhinfosyn@lbkprocnx-1 (tns v1-v3) 3
gdy1v6u3qgc7a 1108803084 26793421578 55823437266 532 sql*plus 7
fj8cyj52b2s2r 1054861801 24798460389 53087369289 449 sql*plus 7
8b2sppz333g4f 1024633879 25252786947 51713907037 530 sql*plus 7
0uakp6kb3cjf7 951567470 26405004422 50999412371 703 sql*plus 7
baq4hpx23bxdy 918886356 39486637374 116358370938 261 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
gzgmtyga27nyt 688593207 25359242505 79656628550 263 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
1jvvk1un0sh99 630332631 16067470267 33135776028 355 sql*plus 7
dx1tuwhnh0u2j 577924931 35974291841 70199486452 1643 jdbc thin client 3
dpr691krc9j82 222980072 11532216814 27131416633 128 sql*plus 3
bf2uu1xn6w7ag 207957666 22106500405 145083945164 758 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
642un4txf910v 145767333 62656467788 72436540638 262 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
fvx120zqr7f14 142484284 21360291749 101327116237 52 jdbc thin client 3
gup9dyndmuu03 121436588 3730103202 7465907047 88 jdbc thin client 3
b7qzn9jr138gn 100903531 61611779559 81267199490 262 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
7cn58fzxt4hst 73546534 1898909732 4483742939 82 sqlshell@kjfcbenx-11 (tns v1-v3) 6
4npzs9gxmxrn1 67790093 22078672259 27115872758 242 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
fcgxhmx4640a1 58211273 20912194403 32581556742 4540 jdbc thin client 3
cyc7jnzhmxtjz 54269409 3019552006 12194950540 28 sql*plus 6
fhh1vk45xrwff 53066460 2818608441 13226758352 28 sql*plus 6
84tc7x1h4wruj 45209872 28685799058 55087838427 713813 runschedule@ljkclnx-1 (tns v1-v3) 6
fpxk5crkjc7cf 37394425 2874708553 6153616963 131 paymentrollback@lbkprocnx-1 (tns v1-v3) 3
9vkrwcankphgm 33944968 3300164718 32205561270 216 jdbc thin client 3
ckjhmx1f667nm 31051576 3167953223 32078507617 215 jdbc thin client 3
4pq38aknnmy8g 31024838 3556856470 21563255623 3415598 loverduenoticetodb@lbkprocnx-1 (tns v1-v3) 3
5va54r557mvv4 30974190 3158333406 31579892812 212 jdbc thin client 3
9ggfmapy1mxum 30859936 3159917455 31811983529 214 jdbc thin client 3
byf31ddybry5a 30519143 3203493348 32553084135 218 jdbc thin client 3
52jcjzkay2mfa 28909406 3031521088 31088340440 208 jdbc thin client 3
5xm5h8b6y00fr 27635257 2008561440 7869404054 107 locpersoncardinfosync@kbkprocnx-1 (tns v1-v3) 3
c2zwtngdrz1b7 24213320 12860944407 14102849386 221 unifyfiledeal@ljkclnx-1 (tns v1-v3) 3
139amnfsps2qd 21877996 3665281311 7499194517 815 jdbc thin client 3
5h271rsq9khc4 19043475 2377443817 15837174245 95715 lfpluschkfiletodb@kibossnx-11 (tns v1-v3) 3
bdg7qvddkcwcz 14394604 42409438217 46778427496 15223 jdbc thin client 3
4trg5k568drxw 14055318 8967127041 12526743054 132 unifyfiledeal@ljkclnx-2 (tns v1-v3) 3
41 rows selected.
五、加载进入优化集
begin
dbms_sqltune.create_sqlset(
sqlset_name => 'io_sts',
description => 'sts from awr');
end;
/
select snap_id, begin_interval_time
from dba_hist_snapshot order by 1;
declare
base_cur dbms_sqltune.sqlset_cursor;
begin
open base_cur for
select value(x)
from table(dbms_sqltune.select_workload_repository(29100,29364,
null, null, 'disk_reads',null, null, null, 100)) x where executions>20 and parsing_schema_name <> 'sys' ;
--
dbms_sqltune.load_sqlset(
sqlset_name => 'io_sts',
populate_cursor => base_cur);
end;
/
六、查看优化集sql
此时也可以利用dbms_sqltune手工删除部分sql
sql> select sqlset_name, elapsed_time
2 ,cpu_time, buffer_gets, disk_reads
3 from dba_sqlset_statements
4 where sqlset_name = 'io_sts';
sqlset_name elapsed_time cpu_time buffer_gets disk_reads
-------------------- ------------ ---------- ----------- ----------
io_sts 3.6473e 11 1.7868e 11 8198258499 8099201919
io_sts 1.8127e 11 6.2681e 10 2177953579 1890642116
io_sts 1.6101e 11 5.8040e 10 1903298474 1812718553
io_sts 1.1503e 12 2.6068e 11 2394175767 1795108559
io_sts 6.5710e 10 3.2008e 10 1466290690 1465851043
io_sts 5.3032e 10 2.5640e 10 1196722876 1132984248
io_sts 2.2870e 11 5.2478e 10 2508450349 1114547751
io_sts 5.5823e 10 2.6793e 10 1407868540 1108803084
io_sts 5.3087e 10 2.4798e 10 1189046395 1054861801
io_sts 5.1714e 10 2.5253e 10 1394952065 1024633879
io_sts 5.0999e 10 2.6405e 10 1836456707 951567470
sqlset_name elapsed_time cpu_time buffer_gets disk_reads
-------------------- ------------ ---------- ----------- ----------
io_sts 1.1636e 11 3.9487e 10 1355568949 918886356
io_sts 7.9657e 10 2.5359e 10 941619996 688593207
io_sts 3.3136e 10 1.6067e 10 925314560 630332631
io_sts 7.0199e 10 3.5974e 10 2749382610 577924931
io_sts 2.7131e 10 1.1532e 10 352679032 222980072
io_sts 1.4508e 11 2.2107e 10 612133638 207957666
io_sts 7.2437e 10 6.2656e 10 156787854 145767333
io_sts 1.0133e 11 2.1360e 10 184710351 142484284
io_sts 7465907047 3730103202 191237172 121436588
io_sts 8.1267e 10 6.1612e 10 213920731 100903531
io_sts 4483742939 1898909732 100850297 73546534
sqlset_name elapsed_time cpu_time buffer_gets disk_reads
-------------------- ------------ ---------- ----------- ----------
io_sts 2.7116e 10 2.2079e 10 76883277 67790093
io_sts 3.2582e 10 2.0912e 10 1883820475 58211273
io_sts 1.2195e 10 3019552006 97094359 54269409
io_sts 1.3227e 10 2818608441 103808891 53066460
io_sts 5.5088e 10 2.8686e 10 1653624828 45209872
io_sts 6153616963 2874708553 617121622 37394425
io_sts 3.2206e 10 3300164718 260187139 33944968
io_sts 3.2079e 10 3167953223 258911329 31051576
io_sts 2.1563e 10 3556856470 443478655 31024838
io_sts 3.1580e 10 3158333406 255475487 30974190
io_sts 3.1812e 10 3159917455 257708931 30859936
sqlset_name elapsed_time cpu_time buffer_gets disk_reads
-------------------- ------------ ---------- ----------- ----------
io_sts 3.2553e 10 3203493348 262523409 30519143
io_sts 3.1088e 10 3031521088 250608164 28909406
io_sts 7869404054 2008561440 100739299 27635257
io_sts 1.4103e 10 1.2861e 10 63328173 24213320
io_sts 7499194517 3665281311 556283282 21877996
io_sts 1.5837e 10 2377443817 70617678 19043475
io_sts 4.6778e 10 4.2409e 10 8458202204 14394604
io_sts 1.2527e 10 8967127041 30488912 14055318
41 rows selected.
六、创建调优任务
sql> variable mytt varchar2(30);
sql> exec :mytt := dbms_sqltune.create_tuning_task(sqlset_name => 'io_sts', task_name => 'tune_test4');
pl/sql procedure successfully completed.
七、调整调优任务参数
exec dbms_sqltune.set_tuning_task_parameter(task_name=>'tune_test4',parameter=>'time_limit',value=>180000);
八、运行调优任务
exec dbms_sqltune.execute_tuning_task(task_name=>'tune_test4');
九、查看调优报告
select dbms_sqltune.report_tuning_task('tune_test4') from dual;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。