0
<Insert Picture Here>




Move to Oracle Database 11g – The whole Story
Mike Dietrich
Database Upgrade & Utilities
ORACLE ...
Agenda

                            Preparation

                            Upgrade

                            News and...
Agenda

                            Preparation

                            Upgrade

                            News and...
Tuning with the right tools ...




© 2009 Oracle Corporation                      250
Agenda

                            Preparation

                            Upgrade

                            News and...
Optimizer Statistics Gathering
        • DML Monitoring is switched ON for all tables
        • INSERTS, UPDATES and DELET...
Optimizer Statistics Gathering
         • Default maintenance job




© 2009 Oracle Corporation                     253
Optimizer Statistics Gathering
        • Configure maintenance schedule




© 2009 Oracle Corporation                     ...
Optimizer Statistics Gathering
        • Configure settings and parameters




© 2009 Oracle Corporation                  ...
GATHER_STATS_JOB in 11g
        • Starting the job manually:
              • Start:
                     exec
            ...
GATHER_STATS_JOB
            Table-                                   every 3h
         Monitoring ON                SMON ...
GATHER_STATS_JOB
            Objects:                                  Analysis order:
                                   ...
Optimizer without statistics
        • What happens if there are no object statistics?
                            The opt...
Extended Optimizer Statistics
        •      Business problem - Correlated Columns
                    •       Real data o...
Example
 Single column

     SELECT ……FROM..
     WHERE model = '530xi'                   Make        Model   Color
     B...
Example
  Non-correlated columns

     SELECT ……FROM..
                                             Make        Model   Co...
Example
 Correlated columns - no extended statistics
     SELECT ……FROM..                         Make       Model   Color...
Example
 Correlated columns - extended statistics
     SELECT ……FROM..
     WHERE model = '530xi'                     Make...
Agenda

                            Preparation

                            Upgrade

                            News and...
Requirements for Diagnostics & Tuning
        •         STATISTICS_LEVEL=TYPICAL [default]
                   •        Alt...
Diagnostics & Tuning Concept since 10g

                        SGA

                   In-memory           MMON
         ...
Tuning Basics since 10g
        •         AWR (Automatic Workload Repository)
                   •        Statistics repos...
Tuning Basics since 10g
        •         AWR
                   •        Change retention and interval:




© 2009 Oracle...
Tuning Basics since 10g
        •         AWR
                   •        Change retention and interval:
                 ...
Tuning Basics since 10g
         •         Transport the AWR
                     •      Extract:
                        ...
Tuning Basics since 10g
        •         ASH (Active Session History)
                   •        ASH is key for database...
Tuning Basics since 10g
        •         Define ASH reporting interval




© 2009 Oracle Corporation                     ...
Tuning Basics since 10g
           •




© 2009 Oracle Corporation                274
Tuning Basics - STATSPACK
       •         STATSPACK is still available in 10g and 11g
                   •        Use eit...
Tuning Basics since 10g
        •         ADDM (Automatic Database Diagnostic Monitor)
                   •        Knowled...
Tuning Basics since 10g
        • ADDM findings – example:




© 2009 Oracle Corporation              277
Memory Tuning - SGA & PGA

                            Streams Pool           Streams Pool
                  OLTP         ...
Automatic Shared Memory Management
• To enable ASMM SGA_TARGET (or MEMORY_TARGET ) and
  STATISTICS_LEVEL=TYPICAL must be ...
Automatic Shared Memory Management
• Statistics collection driven by MMAN in the
  background




                      MM...
DB Management Pack Enhancements 11g
         • Diagnostic Pack
               • ADDM for RAC
               • AWR Baseline...
Agenda

                            Preparation

                            Upgrade

                            News and...
DB Management Pack Enhancements
         • Diagnostic Pack
               • ADDM for RAC
               • AWR Baselines an...
SQL Real-Time Monitoring
       • Dedicated statistics collected for a single execution of a
         SQL statement when i...
SQL Real-Time Monitoring Report
        • DBMS_SQLTUNE.REPORT_SQL_MONITOR() allows to
          display monitoring informa...
SQL Real-Time Monitoring Report
        • Example for an active and long running PQ statement:




© 2009 Oracle Corporati...
Manual SQL Tuning Challenges
        • Complex - requires expertise in several domains
               • SQL optimization: ...
SQL Tuning in Oracle Database 10g

                                                         Evaluate
                     ...
SQL Tuning Automation in 11g
         • Fully automatic SQL Tuning task
               • Runs automatically:
             ...
SQL Tuning Automation in 11g
        • Configure Automatic SQL Tuning




© 2009 Oracle Corporation                   290
SQL Tuning Automation in 11g
        • Configure Automatic SQL Tuning




© 2009 Oracle Corporation                   291
Automatic SQL Tuning in 11g

                             Implement           Test SQL Profiles
                          ...
Result Summary




© 2009 Oracle Corporation     293
SQL Tuning - step-by-step
         1. Monitoring
         2. Identify statement(s) requiring tuning
         3. Use tuning...
SQL Tuning Advisor
        • Can be used in EM or on CLI (via DBMS_SQLTUNE)
        • 2 Different tuning modes are availab...
SQL Tuning - Sources
           Automatic selection




                    AWR
                                    ADDM  ...
SQL Tuning
         • Example: Results „Tuning Advisor“   SQL Profile




© 2009 Oracle Corporation                       ...
SQL Tuning
        • Example: Compare original to new explain plan




© 2009 Oracle Corporation                          ...
SQL Tuning with DBMS_SQLTUNE
         • 4 steps to get an SQL Profile
               •   DBMS_SQLTUNE.CREATE_TUNING_TASK
 ...
SQL Tuning - DBMS_SQLTUNE
          Tuning Task Management             SQL Profile Management
           o
           o   ...
SQL Profile containing literals - not binds
      • SQL Profiles can handle statements containing literals
        (instea...
SQL Profile - evaluation
      • SQL Profiles should be evaluated before making them
        available to every user:
    ...
SQL Profiling Effectiveness
         • Workload of a big market research customer in EMEA -
           73 high load querie...
SQL Profiling Effectiveness
         • Workload of a big market research customer in EMEA -
           73 high load querie...
SQL Profiling Time
         • All together the optimization for all 73 statements
           took approximately 1½h !!!


...
Agenda

                            Preparation

                            Upgrade

                            News and...
Challenges
        • >90% of so-called upgrade problems aren't really upgrade
          problems but performance issues af...
Challenges
        • Optimizer - prevent execution plan changes:
               • Classical approach:
                    ...
Agenda

                            Preparation

                            Upgrade

                            News and...
Without SQL Plan Management
        • Challenging to "freeze" execution plans and statistics
        • Difficulty:
       ...
SQL Plan Management
        • First preventive and fully transparent database
          mechanism to ensure plan stability...
SQL Plan Management
        • 3 phases for plan stability:
               • Capture
                  • Create a SQL Basel...
SQL Plan Management
        • White Paper:
               • http://www.oracle.com/technology/products/
                   ...
SQL Plan Management
        • Phase 1 - Capture
               • Schematically - OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=TRUE...
SQL Plan Management
        • Phase 2 - Selection
               • Same statement parsed again but a different plan will b...
SQL Plan Management
        • Phase 2 - Selection
               • Schematically: OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FAL...
SQL Plan Management
        • Phase 3 - Evolution
               • Schematically:


                                Plan H...
SQL Plan Management
        • Database Control:




© 2009 Oracle Corporation          318
SQL Plan Management
        • DatabaseControl - Configuration:



                                  Start with 5-14 weeks:...
SQL Plan Management - Scenarios
        • Upgrade scenario 1:
                 • Parameterize the optimizer back to the "o...
SQL Plan Management - Upgrade 1
        • Upgrade scenario 1

                                                            ...
SQL Plan Management - Upgrade 2
        • Upgrade scenario 2
                                  Staging

                  ...
SQL Plan Management - New Application
        • New application (module) gets delivered
               @Vendor            ...
SQL Plan Management - New Application
        • New application (module) gets delivered - and it's possible
          to d...
SQL Plan Management - Outlines
        • Migration of Stored Outlines to SQL Plan
          Management:
                 •...
Agenda

                            Preparation

                            Upgrade

                            News and...
Real Application Testing
        • Goal:
               • Record and replay a real workload to see how the new system
    ...
Real Application Testing
        • Real Application Testing consists of:
               • Database Replay
                ...
Real Application Testing
        • White Paper:
               • Database Replay:
                     • http://www.oracle...
Real Application Testing
        • Database Control:




© 2009 Oracle Corporation               330
Agenda

                            Preparation

                            Upgrade

                            News and...
Database Replay
        • Replay actual production database workload in test environment
        • Identify, analyze and f...
Database Replay
        • Workflow:




© 2009 Oracle Corporation      333
Restrictions
        • Capture won't record (currently):
               •   Direct Path Loads
               •   MTS Reque...
Database Replay
        • Step-By-Step




© 2009 Oracle Corporation      335
Database Replay
        1. Create a copy of the database to replay the workload
                   •        RMAN Duplicate...
Database Replay
        2. Some guidelines for Workload Capture
                     •      Ideally restart prod database
...
Database Replay
        2. Workflow in EM: Workload Capture




© 2009 Oracle Corporation                     338
Database Replay
        2. Preparation steps in EM: Workload Capture




© 2009 Oracle Corporation                        ...
Database Replay
        3. Define Workload Filter:
                   •        Default:
                            All us...
Database Replay
        • Start Capture in line mode:
               • BEGIN
                 BEGIN
                    DB...
Database Replay
        • Database Control - capture statistics:




© 2009 Oracle Corporation                          342
Database Replay
        • Export AWR in line mode:
               • BEGIN
                 BEGIN
                    DBMS_...
Database Replay
        • Preprocessing captured workload:




© 2009 Oracle Corporation                    344
Database Replay
        • Preprocessing in line mode:
               • BEGIN
                 BEGIN
                  DBMS...
Database Replay
        • Import AWR snap
               •
                    DECLARE db_id number;
                    D...
Database Replay
        • Workload Replay: replay parameters




© 2009 Oracle Corporation                      347
Database Replay
        • Initialize and parameterize workload replay clients (wrc):
               • BEGIN
              ...
Database Replay
        • Workload Replay Clients: Calibrate
               • $> wrc mode=calibrate replaydir=/tmp/testing...
Database Replay
        • Start Workload Replay in command line mode:
               • BEGIN
                 BEGIN
      ...
Database Replay
        • Monitor divergence stats:




© 2009 Oracle Corporation             351
Database Replay
        • Workload Replay result:




© 2009 Oracle Corporation           352
Database Replay
        • Workload replay reporting in CLI:
               • DECLARE
                 DECLARE
            ...
Agenda

                            Preparation

                            Upgrade

                            News and...
SQL Performance Analyzer: Workflow
                 Production                                     Test

                 ...
SPA for a 9i workload against 11g
        • Upgrade scenario from 9i directly to 11g

                                    ...
SPA for 10.2.0.2 => 10.2.0.4
        • Setup
                       10.2.0.2                       10.2.0.4

             ...
SPA for a 9i workload against 11g
        • Enable statistics timing:
              •     alter system set timed_statistic...
SPA for a 9i workload against 11g
        • Create the mapping table in 9i:
              •     create table MAPPING_TABLE...
SPA for a 9i workload against 11g
        • Create a directory object in 11g:
              •     create or replace DIRECT...
SPA for a 9i workload against 11g
        • Create a SQL Tuning Set (STS) in 11g:
              •    declare
             ...
SPA for a 9i workload against 11g
        • Create a SPA task in 11g:
                •    var tname varchar2(200);
      ...
SPA for a 9i workload against 11g
        • Parameterize the SPA task
                •     begin
                      be...
SPA for a 9i workload against 11g
        • Establish "Before Change" trial (from collected 9i info)
                    b...
SPA for a 9i workload against 11g
        • Compare results
              •     execute
                    execute
      ...
SPA for a 9i workload against 11g
        • Generate summary report
              •     set
                    set     he...
SPA for a 9i workload against 11g
        • Generate regressed SQL report
              •    set
                   set   ...
SPA for a 9i workload against 11g
        • Generate changed plans report
              •     set
                    set ...
Real World Experience: SPA
        • Regressed report in detail:




© 2009 Oracle Corporation                 369
Real World Experience: SPA
        • Regressed report in detail:




© 2009 Oracle Corporation                 370
Real World Experience: SPA
        • Regressed report in detail:



                                        Empty because ...
SPA for a 9i workload against 11g
        • Compare results
              • Be cautious in interpreting trial results
    ...
Capturing a SQL Workload for SPA
        • Capture from cursor cache
              • Create a SQL Tuning Set (STS)
       ...
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Oracle Upgrade11gr1 Workshop2
Upcoming SlideShare
Loading in...5
×

Oracle Upgrade11gr1 Workshop2

2,832

Published on

Presentación de Oracle sobre la actualización a 11g

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,832
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
446
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Oracle Upgrade11gr1 Workshop2"

  1. 1. <Insert Picture Here> Move to Oracle Database 11g – The whole Story Mike Dietrich Database Upgrade & Utilities ORACLE Corporation
  2. 2. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Performance Testing Best Practices © 2009 Oracle Corporation 3
  3. 3. Agenda Preparation Upgrade News and Task List Object Statistics Monitoring Diagnostics & Tuning SQL Tuning Performance Testing Best Practices © 2009 Oracle Corporation 249
  4. 4. Tuning with the right tools ... © 2009 Oracle Corporation 250
  5. 5. Agenda Preparation Upgrade News and Task List Object Statistics Performance Monitoring Diagnostics & Tuning SQL Tuning Performance Testing Best Practices © 2009 Oracle Corporation 251
  6. 6. Optimizer Statistics Gathering • DML Monitoring is switched ON for all tables • INSERTS, UPDATES and DELETES will be monitored • To exclude tables lock their statistics • execute execute DBMS_STATS.LOCK_TABLE_STATS('SH','TAB1'); DBMS_STATS.LOCK_TABLE_STATS('SH','TAB1'); • For statistics collection always use DBMS_STATS, never use ANALYZE anymore © 2009 Oracle Corporation 252
  7. 7. Optimizer Statistics Gathering • Default maintenance job © 2009 Oracle Corporation 253
  8. 8. Optimizer Statistics Gathering • Configure maintenance schedule © 2009 Oracle Corporation 254
  9. 9. Optimizer Statistics Gathering • Configure settings and parameters © 2009 Oracle Corporation 255
  10. 10. GATHER_STATS_JOB in 11g • Starting the job manually: • Start: exec exec DBMS_AUTO_TASK_IMMEDIATE.GATHER_OPTIMIZER_STATS DBMS_AUTO_TASK_IMMEDIATE.GATHER_OPTIMIZER_STATS • Monitoring progress: SELECT job_name,state SELECT job_name,state FROM dba_scheduler_jobs FROM dba_scheduler_jobs WHERE program_name='GATHER_STATS_PROG'; WHERE program_name='GATHER_STATS_PROG'; • For more information see Note:731935.1 (This note can just be downloaded under support guidance and is not visible in Metalink) © 2009 Oracle Corporation 256
  11. 11. GATHER_STATS_JOB Table- every 3h Monitoring ON SMON manually: SQL> exec DBMS_STATS. FLUSH_DATABASE_MONITORING_INFO(); No# of DMLs in: DBA/USER_TAB_MODIFICATIONS: Tables without statistics: Table changed >10%: EMPTY STALE Automatic Job – once a day: manually: SQL> exec DBMS_STATS.GATHER_SCHEMA_STATS('SCOTT'); © 2009 Oracle Corporation 257
  12. 12. GATHER_STATS_JOB Objects: Analysis order: high 27% 27% 54% 54% Priority 54% 54% 27% 27% Statistics: EMPTY Statistics: STALE Statistics: OK low © 2009 Oracle Corporation 258
  13. 13. Optimizer without statistics • What happens if there are no object statistics? The optimizer (CBO) will estimate (at parsing time) the statistics for tables and indexes Prerequisite: OPTIMIZER_DYNAMIC_SAMPLING=2 [Default since 10g] • Level 0 - Dynamic Sampling off (~OLTP) • Level 2 – Optimizer checks first 64 blocks of object • For descriptions of all levels: Performance Tuning Guide • Example: http://www.oracle.com/technology/oramag/oracle/09-jan/o19asktom.html © 2009 Oracle Corporation 259
  14. 14. Extended Optimizer Statistics • Business problem - Correlated Columns • Real data often shows correlations between various attributes • E.g. job title influences salary, car model influences make, seasons affect the amount of sold goods (e.g. snow shoes in winter) • Optimizer has to estimate the correct cardinality • “Does an additional filter reduce the result set or not?” • Solution • Extended Optimizer Statistics provides a mechanism to collect statistics on a group of columns • Full integration into existing statistics framework • Automatically maintained with column statistics • Instantaneous and transparent benefit for any migrated application Improved Cardinality leads to Improved Plans © 2009 Oracle Corporation 260
  15. 15. Example Single column SELECT ……FROM.. WHERE model = '530xi' Make Model Color BMW 530xi RED BMW 530xi RED BMW 530xi BLACK BMW 530xi BLACK BMW 530xi SILVER BMW 530xi SILVER PORSCHE 911 RED MERC SLK BLACK • Three records selected. MERC C320 SLIVER • Single column statistics are accurate --------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | --------------------------------------------------------------------- |* 1 | TABLE ACCESS FULL| CARS | 1 | 3 | 3 | ---------------------------------------------------------------------
  16. 16. Example Non-correlated columns SELECT ……FROM.. Make Model Color WHERE model = '530xi' AND color = 'RED' BMW 530xi RED BMW 530xi BLACK BMW 530xi RED BMW 530xi SILVER PORSCHE 911 RED • One record selected MERC SLK BLACK • No correlated columns MERC C320 SLIVER • Additional predicate reduces result set • Single column statistics are sufficient --------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | --------------------------------------------------------------------- |* 1 | INDEX RANGE SCAN| C_MC | 1 | 1 | 1 | ---------------------------------------------------------------------
  17. 17. Example Correlated columns - no extended statistics SELECT ……FROM.. Make Model Color WHERE model = '530xi' BMW 530xi RED AND make = 'BMW'; BMW 530xi BLACK BMW 530xi RED BMW 530xi SILVER BMW 530xi BLACK PORSCHE 911 RED BMW 530xi SILVER MERC SLK BLACK MERC C320 SLIVER • Three records selected. • Correlated columns • Additional predicate has no effect • Single column statistics are NOT sufficient --------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | --------------------------------------------------------------------- |* 1 | INDEX RANGE SCAN| C_MC | 1 | 1 | 3 | ---------------------------------------------------------------------
  18. 18. Example Correlated columns - extended statistics SELECT ……FROM.. WHERE model = '530xi' Make Model Color AND make = 'BMW'; BMW 530xi RED BMW 530xi BLACK BMW 530xi RED BMW 530xi SILVER BMW 530xi BLACK PORSCHE 911 RED BMW 530xi SILVER MERC SLK BLACK MERC C320 SLIVER • Three records selected. • Multi-column statistics solve the problem --------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | --------------------------------------------------------------------- |* 1 | TABLE ACCESS FULL| CARS | 1 | 3 | 3 | ---------------------------------------------------------------------
  19. 19. Agenda Preparation Upgrade News and Task List Object Statistics Performance Monitoring Diagnostics & Tuning SQL Tuning Performance Testing Best Practices © 2009 Oracle Corporation 265
  20. 20. Requirements for Diagnostics & Tuning • STATISTICS_LEVEL=TYPICAL [default] • Alternative Settings: • BASIC • ALL • TYPICAL (recommended setting) will enable: • Automatic SGA Tuning • Automatic statistics collection • Active Session History • _ash_enabled=false to switch off ASH • DML monitoring © 2009 Oracle Corporation 266
  21. 21. Diagnostics & Tuning Concept since 10g SGA In-memory MMON statistics AWR Snapshots Alerts ADDM ADDM Proactive results DBA Reactive © 2009 Oracle Corporation 267
  22. 22. Tuning Basics since 10g • AWR (Automatic Workload Repository) • Statistics repository in SYSAUX tablespace for AWR snapshots • Self managing • Data stored in the AWR is collected by MMON • Every 60 minutes and kept for 7 (8 in 11g) days [default] • Query AWR contents: DBA_HIST-Views • The automatic removal of certain snapshots can be supressed for later analysis by defining them as a baseline • Snapshots can be created on demand at every time: • EXEC dbms_workload_repository.create_snapshot(); • Size and analysis: • @?/rdbms/admin/awrinfo.sql • Report: • @?/rdbms/admin/awrrpt.sql • Single statements: @?/rdbms/admin/awrsqrpt.sql © 2009 Oracle Corporation 268
  23. 23. Tuning Basics since 10g • AWR • Change retention and interval: © 2009 Oracle Corporation 269
  24. 24. Tuning Basics since 10g • AWR • Change retention and interval: • Recommendation: 30-60 minutes and 20-31 days © 2009 Oracle Corporation 270
  25. 25. Tuning Basics since 10g • Transport the AWR • Extract: DBMS_SWRF_INTERNAL.AWR_EXTRACT( dmpfile => 'awr_data.dmp', dmpdir => 'TMP_DIR', bid => 302, eid => 305); • Load in temporary schema: DBMS_SWRF_INTERNAL.AWR_LOAD( SCHNAME => 'AWRTEMP', dmpfile => 'awr_data', dmpdir => 'TMP_DIR' ); • Move temporary data to AWR location (SYS): DBMS_SWRF_INTERNAL.MOVE_TO_AWR( SCHNAME => 'AWRTEMP_USER'); • Why? • Evaluations outside of production systems • Central repository © 2009 Oracle Corporation 271
  26. 26. Tuning Basics since 10g • ASH (Active Session History) • ASH is key for database diagnosis • Circular buffer inside the SGA • Fixed size: 2MB x #CPUs (max. 5% of the SGA or <30MB) • Contains information about active sessions • ~10% of the information gets written to the AWR by MMNL • View: V$ACTIVE_SESSION_HISTORY • Further info: Note:243132.1 • Report: • @?/rdbms/admin/ashrpt.sql © 2009 Oracle Corporation 272
  27. 27. Tuning Basics since 10g • Define ASH reporting interval © 2009 Oracle Corporation 273
  28. 28. Tuning Basics since 10g • © 2009 Oracle Corporation 274
  29. 29. Tuning Basics - STATSPACK • STATSPACK is still available in 10g and 11g • Use either AWR/ASH (Diagnostic Pack license required) or STATSPACK • See Note:394937.1 (STATSPACK Guide) © 2009 Oracle Corporation 275
  30. 30. Tuning Basics since 10g • ADDM (Automatic Database Diagnostic Monitor) • Knowledge base for performance diagnostics • Analyze performance snapshots and give recommendations • Runs proactively every hour (upon AWR snapshot) or can be invoked manually: SQL> @$ORACLE_HOME/rdbms/admin/addmrpt.sql SQL> @$ORACLE_HOME/rdbms/admin/addmrpti.sql (RAC) © 2009 Oracle Corporation 276
  31. 31. Tuning Basics since 10g • ADDM findings – example: © 2009 Oracle Corporation 277
  32. 32. Memory Tuning - SGA & PGA Streams Pool Streams Pool OLTP Batch Buffer Cache Buffer Cache Large Pool SGA Large Pool SQL Cache SQL Cache Java Pool Java Pool sort sort PGA © 2009 Oracle Corporation 278
  33. 33. Automatic Shared Memory Management • To enable ASMM SGA_TARGET (or MEMORY_TARGET ) and STATISTICS_LEVEL=TYPICAL must be set Auto–Tuned Database buffer cache Redo log Streams pool buffer Shared pool Large pool Fixed SGA Java pool Whole SGA SGA_MAX_SIZE=...
  34. 34. Automatic Shared Memory Management • Statistics collection driven by MMAN in the background MMAN Coordinates size Background: Monitors all of each single SGA Memory components and SGA component Broker coordinates resize operations
  35. 35. DB Management Pack Enhancements 11g • Diagnostic Pack • ADDM for RAC • AWR Baselines and Adaptive Thresholds • Transportable AWR • Tuning Pack • Automatic SQL Tuning Advisor • Partition Advisor • Real-time SQL Monitoring • SQL Plan Management and Plan Evolution © 2009 Oracle Corporation 281
  36. 36. Agenda Preparation Upgrade News and Task List Object Statistics Performance Monitoring Diagnostics & Tuning SQL Tuning Performance Testing Best Practices © 2009 Oracle Corporation 282
  37. 37. DB Management Pack Enhancements • Diagnostic Pack • ADDM for RAC • AWR Baselines and Adaptive Thresholds • Transportable AWR • Tuning Pack • Real-time SQL Monitoring • Automatic SQL Tuning Advisor • Partition Advisor © 2009 Oracle Corporation 283
  38. 38. SQL Real-Time Monitoring • Dedicated statistics collected for a single execution of a SQL statement when its execution becomes high-load • Target all parallel queries, parallel DML or parallel DDL • Target serial execution that exceed 5 sec of CPU or I/O time • Global SQL level statistics are collected: V$SQL_MONITOR • Plan level statistics are collected (#rows, memory, temp space, start/end date): V$SQL_PLAN_MONITOR • Statistics are updated quasi real-time while the query executes • Statistics for completed executions are retained for at least 5 minutes • On by default © 2009 Oracle Corporation 284
  39. 39. SQL Real-Time Monitoring Report • DBMS_SQLTUNE.REPORT_SQL_MONITOR() allows to display monitoring information • Format: xml, text and html • Join with ASH data • SQL Real-time monitoring with GUI integrated in 11.1.0.7 © 2009 Oracle Corporation 285
  40. 40. SQL Real-Time Monitoring Report • Example for an active and long running PQ statement: © 2009 Oracle Corporation 286
  41. 41. Manual SQL Tuning Challenges • Complex - requires expertise in several domains • SQL optimization: adjust the execution plan • Access design: provide fast data access • SQL design: use appropriate SQL constructs • Time consuming • Each SQL statement is unique • Potentially large number of statements to tune • Never ending task • SQL workload always evolving • Plan regressions can happen © 2009 Oracle Corporation 287
  42. 42. SQL Tuning in Oracle Database 10g Evaluate Implement Recommendations Workload DBA DBA Generate Recommendations one hour DBA ADDM Invoke Advisor SQL Tuning AWR SQL Tuning Candidates Advisor Some meaningful automation, but the DBA is still required © 2009 Oracle Corporation 288
  43. 43. SQL Tuning Automation in 11g • Fully automatic SQL Tuning task • Runs automatically: • Maintenance Window, CPU resource controlled, on/off switch • Identifies, ranks and tunes candidate SQL • Leverages SQL Tuning Advisor • Candidate SQL automatically chosen • Excluded: parallel queries, DML/DDL, recursive, ad-hoc (infrequent) • Tests and (optionally) implements SQL profiles • Only implements significantly improved plans (3x) • Time budgeted to avoid run-away plans • DBA can still invoke the advisor manually for reactive tuning, like in 10g © 2009 Oracle Corporation 289
  44. 44. SQL Tuning Automation in 11g • Configure Automatic SQL Tuning © 2009 Oracle Corporation 290
  45. 45. SQL Tuning Automation in 11g • Configure Automatic SQL Tuning © 2009 Oracle Corporation 291
  46. 46. Automatic SQL Tuning in 11g Implement Test SQL Profiles SQL Profiles Workload Generate Recommendations Choose Candidate SQL SQL Tuning one Candidates week It’s Automatic! View Reports / AWR Control DBA Process © 2009 Oracle Corporation 292
  47. 47. Result Summary © 2009 Oracle Corporation 293
  48. 48. SQL Tuning - step-by-step 1. Monitoring 2. Identify statement(s) requiring tuning 3. Use tuning advisors • SQL Access Advisor: • Indexes • Materialized Views • Indexes on Materialized Views • Requires a workload • SQL Tuning Advisor • Optimizer in Tuning Mode • Create profiles for the statements • Can operate on a single SQL statement 4. Implement recommendations © 2009 Oracle Corporation 294
  49. 49. SQL Tuning Advisor • Can be used in EM or on CLI (via DBMS_SQLTUNE) • 2 Different tuning modes are available: • “Comprehensive mode” runs through all possible analysis options • “Limited mode” will not generate a SQL Profile • SQL Profiles contain information that lead to improved execution plans without changing the application code • Use different optimizer settings • Correct wrong/missing statistics • Correct wrong estimates • SQL Profiles are persistent • SQL Profiles don’t change the original SQL statement • SQL Profiles can be transported within SQL Tuning Sets (STS) • SQL Profiles can be tested and verified without any risk © 2009 Oracle Corporation 295
  50. 50. SQL Tuning - Sources Automatic selection AWR ADDM High-load SQL SQL Sources Manual choice AWR SQL Tuning Cursor Cache Advisor SQL Tuning Set Filter / Rank (STS) User-defined © 2009 Oracle Corporation 296
  51. 51. SQL Tuning • Example: Results „Tuning Advisor“ SQL Profile © 2009 Oracle Corporation 297
  52. 52. SQL Tuning • Example: Compare original to new explain plan © 2009 Oracle Corporation 298
  53. 53. SQL Tuning with DBMS_SQLTUNE • 4 steps to get an SQL Profile • DBMS_SQLTUNE.CREATE_TUNING_TASK • DBMS_SQLTUNE.EXECUTE_TUNING_TASK • DBMS_SQLTUNE.REPORT_TUNING_TASK • DBMS_SQLTUNE.ACCEPT_SQL_PROFILE © 2009 Oracle Corporation 299
  54. 54. SQL Tuning - DBMS_SQLTUNE Tuning Task Management SQL Profile Management o o CANCEL_TUNING_TASK CANCEL_TUNING_TASK o o ACCEPT_SQL_PROFILE ACCEPT_SQL_PROFILE o o CREATE_TUNING_TASK CREATE_TUNING_TASK o o ALTER_SQL_PROFILE ALTER_SQL_PROFILE o o DROP_TUNING_TASK DROP_TUNING_TASK o o DROP_SQL_PROFILE DROP_SQL_PROFILE o o EXECUTE_TUNING_TASK EXECUTE_TUNING_TASK o o IMPLEMENT_TUNING_TASK IMPLEMENT_TUNING_TASK o o INTERRUPT_TUNING_TASK INTERRUPT_TUNING_TASK Select SQL Statements o o REPORT_AUTO_TUNING_TASK REPORT_AUTO_TUNING_TASK o o CAPTURE_CURSOR_CACHE_SQLSET CAPTURE_CURSOR_CACHE_SQLSET o o REPORT_TUNING_TASK REPORT_TUNING_TASK o o SELECT_CURSOR_CACHE SELECT_CURSOR_CACHE o o RESUME_TUNING_TASK RESUME_TUNING_TASK o o REPORT_SQL_MONITOR REPORT_SQL_MONITOR o o SCRIPT_TUNING_TASK SCRIPT_TUNING_TASK o o SELECT_WORKLOAD_REPOSITORY SELECT_WORKLOAD_REPOSITORY o o RESET_TUNING_TASK RESET_TUNING_TASK o o SQLTEXT_TO_SIGNATURE SQLTEXT_TO_SIGNATURE o o SET_TUNING_TASK_PARAMETER SET_TUNING_TASK_PARAMETER Staging Table Management SQL Tuning Set Management o o CREATE_STGTAB_SQLPROF CREATE_STGTAB_SQLPROF o o ADD_SQLSET_REFERENCE ADD_SQLSET_REFERENCE o o CREATE_STGTAB_SQLSET CREATE_STGTAB_SQLSET o o CREATE_SQLSET CREATE_SQLSET o o PACK_STGTAB_SQLPROF PACK_STGTAB_SQLPROF o o DELETE_SQLSET DELETE_SQLSET o o PACK_STGTAB_SQLSET PACK_STGTAB_SQLSET o o DROP_SQLSET DROP_SQLSET o o REMAP_STGTAB_SQLPROF REMAP_STGTAB_SQLPROF o o LOAD_SQLSET LOAD_SQLSET o o REMAP_STGTAB_SQLSET REMAP_STGTAB_SQLSET o o REMOVE_SQLSET_REFERENCE REMOVE_SQLSET_REFERENCE o o UNPACK_STGTAB_SQLPROF UNPACK_STGTAB_SQLPROF o o SELECT_SQLSET SELECT_SQLSET o o UNPACK_STGTAB_SQLSET UNPACK_STGTAB_SQLSET o o UPDATE_SQLSET UPDATE_SQLSET © 2009 Oracle Corporation 300
  55. 55. SQL Profile containing literals - not binds • SQL Profiles can handle statements containing literals (instead of binds) as well: • Since 11.1.0.6 possible in EM: • In 10.2 only possible on command line: exec exec :p_name:=dbms_sqltune.accept_sql_profile :p_name:=dbms_sqltune.accept_sql_profile (task_name=>'XT',name=>'XT_PROFILE', FORCE_MATCH=>TRUE); (task_name=>'XT',name=>'XT_PROFILE', FORCE_MATCH=>TRUE); SQL> select name, status, force_matching, sql_text from dba_sql_profiles; NAME STATUS FOR SQL_TEXT ------- -------- ---- -------------------------------------------- MY_PROF ENABLED YES select /*+ use_nl(c) ordered */ count(*) from sh.sales s, sh.customers c where c.cust_id = s.cust_id and CUST_FIRST_NAME = 'Mike' © 2009 Oracle Corporation 301
  56. 56. SQL Profile - evaluation • SQL Profiles should be evaluated before making them available to every user: exec exec :p_name:=dbms_sqltune.accept_sql_profile :p_name:=dbms_sqltune.accept_sql_profile task_name=>'XT',name=>'XT_PROFILE', task_name=>'XT',name=>'XT_PROFILE', category=>'TEST_ENV', FORCE_MATCH=>TRUE) category=>'TEST_ENV', FORCE_MATCH=>TRUE) alter session set SQLTUNE_CATEGORY='TEST_ENV'; alter session set SQLTUNE_CATEGORY='TEST_ENV'; • Now evaluate the statement's profile in a limited user context • If verification went fine, make it accessible to everybody exec exec dbms_sqltune.alter_sql_profile dbms_sqltune.alter_sql_profile (name=>'XT_PROFILE', (name=>'XT_PROFILE', attribute_name=>'CATEGORY',value=>'DEFAULT') attribute_name=>'CATEGORY',value=>'DEFAULT') © 2009 Oracle Corporation 302
  57. 57. SQL Profiling Effectiveness • Workload of a big market research customer in EMEA - 73 high load queries identified requiring tuning • Query execution time Before vs. After Before … … After Time (s) Time (s) 10000 10 0 0 0 1000 10 0 0 100 10 0 10 10 1 1 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 Queries Queries © 2009 Oracle Corporation 303
  58. 58. SQL Profiling Effectiveness • Workload of a big market research customer in EMEA - 73 high load queries identified requiring tuning • Manual tuning compared to automatic tuning of these 73 complex DWH statements Average Worst Cumulative Response Response Response Time Time Time No Tuning 817s 5751s 58821s Manual Tuning 30s 275s 2131s Automatic 13s 59s 929s Tuning (SQL Pr) © 2009 Oracle Corporation 304
  59. 59. SQL Profiling Time • All together the optimization for all 73 statements took approximately 1½h !!! Time (s) 10 0 0 10 0 10 1 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 Queries © 2009 Oracle Corporation 305
  60. 60. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Challenges SQL Plan Management Database Replay Performance Testing SQL Performance Analyzer Best Practices © 2009 Oracle Corporation 306
  61. 61. Challenges • >90% of so-called upgrade problems aren't really upgrade problems but performance issues after the upgrade • It's important to use sufficient test scenarios and methods • Typical problem areas: • Optimizer - execution plans • Queries are slow • Reports or batches take longer to complete • Increased resource requirements • Code path changes © 2009 Oracle Corporation 307
  62. 62. Challenges • Optimizer - prevent execution plan changes: • Classical approach: • Rule Based Optimizer (RBO desupport since Oracle 10g - Note:189702.1) • Hints • Stored Outlines • Rewriting SQL statements • optimizer_features_enabled=n.n.n • Change specific optimizer parameters • Import and fix object and systems statistics • Modern, efficient and better resource consumption: • SQL Plan Management • SQL Profiling © 2009 Oracle Corporation 308
  63. 63. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Challenges SQL Plan Management Database Replay Performance Testing SQL Performance Analyzer Best Practices © 2009 Oracle Corporation 309
  64. 64. Without SQL Plan Management • Challenging to "freeze" execution plans and statistics • Difficulty: • Statement has been parsed and a plan got created Verification happens during execution: GB Parse Execute Plan acceptable HJ HJ • Now some conditions get changed (statistics, upgrade, parameters) • A new plan will be created - is it better or worse??? GB Parse Execute Plan possibly NL not acceptable NL © 2009 Oracle Corporation 310
  65. 65. SQL Plan Management • First preventive and fully transparent database mechanism to ensure plan stability • SQL execution plans will be recorded • A SQL Baseline will be created • Consist of accepted execution plans • Contains only plans for statements being parsed/executed more than once • Only known, verified and accepted plans will be used • Package: DBMS_SPM © 2009 Oracle Corporation 311
  66. 66. SQL Plan Management • 3 phases for plan stability: • Capture • Create a SQL Baseline representing trusted execution plans • Baseline is stored in SQL Management Base in SYSAUX • Selection • Only accepted plans will be used • New execution plans will be recorded to the plan history • Evolution • Evaluate all unverified plans for a given statement in the plan history to become either accepted or rejected © 2009 Oracle Corporation 312
  67. 67. SQL Plan Management • White Paper: • http://www.oracle.com/technology/products/ manageability/database/pdf/ow07/ spm_white_paper_ow07.pdf © 2009 Oracle Corporation 313
  68. 68. SQL Plan Management • Phase 1 - Capture • Schematically - OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=TRUE GB Parse Execute Plan acceptable HJ HJ Initial plan SQL MANAGEMENT BASE will be accepted Plan History Residing in SYSAUX TS. Will occupy max. 10% of SYSAUX. if repeated and Weekly job will delete plans will be added to the not used since 53 weeks [default]. SQL Plan Baseline Plan Baseline GB SQL Profiles HJ HJ © 2009 Oracle Corporation 314
  69. 69. SQL Plan Management • Phase 2 - Selection • Same statement parsed again but a different plan will be created • OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FALSE GB Parse NL NL New plan will be added to the Plan History but it won't Plan History be used unless it has been verified GB NL Plan Baseline NL GB HJ HJ © 2009 Oracle Corporation 315
  70. 70. SQL Plan Management • Phase 2 - Selection • Schematically: OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FALSE GB Parse Execute Plan known and HJ acceptable HJ The optimizer will use Plan History only one of the VERIFIED plans stored GB in the SQL Baseline NL Plan Baseline because only they will NL guarantee PLAN GB STABILITY HJ HJ © 2009 Oracle Corporation 316
  71. 71. SQL Plan Management • Phase 3 - Evolution • Schematically: Plan History Plan History Worse plan will GB GB GB Plan Baseline be kept in the NL Plan Baseline NL Plan History NL NL GB NL GB GB NL NL HJ HJ NL HJ HJ Equal or better plans can be added to the SQL Plan Baseline DBA schedules verification DBA Optimizer © 2009 Oracle Corporation 317
  72. 72. SQL Plan Management • Database Control: © 2009 Oracle Corporation 318
  73. 73. SQL Plan Management • DatabaseControl - Configuration: Start with 5-14 weeks: exec DBMS_SPM.CONFIGURE('plan_retention_weeks',5); © 2009 Oracle Corporation 319
  74. 74. SQL Plan Management - Scenarios • Upgrade scenario 1: • Parameterize the optimizer back to the "old" behaviour • Works for all database releases since 8.0.3 • Upgrade scenario 2: • Transport the well known plans to the new release • Works since 10gR2 • Ship a new application (module) along with appropriate SQL plan baselines: • Ship the best execution plans for the new statements within a staging table and ensure that they'll be used • Works since 11g © 2009 Oracle Corporation 320
  75. 75. SQL Plan Management - Upgrade 1 • Upgrade scenario 1 STS Repeatable plans will be added to the Plan Baseline upon 2nd Now: Different execution plans created with OFE=11 Plan History will be added to GB the Plan History NL for later verification Plan Baseline NL GB GB GB NL HJ NL NL NL HJ OPTIMIZER_FEATURES_ENABLE=9.2.0 OPTIMIZER_FEATURES_ENABLE=11.1.0 OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=TRUE OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FALSE © 2009 Oracle Corporation 321
  76. 76. SQL Plan Management - Upgrade 2 • Upgrade scenario 2 Staging STS exp imp STS Table expdp impdp DB-Link ... 10.2 plans will be added to the SQL Plan Baseline Plan History GB NL Plan Baseline NL GB GB GB NL HJ NL NL NL HJ Every new and better plan will be stored in the Plan History © 2009 Oracle Corporation 322
  77. 77. SQL Plan Management - New Application • New application (module) gets delivered @Vendor @Customer DBMS_SPM.CREATE_STGTAB_BASELINE Staging Staging exp imp expdp impdp Table Table DBMS_SPM.UNPACK_STGTAB_BASELINE DBMS_SPM.PACK_STGTAB_BASELINE Plan Baseline Plan Baseline GB GB GB GB GB GB NL HJ NL NL NL HJ NL NL NL NL HJ HJ © 2009 Oracle Corporation 323
  78. 78. SQL Plan Management - New Application • New application (module) gets delivered - and it's possible to deliver the right execution plans, too: • @Software Vendor: • Create a staging table using DBMS_SPM.CREATE_STGTAB_BASELINE • Pack the required baselines into the staging table using DBMS_SPM.PACK_STGTAB_BASELINE • Export the staging table into a dump file using Data Pump or Export and transport it to the target system • @Customer: • Import the dump file into the target database • Unpack the SQL Plan Baselines from the staging table into the SQL Management Base of the target system • DBMS_SPM.UNPACK_STGTAB_BASELINE © 2009 Oracle Corporation 324
  79. 79. SQL Plan Management - Outlines • Migration of Stored Outlines to SQL Plan Management: • Tuning-Pack: Record execution plans in 10.2 and transport them (see Upgrade Case 1) • No Tuning-Pack license: • Upgrade your database with Outlines to 11g • Set CAPTURE_SQL_PLAN_BASELINES=TRUE • Make sure your run your outlined queries 2x • Plans will be recorded to the Baseline • Switch CAPTURE_SQL_PLAN_BASELINES=FALSE • Delete the Stored Outlines © 2009 Oracle Corporation 325
  80. 80. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Challenges SQL Plan Management Database Replay Performance Testing SQL Performance Analyzer Best Practices © 2009 Oracle Corporation 326
  81. 81. Real Application Testing • Goal: • Record and replay a real workload to see how the new system performs • Find regressions and changing plans before the upgrade • Licensable database pack "Real Application Testing" Available since Oracle Database 11.1.0.6 Available with patch set 10.2.0.4 Available as single patch for 9.2.0.8 and 10.2.0.2/3 For patch numbers please see Note:560977.1 © 2009 Oracle Corporation 327
  82. 82. Real Application Testing • Real Application Testing consists of: • Database Replay • Package DBMS_WORKLOAD_CAPTURE • Package DBMS_WORKLOAD_REPLAY Can be used for upgrades from: 9.2.0.8 and 10.2.0.2/3/4 to 11.1.0.x • SQL Performance Analyzer (SPA) • Package DBMS_SQLPA Can be used for upgrades from: 9.2.0.8 and 10.2.0.2/3/4 to 11.1.0.x 9.2.0.8 to 10.2.0.2/3/4 10.2.0.2/3 to 10.2.0.4 • SQL Tuning Sets (STS) • Package DBMS_SQLTUNE © 2009 Oracle Corporation 328
  83. 83. Real Application Testing • White Paper: • Database Replay: • http://www.oracle.com/technology/products/manageability/database/pdf/o w07/db_replay_white_paper_ow07_1.pdf • SQL Performance Analyzer: • http://www.oracle.com/technology/products/manageability/database/pdf/o w07/spa_white_paper_ow07.pdf • OTN: • http://www.oracle.com/technology/products/manageability/database/index.html • Command line examples for REPLAY and SPA: • http://www.oracle.com/technology/products/manageability/database/tools/db_replay_cli.zip • http://www.oracle.com/technology/products/manageability/database/tools/spa_scripts.zip © 2009 Oracle Corporation 329
  84. 84. Real Application Testing • Database Control: © 2009 Oracle Corporation 330
  85. 85. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Challenges SQL Plan Management Database Replay Performance Testing SQL Performance Analyzer Best Practices © 2009 Oracle Corporation 331
  86. 86. Database Replay • Replay actual production database workload in test environment • Identify, analyze and fix potential instabilities before making changes to production • Capture Workload in Production • Capture full production workload with real load, timing & concurrency characteristics • Move the captured workload to test system • Replay Workload in Test • Make the desired changes in test system • Replay workload with full production characteristics • Honor commit ordering • Analyze & Report • Errors • Data divergence • Performance divergence © 2009 Oracle Corporation 332
  87. 87. Database Replay • Workflow: © 2009 Oracle Corporation 333
  88. 88. Restrictions • Capture won't record (currently): • Direct Path Loads • MTS Requests • Oracle Streams and Advanced Replication • Non-PL/SQL based AQ • Flashback queries • Non-SQL based object access • Distributed transaction • Remote DESCRIBE and COMMITs © 2009 Oracle Corporation 334
  89. 89. Database Replay • Step-By-Step © 2009 Oracle Corporation 335
  90. 90. Database Replay 1. Create a copy of the database to replay the workload • RMAN Duplicate • Snapshot Standby • Possibly create a guaranteed restore point © 2009 Oracle Corporation 336
  91. 91. Database Replay 2. Some guidelines for Workload Capture • Ideally restart prod database • Why? All transactions can be closed correctly • RAC: Just one instance up and running, then start Capture and now start the other instances • Start Capture before users logon to the database • Therefore start database in RESTRICTED mode • As soon as Capture begins it will switch to UNRESTRICTED © 2009 Oracle Corporation 337
  92. 92. Database Replay 2. Workflow in EM: Workload Capture © 2009 Oracle Corporation 338
  93. 93. Database Replay 2. Preparation steps in EM: Workload Capture © 2009 Oracle Corporation 339
  94. 94. Database Replay 3. Define Workload Filter: • Default: All user sessions will be recorded • Inclusion filter: Only specified user session will be recorded • Exclusion filter: All but specified user sessions will be recorded • For instance exclude "OMS" and "emagent%" • Both filters can't be combined • Package: DBMS_WORKLOAD_CAPTURE.ADD_FILTER(fname=>'myFilter', DBMS_WORKLOAD_CAPTURE.ADD_FILTER(fname=>'myFilter', fattribute=>'USER', fattribute=>'USER', fvalue=>'SCOTT'); fvalue=>'SCOTT'); DBMS_WORKLOAD_CAPTURE.DELETE_FILTER(fname=>'myFilter'); DBMS_WORKLOAD_CAPTURE.DELETE_FILTER(fname=>'myFilter'); © 2009 Oracle Corporation 340
  95. 95. Database Replay • Start Capture in line mode: • BEGIN BEGIN DBMS_WORKLOAD_CAPTURE.START_CAPTURE DBMS_WORKLOAD_CAPTURE.START_CAPTURE (name => 'hammerora_single_01', (name => 'hammerora_single_01', dir => 'TESTING', dir => 'TESTING', default_action => 'EXCLUDE'); default_action => 'EXCLUDE'); END; END; / / • Stop Capture: • BEGIN BEGIN DBMS_WORKLOAD_CAPTURE.FINISH_CAPTURE(); DBMS_WORKLOAD_CAPTURE.FINISH_CAPTURE(); END; END; / / © 2009 Oracle Corporation 341
  96. 96. Database Replay • Database Control - capture statistics: © 2009 Oracle Corporation 342
  97. 97. Database Replay • Export AWR in line mode: • BEGIN BEGIN DBMS_WORKLOAD_CAPTURE.EXPORT_AWR DBMS_WORKLOAD_CAPTURE.EXPORT_AWR (capture_id => 5); (capture_id => 5); END; END; / / © 2009 Oracle Corporation 343
  98. 98. Database Replay • Preprocessing captured workload: © 2009 Oracle Corporation 344
  99. 99. Database Replay • Preprocessing in line mode: • BEGIN BEGIN DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE DBMS_WORKLOAD_REPLAY.PROCESS_CAPTURE (capture_dir => 'TESTING'); (capture_dir => 'TESTING'); END; END; / / • Restore database from backup © 2009 Oracle Corporation 345
  100. 100. Database Replay • Import AWR snap • DECLARE db_id number; DECLARE db_id number; BEGIN BEGIN db_id := DBMS_WORKLOAD_CAPTURE.IMPORT_AWR db_id := DBMS_WORKLOAD_CAPTURE.IMPORT_AWR (capture_id => 5, staging_schema => 'TPCC'); (capture_id => 5, staging_schema => 'TPCC'); END; END; / / © 2009 Oracle Corporation 346
  101. 101. Database Replay • Workload Replay: replay parameters © 2009 Oracle Corporation 347
  102. 102. Database Replay • Initialize and parameterize workload replay clients (wrc): • BEGIN . BEGIN DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY DBMS_WORKLOAD_REPLAY.INITIALIZE_REPLAY (replay_name => 'play_hammerora_01', (replay_name => 'play_hammerora_01', replay_dir => 'TESTING'); replay_dir => 'TESTING'); DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY DBMS_WORKLOAD_REPLAY.PREPARE_REPLAY (synchronization => TRUE); (synchronization => TRUE); END; END; / / © 2009 Oracle Corporation 348
  103. 103. Database Replay • Workload Replay Clients: Calibrate • $> wrc mode=calibrate replaydir=/tmp/testing • Workload Replay Clients: Start • $> wrc system/oracle mode=replay © 2009 Oracle Corporation 349
  104. 104. Database Replay • Start Workload Replay in command line mode: • BEGIN BEGIN DBMS_WORKLOAD_REPLAY.START_REPLAY (); DBMS_WORKLOAD_REPLAY.START_REPLAY (); END; END; / / © 2009 Oracle Corporation 350
  105. 105. Database Replay • Monitor divergence stats: © 2009 Oracle Corporation 351
  106. 106. Database Replay • Workload Replay result: © 2009 Oracle Corporation 352
  107. 107. Database Replay • Workload replay reporting in CLI: • DECLARE DECLARE cap_id cap_id NUMBER; NUMBER; rep_id rep_id NUMBER; NUMBER; rep_rpt rep_rpt CLOB; CLOB; BEGIN BEGIN cap_id := DBMS_WORKLOAD_REPLAY.GET_REPLAY_INFO cap_id := DBMS_WORKLOAD_REPLAY.GET_REPLAY_INFO (dir => 'TESTING'); (dir => 'TESTING'); /* Get the latest replay for that capture */ /* Get the latest replay for that capture */ SELECT max(id) INTO rep_id SELECT max(id) INTO rep_id FROM FROM dba_workload_replays WHERE capture_id=cap_id; dba_workload_replays WHERE capture_id=cap_id; rep_rpt := DBMS_WORKLOAD_REPLAY.REPORT rep_rpt := DBMS_WORKLOAD_REPLAY.REPORT (replay_id => rep_id, (replay_id => rep_id, format => DBMS_WORKLOAD_REPLAY.TYPE_TEXT); format => DBMS_WORKLOAD_REPLAY.TYPE_TEXT); END; END; / / © 2009 Oracle Corporation 353
  108. 108. Agenda Preparation Upgrade News and Task List Diagnostics & Tuning Challenges SQL Plan Management Database Replay Performance Testing SQL Performance Analyzer Best Practices © 2009 Oracle Corporation 354
  109. 109. SQL Performance Analyzer: Workflow Production Test Make Change Steps (1) (2) (3) (4) (5) Capture Transport Execute SQL Execute SQL Compare SQL (STS) STS Pre-change Post-change Perf. (6) Reiterate No Done? (7) Yes Tuned System Production Change / (7) Tuning Deployment © 2009 Oracle Corporation 355
  110. 110. SPA for a 9i workload against 11g • Upgrade scenario from 9i directly to 11g Event 10046 ORCL_ora_133674.trc ORCL_ora_133674.trc copy ORCL_ora_133674.trc ORCL_ora_133674.trc STS ... SQL Performance Analyzer Mapping Table Id Owner Name 123 SH1 SAL1 124 SH2 CUST exp / imp See Note:455889.1 - SPA example © 2009 Oracle Corporation 356
  111. 111. SPA for 10.2.0.2 => 10.2.0.4 • Setup 10.2.0.2 10.2.0.4 Upgrade R2 R2 Capture SQLs Capture SQLs Plan Plan into a STS into a STS Stats Stats SQL SQL SQL Performance Analyzer STS © 2009 Oracle Corporation 357
  112. 112. SPA for a 9i workload against 11g • Enable statistics timing: • alter system set timed_statistics=true; alter system set timed_statistics=true; • Enable tracing on 9i: • alter system set events alter system set events '10046 trace name context forever, level 4'; '10046 trace name context forever, level 4'; © 2009 Oracle Corporation 358
  113. 113. SPA for a 9i workload against 11g • Create the mapping table in 9i: • create table MAPPING_TABLE as create table MAPPING_TABLE as select object_id id, owner, select object_id id, owner, substr(object_name, 1, 30) name substr(object_name, 1, 30) name from from dba_objects dba_objects where where object_type NOT IN object_type NOT IN ('CONSUMER GROUP', 'EVALUATION CONTEXT','FUNCTION', ('CONSUMER GROUP', 'EVALUATION CONTEXT','FUNCTION', 'INDEXTYPE', 'JAVA CLASS', 'JAVA DATA', 'JAVA 'INDEXTYPE', 'JAVA CLASS', 'JAVA DATA', 'JAVA RESOURCE', 'LIBRARY', 'LOB', 'OPERATOR', 'PACKAGE', RESOURCE', 'LIBRARY', 'LOB', 'OPERATOR', 'PACKAGE', 'PACKAGE BODY', 'PROCEDURE', 'QUEUE', 'RESOURCE 'PACKAGE BODY', 'PROCEDURE', 'QUEUE', 'RESOURCE PLAN', 'SYNONYM', 'TRIGGER', 'TYPE', 'TYPE BODY') PLAN', 'SYNONYM', 'TRIGGER', 'TYPE', 'TYPE BODY') union all union all select user_id id, username owner, null name select user_id id, username owner, null name from dba_users; from dba_users; • Disable tracing in 9i afterwards: • alter system set events '10046 trace name context forever off'; alter system set events '10046 trace name context forever off'; • Export mapping table with exp © 2009 Oracle Corporation 359
  114. 114. SPA for a 9i workload against 11g • Create a directory object in 11g: • create or replace DIRECTORY 'SPA_DIR' as '/tmp/spa'; create or replace DIRECTORY 'SPA_DIR' as '/tmp/spa'; • Install SPA one-off patch (see Note:562899.1) or use 11.1.0.7 • Transport event-10046 trace files to the 11g system • Import mapping table © 2009 Oracle Corporation 360
  115. 115. SPA for a 9i workload against 11g • Create a SQL Tuning Set (STS) in 11g: • declare declare mycur mycur DBMS_SQLTUNE.SQLSET_CURSOR; DBMS_SQLTUNE.SQLSET_CURSOR; begin begin DBMS_SQLTUNE.CREATE_SQLSET('SPA_9iWKLD'); DBMS_SQLTUNE.CREATE_SQLSET('SPA_9iWKLD'); open mycur for open mycur for select value(p) from select value(p) from table(DBMS_SQLTUNE.SELECT_SQL_TRACE( table(DBMS_SQLTUNE.SELECT_SQL_TRACE( directory => 'SPA_DIR', directory => 'SPA_DIR', file_name => '%ora%', file_name => '%ora%', mapping_table_name => 'MAPPING_TABLE' mapping_table_name => 'MAPPING_TABLE' select_mode => DBMS_SQLTUNE.SINGLE_EXECUTION)) p; select_mode => DBMS_SQLTUNE.SINGLE_EXECUTION)) p; DBMS_SQLTUNE.LOAD_SQLSET('SPA_9iWKLD', mycur); DBMS_SQLTUNE.LOAD_SQLSET('SPA_9iWKLD', mycur); close mycur; close mycur; end; end; / / • Monitor progress in DBA_SQLSET © 2009 Oracle Corporation 361
  116. 116. SPA for a 9i workload against 11g • Create a SPA task in 11g: • var tname varchar2(200); var tname varchar2(200); execute execute :tname := DBMS_SQLPA.CREATE_ANALYSIS_TASK( :tname := DBMS_SQLPA.CREATE_ANALYSIS_TASK( sqlset_name => ‘SPA_9iWKLD’, sqlset_name => ‘SPA_9iWKLD’, task_name task_name => ‘SPA_TASK_9i_11g’, => ‘SPA_TASK_9i_11g’, description => ‘Test 9i to 11g upgrade'); description => ‘Test 9i to 11g upgrade'); print tname print tname © 2009 Oracle Corporation 362
  117. 117. SPA for a 9i workload against 11g • Parameterize the SPA task • begin begin DBMS_SQLPA.SET_ANALYSIS_TASK_PARAMETER( DBMS_SQLPA.SET_ANALYSIS_TASK_PARAMETER( task_name => ‘SPA_TASK_9i_11g’, task_name => ‘SPA_TASK_9i_11g’, parameter => ‘WORKLOAD_IMPACT_THRESHOLD’, parameter => ‘WORKLOAD_IMPACT_THRESHOLD’, value => 0); value => 0); DBMS_SQLPA.SET_ANALYSIS_TASK_PARAMETER( DBMS_SQLPA.SET_ANALYSIS_TASK_PARAMETER( task_name => ‘SPA_TASK_9i_11g’, task_name => ‘SPA_TASK_9i_11g’, parameter => ‘SQL_IMPACT_THRESHOLD’, parameter => ‘SQL_IMPACT_THRESHOLD’, value => 5); value => 5); end; end; / / • To filter "noise" use "SQL_IMPACT_THRESHOLD"=5 (means only regressed SQL 5% above this threshold will be shown) © 2009 Oracle Corporation 363
  118. 118. SPA for a 9i workload against 11g • Establish "Before Change" trial (from collected 9i info) begin begin DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( task_name task_name => ‘SPA_TASK_9i_11g’, => ‘SPA_TASK_9i_11g’, execution_name => ‘SPA_RUN1_9i’, execution_name => ‘SPA_RUN1_9i’, execution_type => ‘CONVERT SQLSET’, execution_type => ‘CONVERT SQLSET’, execution_desc => ‘9i run generated from STS’); execution_desc => ‘9i run generated from STS’); end; end; / / • Run 11g execution • begin begin DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( task_name task_name => ‘SPA_TASK_9i_11g’, => ‘SPA_TASK_9i_11g’, execution_name => ‘SPA_RUN2_11g’, execution_name => ‘SPA_RUN2_11g’, execution_type => ‘TEST EXECUTE’, execution_type => ‘TEST EXECUTE’, execution_desc => ‘Test now against 11g’); execution_desc => ‘Test now against 11g’); end; end; / / © 2009 Oracle Corporation 364
  119. 119. SPA for a 9i workload against 11g • Compare results • execute execute DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( DBMS_SQLPA.EXECUTE_ANALYSIS_TASK( task_name task_name => ‘SPA_TASK_9i_11g’, => ‘SPA_TASK_9i_11g’, execution_name execution_name => ‘COMPARE_9i_11g_CPU’, => ‘COMPARE_9i_11g_CPU’, execution_type execution_type => ‘COMPARE PERFORMANCE’, => ‘COMPARE PERFORMANCE’, execution_params => DBMS_ADVISOR.ARGLIST( execution_params => DBMS_ADVISOR.ARGLIST( 'COMPARISON_METRIC', 'CPU_TIME', 'COMPARISON_METRIC', 'CPU_TIME', 'EXECUTION_NAME1', 'SPA_RUN1_9i', 'EXECUTION_NAME1', 'SPA_RUN1_9i', 'EXECUTION_NAME2', 'SPA_RUN2_11g'), 'EXECUTION_NAME2', 'SPA_RUN2_11g'), execution_desc execution_desc => ‘Compare 9i vs. 11g on CPU_TIME’); => ‘Compare 9i vs. 11g on CPU_TIME’); • Comparison metrics options: • CPU_TIME Compare performance for at least these two metric • BUFFER_GETS • PARSE_TIME • ELAPSED_TIME • USER_IO_TIME • DISK_READS • DIRECT_WRITES • OPTIMIZER_COST © 2009 Oracle Corporation 365
  120. 120. SPA for a 9i workload against 11g • Generate summary report • set set heading off heading off set set long 1000000000 long 1000000000 set set longchunksize 10000 longchunksize 10000 set set echo off; echo off; set set linesize 1000; linesize 1000; spool /tmp/spa_9i_11g_cpu_summary.html spool /tmp/spa_9i_11g_cpu_summary.html select select xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( 'SPA_TASK_9i_11g', 'SPA_TASK_9i_11g', /* task_name */ /* task_name */ 'html', 'html', /* type */ /* type */ 'typical', 'typical', /* level */ /* level */ 'summary', 'summary', /* section */ /* section */ null, null, /* object_id */ /* object_id */ 100, 100, /* top_sql */ /* top_sql */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ from dual; from dual; spool off spool off © 2009 Oracle Corporation 366
  121. 121. SPA for a 9i workload against 11g • Generate regressed SQL report • set set heading off heading off set set long 1000000000 long 1000000000 set set longchunksize 10000 longchunksize 10000 set set echo off; echo off; set set linesize 1000; linesize 1000; spool /tmp/spa_9i_11g_cpu_regressed.html spool /tmp/spa_9i_11g_cpu_regressed.html select select xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( 'SPA_TASK_9i_11g', 'SPA_TASK_9i_11g', /* task_name */ /* task_name */ 'html', 'html', /* type */ /* type */ 'regressed', 'regressed', /* level */ /* level */ 'all', 'all', /* section */ /* section */ null, null, /* object_id */ /* object_id */ null, null, /* top_sql */ /* top_sql */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ from dual; from dual; spool off spool off © 2009 Oracle Corporation 367
  122. 122. SPA for a 9i workload against 11g • Generate changed plans report • set set heading off heading off set set long 1000000000 long 1000000000 set set longchunksize 10000 longchunksize 10000 set set echo off; echo off; set set linesize 1000; linesize 1000; spool /tmp/spa_9i_11g_changed_plans.html spool /tmp/spa_9i_11g_changed_plans.html select select xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( xmltype(DBMS_SQLPA.REPORT_ANALYSIS_TASK( 'SPA_TASK_9i_11g', 'SPA_TASK_9i_11g', /* task_name */ /* task_name */ 'html', 'html', /* type */ /* type */ 'changed_plans', 'changed_plans', /* level */ /* level */ 'all', 'all', /* section */ /* section */ null, null, /* object_id */ /* object_id */ null, null, /* top_sql */ /* top_sql */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ 'COMPARE_9i_11g_CPU')).getclobval(2,2) /* execution_name */ from dual; from dual; spool off spool off © 2009 Oracle Corporation 368
  123. 123. Real World Experience: SPA • Regressed report in detail: © 2009 Oracle Corporation 369
  124. 124. Real World Experience: SPA • Regressed report in detail: © 2009 Oracle Corporation 370
  125. 125. Real World Experience: SPA • Regressed report in detail: Empty because source db was an Oracle 9i database © 2009 Oracle Corporation 371
  126. 126. SPA for a 9i workload against 11g • Compare results • Be cautious in interpreting trial results • Analysis based on “single_execution” of SQL in 9i does not account for multiple bind variables and plans • Environmental traps: SPA is agnostic of the environment used for pre- and post-change trials • Data changes during SQL tracing • Bias caused by SQL tracing in 9i • Reports may be overly optimistic or pessimistic due to above reasons • Recommended approach is to investigate as follows: • Summary of change impact by CPU_TIME and BUFFER_GETS • Regressed SQL based on CPU_TIME and BUFFER_GETS • All SQL with changed plans © 2009 Oracle Corporation 372
  127. 127. Capturing a SQL Workload for SPA • Capture from cursor cache • Create a SQL Tuning Set (STS) • BEGIN BEGIN DBMS_SQLTUNE.CREATE_SQLSET( DBMS_SQLTUNE.CREATE_SQLSET( sqlset_name => 'SPA_STS', sqlset_name => 'SPA_STS', description => 'Upgrade test STS for SPA'); description => 'Upgrade test STS for SPA'); END; END; / / • Capture SQL directly from the cursor cache into STS • EXEC EXEC DBMS_SQLTUNE.CAPTURE_CURSOR_CACHE_SQLSET( DBMS_SQLTUNE.CAPTURE_CURSOR_CACHE_SQLSET( sqlset_name sqlset_name => 'SPA_STS', => 'SPA_STS', time_limit time_limit => 15*60, => 15*60, repeat_interval => 10, repeat_interval => 10, capture_mode capture_mode => dbms_sqltune.MODE_ACCUMULATE_STATS); => dbms_sqltune.MODE_ACCUMULATE_STATS); © 2009 Oracle Corporation 373
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×