Upload
phungduong
View
223
Download
0
Embed Size (px)
Citation preview
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Database Optimizer Statistics Gathering OSM 7.2.4.1 Enablement Training
November, 2014 Version 1.0
Oracle Confidential – Internal/Restricted/Highly Restricted
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Oracle Confidential – Internal/Restricted/Highly Restricted 2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
Why Care about Database Statistics?
Setting Up for Accurate Statistics Gathering
Maintaining Statistics when Managing Partitions
Maintaining Statistics when Making Changes to Cartridges
Other Operational Considerations
1
2
3
4
5
Oracle Confidential – Internal/Restricted/Highly Restricted 3
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Oracle Database needs statistics about the data in tables to execute requests efficiently. The execution plan is chosen according to the statistics available.
Oracle Confidential – Internal/Restricted/Highly Restricted 4
Why Care about Database Statistics?
•Example select * from employees where name = 'John';
•Without accurate statistics, the database performance can crumble.
If there are only 5 rows
• Look at all rows, even if there is an index on name
If there are 5,000 rows
• Use the index on name
• Likely more efficient
If there are 500,000 rows
• Use the index on name
• Use of index is essential
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Why Care about Database Statistics?
• In OSM, database statistics can become stale or inaccurate
– Frequent data changes
– Big changes to data tables
• OSM 7.2.4.1 has a package of stored procedures available to help manage statistics collection
• This presentation discusses how to manage database statistics for OSM
– Guidance on how to configure with existing Oracle mechanisms
– Use of OSM packaged procedure when appropriate
Oracle Confidential – Internal/Restricted/Highly Restricted 5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Setting up for Accurate Statistics Gathering
Oracle Confidential – Internal/Restricted/Highly Restricted 6
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Setting up for Accurate Statistics Gathering
• By default, Oracle has enabled automatic statistics collection job
– It collects statistics during a predefined maintenance window
Recommendation – leave it enabled
Oracle Confidential – Internal/Restricted/Highly Restricted 7
Automated Optimizer Statistics Collection
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Setting up for Accurate Statistics Gathering
• Automatic statistics gathering job does not gather fixed object statistics
– When missing, optimizer uses default values which can lead to suboptimal execution plans • RMAN, Data Guard, Streams, and Grid Control use fixed tables often
• Another common symptom is extreme TEMP space usage
– Recommendation – gather statistics on fixed objects using DBMS_STATS.GATHER_FIXED_OBJECTS_STATS • Run when there is a representative workload on the system
• Re-run the procedure after major OSM upgrade, database upgrade or DB configuration change
Oracle Confidential – Internal/Restricted/Highly Restricted 8
Gathering Fixed Object Statistics
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Setting up for Accurate Statistics Gathering
• System statistics describe system hardware characteristics (in CPU, I/O util) to query optimizer, to choose a better execution plan
– not automatically collected as part of the automatic statistics gathering job
– Recommendation – run DBMS_STATS.GATHER_SYSTEM_STATS to gather system statistics • Run when there is a representative workload, ideally at peak times
• Run again when CPU speed or I/O component is changed in DB server, or when order volume has significantly increased (e.g. another phase of OSM project went live)
Oracle Confidential – Internal/Restricted/Highly Restricted 9
Gathering System Statistics
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Keeping Order Table Statistics Up-to-Date
• Volatility – how often volume of data changes over time
• In the package, OSM order tables are broadly categorized into 3 levels:
– High Volatility: tables are filled with rows at peak workload but quite empty overnight (when automatic statistics collection job runs)
– Medium Volatility: have some partitions that retain order data, and some partitions that delete data after processing
– Low Volatility: retain data until order is purged
Oracle Confidential – Internal/Restricted/Highly Restricted 10
Order Table Volatility
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Keeping Order Table Statistics Up-to-Date
Oracle Confidential – Internal/Restricted/Highly Restricted 11
Setting Up Statistics Gathering for Order Tables by Volatility
High Volatility
• OM_JMS_EVENT
• OM_JMS_THREAD
• OM_ORDER_STATE_PENDING
• OM_ORDER_STATE_EVENT_PENDING
Medium Volatility
• OM_ORDER_FLOW_COORDINATOR
• OM_COORD_NODE_INSTANCE
• ------------------------------------------
• OM_ORDER_FLOW
• OM_AUTOMATION_CTX
• OM_AUTOMATION_CORRELATION
• OM_ORDER_POS_INPUT
• OM_UNDO_BRANCH_ROOT
• OM_ORCH_DEPENDENCY_PENDING
Low Volatility
• (Majority of order tables; those not listed otherwise)
These tables in brackets are defaulted to medium volatility, but it depends on order completion of the solution. •Move them to high volatility if orders complete in seconds •Move them to low volatility if orders complete in days or weeks •Remain medium if order completion times are mixed
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Keeping Order Table Statistics Up-to-Date
Oracle Confidential – Internal/Restricted/Highly Restricted 12
Setting Up Statistics Gathering for Order Tables by Volatility
High Volatility
• OM_JMS_EVENT
• OM_JMS_THREAD
• OM_ORDER_STATE_PENDING
• OM_ORDER_STATE_EVENT_PENDING
Medium Volatility
• OM_ORDER_FLOW_COORDINATOR
• OM_COORD_NODE_INSTANCE
• ------------------------------------------
• OM_ORDER_FLOW
• OM_AUTOMATION_CTX
• OM_AUTOMATION_CORRELATION
• OM_ORDER_POS_INPUT
• OM_UNDO_BRANCH_ROOT
• OM_ORCH_DEPENDENCY_PENDING
Low Volatility
• (Majority of order tables; those not listed otherwise)
•Schedule statistics gathering when the workload is representative e.g. at peak hours, periodically, e.g. once a day. •Lock statistics for these tables •Do not enable incremental statistics
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Keeping Order Table Statistics Up-to-Date
Oracle Confidential – Internal/Restricted/Highly Restricted 13
Setting Up Statistics Gathering for Order Tables by Volatility
High Volatility
• OM_JMS_EVENT
• OM_JMS_THREAD
• OM_ORDER_STATE_PENDING
• OM_ORDER_STATE_EVENT_PENDING
Medium Volatility
• OM_ORDER_FLOW_COORDINATOR
• OM_COORD_NODE_INSTANCE
• ------------------------------------------
• OM_ORDER_FLOW
• OM_AUTOMATION_CTX
• OM_AUTOMATION_CORRELATION
• OM_ORDER_POS_INPUT
• OM_UNDO_BRANCH_ROOT
• OM_ORCH_DEPENDENCY_PENDING
Low Volatility
• (Majority of order tables; those not listed otherwise)
•Schedule statistics gathering when the workload is representative e.g. near peak hours, periodically, e.g. once every few days. •Enable incremental statistics
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Keeping Order Table Statistics Up-to-Date
Oracle Confidential – Internal/Restricted/Highly Restricted 14
Setting Up Statistics Gathering for Order Tables by Volatility
High Volatility
• OM_JMS_EVENT
• OM_JMS_THREAD
• OM_ORDER_STATE_PENDING
• OM_ORDER_STATE_EVENT_PENDING
Medium Volatility
• OM_ORDER_FLOW_COORDINATOR
• OM_COORD_NODE_INSTANCE
• ------------------------------------------
• OM_ORDER_FLOW
• OM_AUTOMATION_CTX
• OM_AUTOMATION_CORRELATION
• OM_ORDER_POS_INPUT
• OM_UNDO_BRANCH_ROOT
• OM_ORCH_DEPENDENCY_PENDING
Low Volatility
• (Majority of order tables; those not listed otherwise)
•No need to schedule re-gathering; automated optimizer stats collection is sufficient •Enable incremental statistics
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Maintaining Statistics when Managing Partitions
Oracle Confidential – Internal/Restricted/Highly Restricted 15
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Creating a New Partition
• A newly created partition have not yet collected statistics
• Populating statistics on it can avoid performance issues when the new partition is first used
• 2 ways of populating statistics to new partitions:
a) Copy statistics from local system
b) Copy statistics from another system (e.g. from pre-production)
Oracle Confidential – Internal/Restricted/Highly Restricted 16
Populating Statistics for New Partition
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Creating a New Partition
Populate by either:
a) Manually copy statistics from another (older) partition in the system
– Use om_db_stats_pkg.copy_order_ptn_stats procedure
b) Set OSM to automatically perform a)
– Set in om_parameter table: db_stats_auto_copy_to_new_partition to ON_ADD (default is OFF)
c) Manually copy statistics from a pre-defined statistics table (i.e., a "template")
– Use om_db_stats_pkg.copy_order_ptn_stats procedure, with specified source and destination partition names
Oracle Confidential – Internal/Restricted/Highly Restricted 17
Populating Statistics for New Partition – from Local System
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Creating a New Partition
Ideal for initial system deployment, by importing statistics from pre-production
– Export from another system using om_db_stats_pkg.export_order_ptn_stats
– Save to files using om_db_stats_pkg.expdp_order_ptn_stats • files are saved to the DATA_PUMP_DIR directory
– Transfer file (e.g. FTP) to local system
– Load file using om_db_stats_pkg.impdp_order_ptn_stats
– Import using om_db_stats_pkg.import_order_ptn_stats
Oracle Confidential – Internal/Restricted/Highly Restricted 18
Populating Statistics for New Partition – from Another System
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Maintaining Statistics when Making Changes to Cartridges
Oracle Confidential – Internal/Restricted/Highly Restricted 19
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Gathering Cartridge Metamodel Statistics
• Generally, statistics of cartridge metadata tables are kept up-to-date with automatic statistics gathering job
• Recommendation: gather cartridge metadata statistics manually, after extensive deploy, undeploy/purge of cartridges
– Use om_db_stats_pkg.gather_cartridge_stats procedure
Oracle Confidential – Internal/Restricted/Highly Restricted 20
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Other Operational Considerations
Oracle Confidential – Internal/Restricted/Highly Restricted 21
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Performance Tuning on Optimizer Statistics Management
Other aspects of statistics gathering that can be tuned:
– Gather statistics in parallel: Degree controls # of parallel server processes that are used to gather statistics on tables
– Concurrent collection preference
– Incremental Statistics preference
– Cursor Invalidations: _optimizer_invalidation_period controls the spread period of cursor invalidations
– Dynamic Statistics: OPTIMIZER_DYNAMIC_SAMPLING controls when dynamic statistics are used by the optimzer
– METHOD_OPT controls column statistics collection and histogram creation
• Guidelines and recommendations can be found in product docs & KM Note
Oracle Confidential – Internal/Restricted/Highly Restricted 22
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Online vs Offline
Can these statistics management procedures be run on-line?
A: Yes. All procedures in om_db_stats_pkg package (as well as native Oracle DB statistics procedures) can all be executed online. However, you should lower the value of the DEGREE preference of Parallel Collection when gathering statistics during peak hours.
Oracle Confidential – Internal/Restricted/Highly Restricted 23
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
References
• OSM 7.2.4.1 System Administrator’s Guide
• KM Notes:
– OSM 7.2.0.10 Database Optimizer Statistics Management
https://support.oracle.com/epmos/faces/DocumentDisplay?id=1925539.1 • the article also applies to 7.2.4.1. There is specific information (on how medium volatility order
tables are managed by the package) that applies to 7.2.0.10 only and is noted, but otherwise everything else is applicable.
– Best Practices for Managing Optimizer Statistics for OSM
https://support.oracle.com/epmos/faces/DocumentDisplay?id=1662447.1 • This older article is before 7.2.4.1, and precedes the above article. So there is no mention on OSM
packaged support to statistics management.
Oracle Confidential – Internal/Restricted/Highly Restricted 24
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted 25