38
Oracle Open Day טכנולוגיות, חידושים, מגמות וכיוונים למפתחים ומנהלי בסיסי נתונים עמי אהרונוביץ מייסד ומנכ" ל חברתDBAces יו" רilOUG , ארגון משתמשי אורקל בישראל מנהל תחום אורקל ג' ון ברייס- מכללת הייטק[email protected]

Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Embed Size (px)

Citation preview

Page 1: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Oracle Open Dayמגמות וכיוונים, חידושים, טכנולוגיות

למפתחים ומנהלי בסיסי נתונים

עמי אהרונוביץ

DBAcesל חברת "מייסד ומנכ

ארגון משתמשי אורקל בישראל, ilOUGר "יו

מכללת הייטק-ון ברייס'מנהל תחום אורקל ג

[email protected]

Page 2: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Agenda

התכנסות09:00-09:30

דברי פתיחה09:30-10:00

, חידושים, סקירת טכנולוגיות–העולם של אורקל 10:00-10:45

מגמות וכיוונים

הפסקה10:45-11:00

סקירה –אבטחת בסיסי נתונים בסביבת אורקל 11:00-11:45 טכנולוגית וכללי עשה ואל תעשה

11:45-12:30SQL Tuning Tips & Tricks and Best Practices

למפתחים ומנהלי בסיסי נתונים בסביבת אורקל

שאלות ותשובות וסיכום היום12:30-13:00

Page 3: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

?אז למה התכנסנו כאן היום

מגמות , חידושים, טכנולוגיותשממוקד כולו בנושא אירוע ייחודי • אורקלוכיוונים למפתחים ומנהלי בסיסי נתונים בסביבת

הפיתוחים והטכנולוגיות החדשות, הרכישות–

הצגת חזון מערכות המידע העתידי של חברת אורקל–

סקירת המוצרים החדשים המשלבים פתרונות מתקדמים של –

חומרה ותוכנה וכן טכנולוגיות הענן מבית אורקל

סקירת פתרונות מתקדמים בנושא אבטחת בסיסי נתונים והצגת –

כללי עשה ואל תעשה לשיפור רמת האבטחה של בסיס הנתונים

ומתן SQLלכתיבה נכונה של פקודות Best Practices -הצגת טיפים ו–

המלצות עשה ואל תעשה לכוונון ושיפור ביצועי בסיס הנתונים

Page 4: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

?מי אני

• Oracle ACE

• Oracle Certified Professional DBA (OCP)

• 11+ years of expertise as an Oracle DBA consultant and

instructor, specializing in Oracle database core technologies

• Founder and CEO of DBAces delivering expert consulting

and training services using Oracle database technologies

• Specializing in training Oracle University courses

• Oracle team leader – John Bryce Hi-Tech

• President of Israel Oracle User Group

Page 5: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

מכללת הייטק-ון ברייס'פעילות תחום אורקל בג

חברת טק מקבוצת מטריקס הינה -מכללת היי-ברייסון 'חברת ג•הדרכת המחשוב וטכנולוגיית בתחום ההדרכה המובילה בישראל

השירות , המידע והאלקטרוניקה ובתחום הדרכת מיומנות הניהול והמכירות

הדרכה בישראל ומרכזים מרכזי 4טק -מכללת היי-ון ברייס'לג• הרחוקנוספים באירופה ובמזרח

הינה חברת ההדרכה המוסמכת של טק -מכללת היי-ברייסון 'ג•החומרה , חברות בינלאומיות המובילות בתחום התוכנה

, Oracle ,Microsoft ,IBM ,CheckPoint ,Cisco: והתקשורת

VMWare ,RedHat ,Symantec ,Juniper ,Citrix ,Wind River ועוד

Page 6: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

מכללת הייטק-ון ברייס'פעילות תחום אורקל בג

מציעה מגוון עצום של קורסים מקצועיים טק -מכללת היי-ון ברייס'ג•מבוקשים וייחודיים לקהל הרחב ולקהל המקצוענים הטכנולוגים

ובעולםבישראל

, שלהםידועים באיכות טק -מכללת היי-ברייסון 'של גהקורסים •

פשרותהרבה ובהכשרה מקצועית חסרת בעדכניות

מתאימים הן למי שרוצה להיכנס לתחום מסוים או לבצע הקורסים •והן למי שרוצה להרחיב את הידע שלו או למקסם , הסבה מקצועית

ועוד, את התמחותו בענף

Page 7: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

מכללת הייטק-ון ברייס'פעילות תחום אורקל בג

• Oracle 11g Database Programming:

– SQL

– PL/SQL

– SQL Tuning

– Advanced PL/SQL

– Oracle & .NET Advanced Programming

– Oracle Application Express Advanced Workshop

Page 8: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

מכללת הייטק-ון ברייס'פעילות תחום אורקל בג

• Oracle 11g Database Administration:

– DBA Workshop 1 & 2

– Database Performance Tuning

– New Features for DBA’s

– RAC & Grid Infrastructure Administration

– Data Guard Administration

– Data Warehouse Administration

– Database Security

– Enterprise Manager Grid Control

– Managing Oracle on Linux for DBA’s

Page 9: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

מכללת הייטק-ון ברייס'פעילות תחום אורקל בג

• Oracle Business Intelligence

• Oracle Fusion Middleware

• Oracle Solaris

• Oracle MySQL

• Oracle Master DBA

Page 10: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

2012שבוע אורקל מלון דניאל הרצליה, בנובמבר 18-22

השנים האחרונות מניבה השותפות ארוכת השנים בין 19במהלך •הלימודי האירוע טק את -מכללת היי-ברייסון 'אורקל ישראל וג

בו משתתפים אלפי אנשי מקצוע , הגדול ביותר בישראלמקצועי שבוע אורקל–שנה מדי

המרצים , זוהי הזדמנות חד פעמית לשמוע מפי טובי המומחים•, ואנשי התוכן הבכירים בקהילת הטכנולוגיה והעסקים הישראלית

להתעדכן וללמוד על החידושים והנושאים המאתגרים את ובתחום העסקי IT -ההמנהלים ואנשי המקצוע בתחום

Page 11: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

2012במאי 2הכנס הטכנולוגי השנתי של אורקל ייערך ביום רביעי •

–Hardware & Software: במרכזו של הכנס עומד חזון אורקל•

Engineered to Work Together המדגיש את ההיצע הטכנולוגיהמלא של החברה מרמת היישום האסטרטגי ביותר לארגון ועד

, עם אחריות אחת, מבית אחד הכל–רמת הדיסק שבמחשב

אינטגרציה אחת וצוות פיתוח אחד

הכנס יתמקד בפתרונות החדשים שמציעה אורקל בתחומי מחשוב •, ניתוחים אנליטיים של מידע ארגוני, Big Data -טיפול וניהול ה, ענן

הרחבה והיצע פתרונות החומרה של החברה התווכהתשתית

Page 12: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

SQL Tuning

Tips, Tricks & Best Practices

Ami Aharonovich

Oracle ACE & OCP

[email protected]

Page 13: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

About Me

• Oracle ACE

• Oracle Certified Professional DBA (OCP)

• 11+ years of expertise as an Oracle DBA consultant and

instructor, specializing in Oracle database core technologies

• Founder and CEO of DBAces delivering expert consulting

and training services using Oracle database technologies

• Specializing in training Oracle University courses

• Oracle team leader – John Bryce Hi-Tech

• President of Israel Oracle User Group

Page 14: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Agenda

• Parsing time is important

• 11g adaptive cursor sharing

• Selectivity and cardinality

• Indexes and nulls and cardinality

• Integrity constraints are important

• Reasons for inefficient SQL performance

• Restructuring SQL statements and indexes

• General tips

Page 15: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

About My Presentation

• My slides and examples are based on:

– John Bryce Oracle University Course# 52163:

Oracle Database 11g SQL Tuning Workshop

– Tom Kyte ilOUG seminar: “Ask Tom Kyte Live in Israel 2010”

– Oracle Open World 2011

– Internet

– My knowledge and experience

Page 16: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Parsing Time is Important

BEGIN

FOR i IN 1..100000 LOOP

EXECUTE IMMEDIATE 'INSERT INTO t (x,y)

VALUES (' || i || ',''A'' )';

END LOOP;

END;

/

PL/SQL procedure successfully completed.

Elapsed: 00:00:42.91

Parsing_Time_is_Important.sql

Page 17: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Parsing Time is Important

BEGIN

FOR i IN 1..100000 LOOP

EXECUTE IMMEDIATE 'INSERT INTO t (x,y)

VALUES ( :i , ''A'' )' USING i;

END LOOP;

END;

/

PL/SQL procedure successfully completed.

Elapsed: 00:00:08.26

Page 18: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Parsing Time is Important

SELECT SUBSTR(sql_text,11,8) "Bind", COUNT(*),

ROUND(SUM(sharable_mem)/1024) "Memory KB"

FROM v$sqlarea

WHERE sql_text LIKE 'INSERT%INTO t (x,y)%'

GROUP BY SUBSTR(sql_text,11,8);

Bind COUNT(*) Memory KB

------------ ------------ ------------

NO_BIND 9,349 131,580

USE_BIND 1 14

Page 19: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

11g Adaptive Cursor Sharing

• One plan not always appropriate for all bind values

• Provides intelligent cursor sharing only for statements that

use bind variables and allows the optimizer to generate a

set of plans that are optimal for different sets of bind values

• Adaptive Cursor Sharing benefits:

– Automatically detects when different executions would

benefit from different execution plans

– Limits the number of generated child cursors to a minimum

– Automated mechanism that cannot be turned off

Adaptive_Cursor_Sharing.sql

Page 20: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

11g Adaptive Cursor Sharing Views

• The following views provide information about Adaptive

Cursor Sharing:

V$SQL Two new columns show whether a cursor is bind-sensitive

or bind-aware

V$SQL_CS_HISTOGRAMS Shows the distribution of the execution count across the

execution history histogram

V$SQL_CS_SELECTIVITY Shows the selectivity cubes stored for every predicate

containing a bind variable and whose selectivity is used in

the cursor sharing checks

V$SQL_CS_STATISTICS Shows execution statistics of a cursor using different bind

sets

Page 21: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Selectivity

• Selectivity is the estimated proportion of a row set retrieved

by a particular predicate or combination of predicates

• It is expressed as a value between 0.0 and 1:

– High selectivity: Small proportion of rows

– Low selectivity: Big proportion of rows

• Selectivity computation:

– If no statistics: Use dynamic sampling

– If no histograms: Assume even distribution of rows

Page 22: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Cardinality

• Expected number of rows retrieved by a particular

operation in the execution plan

• Vital figure to determine join, filters, and sort costs

Cardinality = Selectivity * Total number of rows

Selectivity_and_Cardinality.sql

Page 23: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

B*-tree Indexes and Nulls

Page 24: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

B*-tree Indexes and Nulls

CREATE INDEX HR.EMP_DEPTID_NULL_IDX ON HR.employees(department_id,0);

Page 25: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

NULLs and Cardinality and Indexes

• There is a pervasive myth that indexes and NULLs are like

matter and anti-matter

• There is the though that “WHERE COLUMN IS NULL” cannot

use an index

• There is a thought that NULLs cannot be indexed

• “Lets use invalid values instead of the NULLs”

Nulls_and_Cardinality.sql

Page 26: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Integrity Constraints are Important

� Constraint EMP_DEPT_FK is disabled

Page 27: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Integrity Constraints are Important

� Constraint EMP_DEPT_FK is enabled

Page 28: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

You Are Being Watched!

We watch what you ask for and change how statistics are

gathered based on that

SELECT histogram

FROM user_tab_cols

WHERE table_name = 'T'

AND column_name = 'STATUS';

HISTOGRAM

---------------

NONE

SELECT histogram

FROM user_tab_cols

WHERE table_name = 'T'

AND column_name = 'STATUS';

HISTOGRAM

---------------

FREQUENCY

You_Are_Being_Watched.sql

Page 29: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Reasons for Inefficient SQL Performance

• Stale or missing optimizer statistics

• Missing access structures, such as indexes, materialized

views, partitions

• Suboptimal execution plan selection: because of incorrect

estimates of some attributes of the SQL statements such as

its cost, cardinality or predicate selectivity

• Poorly constructed SQL, such as a missing join condition

(Cartesian product, “Merge Join Cartesian”) or use of

UNION instead of UNION ALL

Page 30: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Inefficient SQL: Examples

SELECT p.prod_id,p.prod_name,p.prod_list_priceFROM SH.products pWHERE p.prod_list_price > 5 * (SELECT AVG(unit_cost)FROM SH.costs c WHERE c.prod_id = p.prod_id);

SELECT * FROM job_history jh, employees e WHERE substr(to_char(e.employee_id),2) =

substr(to_char(jh.employee_id),2);

SELECT * FROM orders WHERE order_id_char = 1205;

SELECT * FROM employees WHERE to_char(salary) = :sal;

1

2

3

4

SELECT * FROM parts_old UNION SELECT * FROM parts_new;5

Page 31: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Which One is Better ?SELECT p.prod_id , p.prod_name , p.prod_list_priceFROM SH.products pWHERE p.prod_list_price > 5 * (SELECT AVG(unit_cost)FROM SH.costs c WHERE c.prod_id = p.prod_id);

SELECT p.prod_id , p.prod_name , p.prod_list_priceFROM SH.products p,

(SELECT prod_id , AVG(unit_cost) avg_costFROM SH.costs GROUP BY prod_id) c

WHERE p.prod_id = c.prod_idAND p.prod_list_price > 5 * c.avg_cost;

Cost = 991 / Elapsed = 00:00:00.26

Cost = 222K / Elapsed = 00:00:01.38

Which_One_is_Better.sql

Page 32: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Use a Join – Not Always…

• In general, you use a join when you need data from more

than one table in the ultimate SELECT list

• When you need data only from one table, it is unlikely that

you would consider a join. Instead consider using either

WHERE EXISTS or WHERE IN

SELECT DISTINCT d.dname,d.loc

FROM emp e,dept d

WHERE e.deptno=d.deptno;

SELECT d.dname,d.loc

FROM dept d

WHERE EXISTS (SELECT null FROM emp e

WHERE e.deptno=d.deptno);

Page 33: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Restructuring SQL Statements

• Compose predicates using AND and =

• Avoid transformed columns in the WHERE clause

• Beware of implicit type conversions

• Use EXISTS rather than IN for sub queries

• Try to avoid joins with numerous tables

• Break up “complicated” SQL statements – do not attempt to

solve all situations with a single statement

• Do not DELETE. Prefer using INSERT AS SELECT

Page 34: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Restructuring Indexes

• Remove non selective indexes to speed up DML performance

• Reorder columns in existing concatenated indexes

• Add columns to the index to improve selectivity

• Consider index organized tables

• Consider using compression

• Parallelize index creation

Page 35: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

General Tips

• Do not try to tune every SQL statement. Tune only the ones

that are heavy consumers of resources

• You can tune forever. Set your goals before starting and

know when to stop. Setting reasonable response time

• Keep tracing your running system and track degradation in

response time. System growth may require additional tuning

• When using AUTOTRACE, use bind variables if your original

statement uses them. Existence of bind variables may

change the execution plan

Page 36: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Conclusions

• Wrong cardinality = Wrong plan

• Constraints and datatypes are important

• Beware of “Merge Join Cartesian”

• Minimize parsing (parse once, execute many times)

• Use bind variables

• Avoid transformed columns in the WHERE clause

• Beware of implicit type conversions

• Use EXISTS rather than IN for sub queries

Page 37: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Conclusions

• Try to avoid joins with numerous tables

• Break up “complicated” SQL statements

• Don’t DELETE. Just INSERT…

• Remove non selective indexes

• Reorder columns in existing concatenated indexes

• Add columns to the index to improve selectivity

• Consider using index compression

• Consider parallelizing index creation

Page 38: Oracle Open Day - marketing.johnbryce.co.ilmarketing.johnbryce.co.il/ad/2012/April/Oracle Open Day - Ami... · – DBA Workshop 1 & 2 – Database Performance Tuning – New Features

Thank You !Ami Aharonovich

Oracle ACE & OCP

[email protected]