upgrading to oracle database 12c without pain

62

Upload: letruc

Post on 02-Jan-2017

234 views

Category:

Documents


0 download

TRANSCRIPT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Upgrading to Oracle Database 12c Without Pain And How Oracle Database 12c Release 2 Optimizer Features Will Help

Nigel Bayliss Optimizer Product Manager @vldbb http://blogs.oracle.com/optimizer Data Warehousing Product Management Team

Copyright © 2016, 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.

3

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

• Available now

– Exadata Express Cloud Service

• Coming soon

– Database Cloud Services

– Exadata Cloud Machine

4

Announcing Oracle Database 12c Release 2 on Oracle Cloud

Oracle is presenting features for Oracle Database 12c Release 2 on Oracle Cloud. We will announce availability of the On-Prem release sometime after Open World.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

5

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Upgrading to Oracle Database 12c Without Pain

• From: –Oracle Database 11g Release 2 or...

–Oracle Database 12c Release 1

• To: –Oracle Database 12c Release 2

• With a word about Oracle Database 12c Release 1

6

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

7

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Stepping up to Oracle Database 12c

•Understand the principles

•Select the features you want to use

•Control the features you want to use

8

The Evolution of the Adaptive Optimizer

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

The Goal of the Oracle Optimizer

• To find a good SQL execution plan for every query –Oracle must figure out how to execute queries

–Better execution plans yield better performance

• The optimizer uses cardinality estimates to find the best execution plans –"How many rows?"

9

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

The Cost-Based Optimizer Uses Statistics

•The database gathers and stores a rich set of statistics about your data

10

Row Count Min/Max #Distinct values

Data Distribution

Correlation ...and more...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

But Statistics Are Not Always Enough

•SQL statements can be REALLY complex

•Schemas can be REALLY complex

•Data can be REALLY complex

11

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

The Goal of the Adaptive Optimizer

•To account for complexity –Cardinality misestimates

–Missing statistics

• It must adapt!

12

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 13

The Adaptive Optimizer

New in Oracle Database 12c Release 1

12c Optimizer

Adaptive Statistics

Optimizer Adaptive Features

Change SQL execution plans at runtime Learn from previous executions and choose better SQL execution plans

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14

Oracle Database 11g 11g Optimizer

Column Usage Statistics

Answers the question, "How are columns used in queries?" This metadata is persisted to the data dictionary G a t h e r S t a t i s t i c s

F O R A L L C O L U M N S S I Z E A U T O ( t h e d e f a u l t )

Histograms Better statistics for skewed datasets

Learn from previous executions (on a query-by-query basis)

Cardinality Feedback

The Data Dictionary

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 15

Dynamic Sampling In Oracle Database 11g 11g Optimizer

Column Usage Statistics

Histograms

Cardinality Feedback

Dynamic Sampling

Sample data to account for missing or inadequate statistics

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 16

From Oracle Database 12c Release 1

The Oracle Optimizer in Oracle Database 12c 12c Optimizer

Column Usage Statistics

SQL Plan Directives

The lessons learned from previous executions are SHARED between queries

Statistics feedback for single table cardinality and joins

Dynamic Statistics (Adaptive)

Adaptive Plans

Histograms

Adapt at runtime

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 17

From Oracle Database 12c Release 1

Oracle Optimizer Adaptive Features 12c Optimizer

Column Usage Statistics

SQL Plan Directives

Dynamic Statistics (Adaptive)

G a t h e r S t a t i s t i c s

Column group statistics created automatically

G a t h e r S t a t i s t i c s F O R A L L C O L U M N S S I Z E A U T O

Histograms

Statistics feedback for single table cardinality and joins

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

18

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

Controlling adaptive features

Oracle Database 12c Release 1

12c Optimizer

Adaptive Statistics

Optimizer Adaptive Features

Change plans at runtime Learn from previous executions

OPTIMIZER_ADAPTIVE_FEATURES

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 20

A Wide Spectrum of Oracle Databases

Highly responsive Time critical - Strict SLAs

Long running High complexity Large datasets

Most Databases

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 21

Adaptive features controlled with OPTIMIZER_ADAPTIVE_FEATURES

Oracle Database 12c Release 1

Oracle Database 12c Release 1 Default

Zero Adaptive

Fully Adaptive

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 22

A new default

Oracle Database 12c Release 2

Oracle Database 12c Release 2 Default

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 23

A new default and finer control

Oracle Database 12c Release 2

Default Adaptive

Fully Adaptive

Minimal Adaptive

Oracle Database 12c Release 2 Default

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 24

Finer control of adaptive features – new database parameters

From Oracle Database 12c Release 2

12c Optimizer

Adaptive Statistics

Optimizer Adaptive Features

Change plans at runtime Learn from previous executions

OPTIMIZER_ADAPTIVE_FEATURES Obsolete

OPTIMIZER_ADAPTIVE_PLANS OPTIMIZER_ADAPTIVE_STATISTICS

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

OPTIMIZER_ADAPTIVE_STATISTICS (FALSE)

25

New default behavior

From Oracle Database 12c Release 2

12c Optimizer

Adaptive Statistics

Optimizer Adaptive Features

Change plans at runtime Learn from previous executions

OPTIMIZER_ADAPTIVE_PLANS (TRUE)

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 26

A new default and finer control

Oracle Database 12c Release 2

Default Adaptive

Fully Adaptive

Minimal Adaptive

Oracle Database 12c Release 2 Default

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27

Oracle Database 12c Release 2

Oracle Optimizer Adaptive Features 12c Optimizer

Column Usage Statistics

SQL Plan Directives

Dynamic Statistics (Adaptive)

G a t h e r S t a t i s t i c s

Column group statistics created automatically

G a t h e r S t a t i s t i c s F O R A L L C O L U M N S S I Z E A U T O

Histograms

Statistics feedback for single table cardinality and joins

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28

Oracle Database 12c Release 2

Oracle Optimizer Adaptive Features – New Defaults 12c Optimizer

Column Usage Statistics

SQL Plan Directives

Statistics feedback for single table cardinality ONLY

G a t h e r S t a t i s t i c s G a t h e r S t a t i s t i c s F O R A L L C O L U M N S S I Z E A U T O

Histograms

Dynamic Statistics

Adaptive Plans

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29

Oracle Database 12c Release 2

Oracle Optimizer Adaptive Features 12c Optimizer

Column Usage Statistics

SQL Plan Directives

Statistics feedback for single table cardinality ONLY

G a t h e r S t a t i s t i c s G a t h e r S t a t i s t i c s F O R A L L C O L U M N S S I Z E A U T O

Histograms

Dynamic Statistics

Adaptive Plans

DBMS_STATS preference: AUTO_STAT_EXTENSIONS Default is OFF

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30

Oracle Database 12c Release 2

Oracle Optimizer Adaptive Features 12c Optimizer

Column Usage Statistics

SQL Plan Directives

Statistics feedback for single table cardinality ONLY

G a t h e r S t a t i s t i c s G a t h e r S t a t i s t i c s F O R A L L C O L U M N S S I Z E A U T O

Histograms

Dynamic Statistics

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Oracle Database 12c Release 2

•Adaptive features ‒Defaults suitable for the widest range of workloads

‒Finer control

• In the context of upgrades –Defaults are closer to the behavior of Oracle Database 11g

31

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

32

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

You Have Hundreds of Databases

• You expect Oracle to provide defaults that deliver excellent performance for most systems –"KISS" - and use the defaults in Oracle Database 12c Release 2

• The defaults have been chosen on the basis of what works best for widest range of workloads

33

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 34

Traditionally, Oracle has always recognized that DBAs need more control in complex and critical environments If you want more control...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 35

Default Adaptive Features

Use the defaults

OPTIMIZER_ADAPTIVE_PLANS (TRUE) OPTIMIZER_ADAPTIVE_STATISTICS (FALSE)

Default Adaptive

Fully Adaptive

Minimal Adaptive

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 36

Minimal Adaptive

Set OPTIMIZER_ADAPTIVE_PLANS=FALSE

Default Adaptive

Fully Adaptive

Minimal Adaptive

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 37

Fully Adaptive

Set OPTIMIZER_ADAPTIVE_STATISTICS=TRUE Optionally, set DBMS_STATS preference AUTO_STAT_EXTENSIONS=ON

Default Adaptive

Fully Adaptive

Minimal Adaptive

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Adaptive Statistics

•High added value where… –Queries are longer-running

–Queries are complex

–Schema is complex

–Data is complex

•Ad-hoc query environments –SQL plan directives allow the optimizer to learn from queries

and share this information with others

38

OPTIMIZER_ADAPTIVE_STATISTICS=TRUE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Things to be Aware Of

•Changes to optimizer statistics –New histogram types

–More compact incremental statistics for partitioned tables (from Oracle Database 12c Release 2)

–Global temporary tables (GTTs) use SESSION private statistics by default

• SQL plan management evolution is automated in Oracle

39

Oracle gives you control: http://blogs.oracle.com/optimizer

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Remember: You Have Fine Control of Optimizer Statistics

• You can test new statistics without deleting the old –DBMS_STATS.SET_GLOBAL_PREFS('PUBLISH', 'false');

DBMS_STATS.GATHER… optimizer_use_pending_statistics = TRUE DBMS_STATS.PUBLISH_PENDING_STATS

• You roll out changes to statistics back to a point-in-time –DBMS_STATS.RESTORE_SCHEMA_STATS

40

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 41

You have a critical environment where any performance regression is unacceptable...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 42

What if You Could Do This?

Good query execution plans = Good query performance

Start With Oracle Database 11g

Oracle Database 12c

3. Use SQL Plan Baselines

4. Evolve 3. Use SQL Plan Baselines

The same execution plans = Good query performance

Evolve over time... Auto-discover better execution plans = Better query performance

Upgrade

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 43

Capture SQL plan baselines in pre-upgrade database

Use SQL Plan Management

1. Capture

SQL Plan Baselines

Good Execution Plans

SQL Plan Baselines

No Performance Regressions

Oracle Database 11g

Oracle Database 12c

3. Use SQL Plan Baselines 4. Evolve

Better Performance

2. Upgrade OR Copy

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

Use optimizer_features_enable (OFE) to capture in post-upgrade database

SQL Plan Management – Even Post-Upgrade

1. Capture

SQL Plan Baselines

Good Execution Plans

No Performance Regressions

Oracle Database 12c

2. Use SQL Plan Baselines 3. Evolve

Better Performance

optimizer_features_enable='12.2.0.1'

optimizer_features_enable='11.2.0.4'

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 45

Taking control of change…

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

SQL Plan Management

• Fix existing SQL execution plans, but don't set them in stone

•Reduce the risk of change –Capture baselines and control SQL execution plans

–New SQL execution plans are validated automatically

–Better SQL execution plans can be accepted automatically

46

Taking control of change

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 47

Enabling Optimizer Adaptive Statistics in a Controlled Manner

SQL Plan Management

1. Capture

SQL Plan Baselines

Good Execution Plans

No Performance Regressions

Oracle Database 12c

2. Use SQL Plan Baselines 3. Evolve

Better Performance

optimizer_adaptive_statistics=TRUE

optimizer_adaptive_statistics=FALSE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 48

Upgrading from Oracle Database 12c Release 1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Upgrading from Oracle Database 12c Release 1

• You want to continue with everything on, then keep things as they are

– Set OPTIMIZER_ADAPTIVE_STATISTICS=TRUE

– Set DBMS_STATS preference AUTO_STAT_EXTENSIONS to ON to allow column group statistics to be created in response to SQL plan directives

• If adaptive features are disabled, consider using adaptive plans: – Default OPTIMIZER_ADAPTIVE_PLANS (the default is TRUE)

– Default OPTIMIZER_ADAPTIVE_STATISTICS (the default is FALSE)

• Remember SQL plan management!

49

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

50

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Oracle Database 12c Release 1 - Options

•You should probably keep things as they are –OPTIMIZER_ADAPTIVE_FEATURES

–OPTIMIZER_FEATURES_ENABLE

•Defaults can be expected to work well for most systems

51

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Oracle Database 12c Release 1 - Options

• If you want the new adaptive parameters in Oracle Database 12c Release 1 request patch for bug# 22652097

• To control auto column group creation using DBMS_STATS preference AUTO_STAT_EXTENSIONS, apply patch for bug# 21171382

52

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Agenda

53

Stepping up to Oracle Database 12c

Enhancements in Oracle Database 12c Release 2

Upgrade Approach

A word about Oracle Database 12c Release 1

From test to production

1

2

3

4

5

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

From Test to Production

• The optimizer generates metadata

• Metadata gives rise to additional statistics

• Testing on realistic data can generate useful metadata and statistics

• Consider whether you need to copy metadata and statistics from one database to another

54

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Migrating Oracle Optimizer Metadata and Statistics

55

Keep It Simple - Data Pump!

Column Usage Statistics

SQL Plan Directives expdp content=metadata_only

include=statistics impdp table_exists_action=skip include=statistics remap_schema=s1:s2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Migrating Oracle Optimizer Metadata and Statistics

56

Other Recommended Methods

Column Usage Statistics

SQL Plan Directives

Export/Import SQL Plan Directives DBMS_SPD.PACK_STGTAB_DIRECTIVE

DBMS_STATS.TRANSFER_STATS (DB Link)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Summary • Oracle Database 12c Release 2 Adaptive Features –Have been improved

–Have finer controls

–By default, are closer to the behavior of Oracle Database 11g

–Most systems should use the new default settings for adaptive features

• For complex systems, choose adaptive features to match your priorities and/or workload

• SQL plan management helps you manage change

• Optimizer metadata can be migrated from test to production

57

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

More Information

•Future white papers... –Optimizer with Oracle Database 12c Release 2

–Understanding Optimizer Statistics with Oracle Database 12c Release 2

–Best Practices for Gathering Optimizer Statistics with Oracle Database 12c Release 2

–SQL Plan Management with Oracle Database 12c Release 2

58

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

More Information

•Demo ground booth SDB-017: Optimizer and Statistics

•Oracle Optimizer Blog –http://blogs.oracle.com/optimizer

•Upgrade Blog –http://blogs.oracle.com/UPGRADE

•Upgrade and Migrate to Oracle Database 12c: Live and Uncensored 4:15 p.m. - 5:00 p.m. Moscone South - 102

59

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Safe Harbor Statement

The preceding 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.

60

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 61