1. 程式人生 > >dbms_advisor 手動生成段顧問建議!

dbms_advisor 手動生成段顧問建議!

pl/sql http viso air 指定 repair _id itl nal

執行包需要dbms_advisor權限:

[sql] view plain copy
  1. sys@ORCL> grant advisor to u1;
  2. 授權成功。

創建段顧問任務,指定create_task的advisor_name參數為“段顧問”。查詢dba_advisor_definitions來獲得所有有效的顧問列表。

[sql] view plain copy
  1. u1@ORCL> select * from dba_advisor_definitions;
  2. ADVISOR_ID ADVISOR_NAME PROPERTY
  3. ---------- ------------------------------ ----------
  4. 1 ADDM 1
  5. 2 SQL Access Advisor 271
  6. 3 Undo Advisor 1
  7. 4 SQL Tuning Advisor 935
  8. 5 Segment Advisor 3
  9. 6 SQL Workload Manager 0
  10. 7 Tune MView 31
  11. 8 SQL Performance Analyzer 935
  12. 9 SQL Repair Advisor 679
  13. 10 Compression Advisor 3
  14. 已選擇10行。

手動執行段顧問:

[sql] view plain copy
  1. sys@ORCL> DECLARE
  2. 2 my_task_id number;
  3. 3 obj_id number;
  4. 4 my_task_name varchar2(100);
  5. 5 my_task_desc varchar2(500);
  6. 6 BEGIN
  7. 7 my_task_name := ‘BIG_TABLE Advice‘;
  8. my_task_desc := ‘Manual Segment Advisor Run‘;
  9. 9 ---------
  10. 10 -- Step 1 創建一個任務
  11. 11 ---------
  12. 12 dbms_advisor.create_task (
  13. 13 advisor_name => ‘Segment Advisor‘,
  14. 14 task_id => my_task_id,
  15. 15 task_name => my_task_name,
  16. 16 task_desc => my_task_desc);
  17. 17 ---------
  18. 18 -- Step 2 為這個任務分配一個對象
  19. 19 ---------
  20. 20 dbms_advisor.create_object (
  21. 21 task_name => my_task_name,
  22. 22 object_type => ‘TABLE‘,
  23. 23 attr1 => ‘U1‘,
  24. 24 attr2 => ‘BIG_TABLE‘,
  25. 25 attr3 => NULL,
  26. 26 attr4 => NULL,
  27. 27 attr5 => NULL,
  28. 28 object_id => obj_id);
  29. 29 ---------
  30. 30 -- Step 3 設置任務參數
  31. 31 ---------
  32. 32 dbms_advisor.set_task_parameter(
  33. 33 task_name => my_task_name,
  34. 34 parameter => ‘recommend_all‘,
  35. value => ‘TRUE‘);
  36. ---------
  37. 37 -- Step 4 執行這個任務
  38. 38 ---------
  39. 39 dbms_advisor.execute_task(my_task_name);
  40. 40 END;
  41. 41 /
  42. PL/SQL 過程已成功完成。
  43. sys@ORCL> SELECT
  44. 2 ‘Segment Advice --------------------------‘|| chr(10) ||
  45. 3 ‘TABLESPACE_NAME : ‘ || tablespace_name || chr(10) ||
  46. 4 ‘SEGMENT_OWNER : ‘ || segment_owner || chr(10) ||
  47. 5 ‘SEGMENT_NAME : ‘ || segment_name || chr(10) ||
  48. 6 ‘ALLOCATED_SPACE : ‘ || allocated_space || chr(10) ||
  49. 7 ‘RECLAIMABLE_SPACE: ‘ || reclaimable_space || chr(10) ||
  50. 8 ‘RECOMMENDATIONS : ‘ || recommendations || chr(10) ||
  51. 9 ‘SOLUTION 1 : ‘ || c1 || chr(10) ||
  52. 10 ‘SOLUTION 2 : ‘ || c2 || chr(10) ||
  53. 11 ‘SOLUTION 3 : ‘ || c3 Advice
  54. 12 FROM
  55. 13 TABLE(dbms_space.asa_recommendations(‘TRUE‘, ‘TRUE‘, ‘FALSE‘));
  56. ADVICE
  57. --------------------------------------------------------------------------------
  58. Segment Advice --------------------------
  59. TABLESPACE_NAME : USERS
  60. SEGMENT_OWNER : QYV
  61. SEGMENT_NAME : BIG_TABLE
  62. ALLOCATED_SPACE : 125829120
  63. RECLAIMABLE_SPACE: 81788928
  64. RECOMMENDATIONS : 壓縮對象 QYV.BIG_TABLE, 估計可以節省 81788928 字節。
  65. SOLUTION 1 : alter table "QYV"."BIG_TABLE" compress for oltp
  66. SOLUTION 2 : alter table "QYV"."BIG_TABLE" move
  67. SOLUTION 3 :
  68. Segment Advice --------------------------
  69. TABLESPACE_NAME : USERS
  70. SEGMENT_OWNER : U1
  71. SEGMENT_NAME : BIG_TABLE
  72. ALLOCATED_SPACE : 125829120
  73. RECLAIMABLE_SPACE: 109535475
  74. RECOMMENDATIONS : 啟用表 U1.BIG_TABLE 的行移動並執行收縮, 估計可以節省 10953547
  75. 5 字節。
  76. SOLUTION 1 : alter table "U1"."BIG_TABLE" shrink space
  77. SOLUTION 2 : alter table "U1"."BIG_TABLE" shrink space COMPACT
  78. SOLUTION 3 : alter table "U1"."BIG_TABLE" enable row movement
  79. Segment Advice --------------------------
  80. TABLESPACE_NAME : USERS
  81. SEGMENT_OWNER : U1
  82. SEGMENT_NAME : TT
  83. ALLOCATED_SPACE : 27262976
  84. RECLAIMABLE_SPACE: 17314513
  85. RECOMMENDATIONS : 啟用表 U1.TT 的行移動並執行收縮, 估計可以節省 17314513 字節。
  86. SOLUTION 1 : alter table "U1"."TT" shrink space
  87. SOLUTION 2 : alter table "U1"."TT" shrink space COMPACT
  88. SOLUTION 3 : alter table "U1"."TT" enable row movement
  89. sys@ORCL> SELECT
  90. 2 ‘Task Name : ‘ || f.task_name || chr(10) ||
  91. 3 ‘Segment Name : ‘ || o.attr2 || chr(10) ||
  92. 4 ‘Segment Type : ‘ || o.type || chr(10) ||
  93. 5 ‘Partition Name : ‘ || o.attr3 || chr(10) ||
  94. 6 ‘Message : ‘ || f.message || chr(10) ||
  95. 7 ‘More Info : ‘ || f.more_info TASK_ADVICE
  96. 8 FROM dba_advisor_findings f
  97. 9 ,dba_advisor_objects o
  98. 10 WHERE o.task_id = f.task_id
  99. 11 AND o.object_id = f.object_id
  100. 12 AND f.task_name like ‘BIG_TABLE Advice‘
  101. 13 ORDER BY f.task_name;
  102. TASK_ADVICE
  103. -----------------------------------------------------------------------------------------------------------------------------------
  104. Task Name : BIG_TABLE Advice
  105. Segment Name : BIG_TABLE
  106. Segment Type : TABLE
  107. Partition Name :
  108. Message : 啟用表 U1.BIG_TABLE 的行移動並執行收縮, 估計可以節省 109535475 字節。
  109. More Info : 分配空間:125829120: 已用空間:16293645: 可回收空間:109535475:
  110. Task Name : BIG_TABLE Advice
  111. Segment Name : BIG_TABLE
  112. Segment Type : TABLE
  113. Partition Name :
  114. Message : 啟用表 U1.BIG_TABLE 的行移動並執行收縮, 估計可以節省 109535475 字節。
  115. More Info : 分配空間:125829120: 已用空間:16293645: 可回收空間:109535475:

技術分享圖片


刪除一個任務:

[sql] view plain copy
    1. u1@ORCL> exec dbms_advisor.delete_task(‘BIG_TABLE Advice‘);
    2. PL/SQL 過程已成功完成。

dbms_advisor 手動生成段顧問建議!