60
© 2013 IBM Corporation Information Management DB2 for z/OS: Programmer Essentials for Designing, Building and Tuning Brett Elam [email protected] - DB2 for z/OS: Programmer Essentials for Designing, Building and Tuning April 4, 2013

DB2 for z/OS: Programmer Essentials for Designing ... 2013-04-05...DB2 for z/OS: Programmer Essentials for Designing, ... Programmer Essentials for Designing, Building and Tuning

Embed Size (px)

Citation preview

© 2013 IBM Corporation

Information Management

DB2 for z/OS: Programmer Essentials for Designing, Building and Tuning

Brett Elam – [email protected] - DB2 for z/OS: Programmer Essentials for Designing, Building and Tuning

April 4, 2013

© 2013 IBM Corporation

Information Management

Disclaimer and Trademarks

Information contained in this material has not been submitted to any formal IBM review and is distributed on "as is" basis without any warranty either expressed or implied. Measurements data have been obtained in laboratory environment. Information in this presentation about IBM's future plans reflect current thinking and is subject to change at IBM's business discretion. You should not rely on such information to make business plans. The use of this information is a customer responsibility.

IBM MAY HAVE PATENTS OR PENDING PATENT APPLICATIONS COVERING SUBJECT MATTER IN THIS DOCUMENT. THE FURNISHING OF THIS DOCUMENT DOES NOT IMPLY GIVING LICENSE TO THESE PATENTS.

TRADEMARKS: THE FOLLOWING TERMS ARE TRADEMARKS OR ® REGISTERED TRADEMARKS OF THE IBM CORPORATION IN THE UNITED STATES AND/OR OTHER COUNTRIES: AIX, AS/400, DATABASE 2, DB2, e-business logo, Enterprise Storage Server, ESCON, FICON, OS/390, OS/400, ES/9000, MVS/ESA, Netfinity, RISC, RISC SYSTEM/6000, System i, System p, System x, System z, IBM, Lotus, NOTES, WebSphere, z/Architecture, z/OS, zSeries

The FOLLOWING TERMS ARE TRADEMARKS OR REGISTERED TRADEMARKS OF THE MICROSOFT CORPORATION IN THE UNITED STATES AND/OR OTHER COUNTRIES: MICROSOFT, WINDOWS, WINDOWS NT, ODBC, WINDOWS 95

For additional information see ibm.com/legal/copytrade.phtml

© 2013 IBM Corporation

Information Management

3

December 2012 Data Studio 3.2 Announcement…

New option possibilities:

• Query – focus on catalog navigation and query editor

• Admin – focus on object management and utilities

• Develop – Stored procedures/routine development and debugging

• Query Tuning

Available in 32 or 64 Bit support

Data Studio now a single package, no more “Full” versus “Administration” client. Eclipse base Installation Manager installation with more installation possibilities to tailor features and size of footprint, and is still available at no charge.

Data Studio Home Page: http://www.ibm.com/developerworks/downloads/im/data/

© 2013 IBM Corporation

Information Management

Data Studio V3.2

© 2013 IBM Corporation

Information Management

Data Studio – 32 or 64 Bit Deployment Option

© 2013 IBM Corporation

Information Management

Customized Installation and Footprint Size

http://pic.dhe.ibm.com/infocenter/dstudio/v3r2/topic/com.ibm.datatools.base.install.doc/topics/c_plan_install_feature_product.html

For Details See:

© 2013 IBM Corporation

Information Management

Installation FootprintFull install: 1.5GB and minimum install: 499MB

© 2013 IBM Corporation

Information Management

8

IBM Data Studio

IBM Data Studio provides extensible database development and administration support for the DB2 and Informix family of products

Eclipse-based tool set

No client or DB2 Connect software needed

– Restricted use type-4 Java driver included to connect to DB2 z/OS

Provides database management capabilities for DB2 LUW and z/OS, Oracle, MySQL, SQL

Server, Sybase, Informix, etc.

Query building and editing

– Automatic DDL Generation

Stored Procedures and UDF development wizards

– Create, Test, Debug, Deploy the routines

Web Service creation wizards

– In order to expose database operations to client applications (SQL SELECT and DML

statements, XQuery expressions, call SPs)

Replacement for DB2 Control Center

© 2013 IBM Corporation

Information Management

9

Fast Up and Running

Launch key tasks

Select lifecycle

Access tutorials and advice

© 2013 IBM Corporation

Information Management

10

Perspectives

DatabaseMetaDataView

Output View

Database ProjectsEditor

© 2013 IBM Corporation

Information Management

11

More Flexible Navigation

True hierarchy

Fast filtering

Show menu

Save customizations

Better context menus

Add columns to object list

(LUW)

Server -> Database

Name filteringMore filtering and

customization

© 2013 IBM Corporation

Information Management

12

Some of Data Studio Abilities – Create Table Space…

© 2013 IBM Corporation

Information Management

13

Create a Table…

© 2013 IBM Corporation

Information Management

14

Viewing Entity Relationships

InfoSphere Data Architect(Viewer)

© 2013 IBM Corporation

Information Management

15

Generate DDL

© 2013 IBM Corporation

Information Management

16

Add some data to a table…

© 2013 IBM Corporation

Information Management

17

Follow instructions to select table and column

© 2013 IBM Corporation

Information Management

18

Support for the XML data type

© 2013 IBM Corporation

Information Management

19

Data Studio Includes Optim Database Administrator for DB2 LUW

Automate and script structural database changes to help DBAs better manage

test databases and speed deployments and streamline overall administrative

tasks.

Compare and handle forward and reverse schema engineering between models,

the database, and DDL.

Perform extended alters that require dropping and re-creating tables and

managing data preservation.

Facilitate impact analysis and dependency analysis to mitigate change risk.

Migrate database objects, data, and privileges and generate maintenance utility

commands.

Document and report on proposed and completed changes for collaboration and

audit.

Manage large environments with large volumes of objects more efficiently by

taking advantage of the overall scalability and performance enhancements.

© 2013 IBM Corporation

Information Management

20

Database Administration Perspective and Administration Explorer is the workbench

© 2013 IBM Corporation

Information Management

21

Sample of Features – Database Management

© 2013 IBM Corporation

Information Management

22

Sample of Features – Table Management

© 2013 IBM Corporation

Information Management

23

Sample of Features – Data Movement

© 2013 IBM Corporation

Information Management

24

Data Studio Includes the Query Tuner Client for DB2 LUW and z/OS

Optim Query Workload Tuner is now activated by a key in the database now, no need to install

additional workstation software

Query tuning

You can tune single queries with several features that are incorporated from Optimization Service

Center for DB2 for z/OS, which is now deprecated. These new features are supported on either DB2 for

Linux, UNIX, and Windows or DB2 for z/OS:

Supported query tuning features for DB2 for z/OS and LUW:

Capture queries from all data sources that Optimization Service Center for DB2 for z/OS supports and

from XML files that are exported from DB2 Query Monitor for z/OS.

– View formatted queries.

– View access plan graphs.

– Capture information about the data server that queries run against, a feature which corresponds to

Service SQL in Optimization Service Center for DB2 for z/OS.

– Generate reports on the performance of queries.

– Run the Query Statistics Advisor to analyze the statistics that are available for the data that a query

accesses, check for inaccurate, outdated, or conflicting statistics, and look for additional statistics that

you might capture to improve how the data server processes the query.

– Query Sources:

• Text, Statement Cache, Plans/Packages, QMF, Files, Plan Table, Data Studio Objects

© 2013 IBM Corporation

Information Management

25

IBM Data Studio – Visual ExplainSeveral options to “Right” click on “Open Visual Explain”

© 2013 IBM Corporation

Information Management

26

Visual ExplainAccess Plan diagramand navigator

Tip: Red lines around boxes around tables and indexes indicate missing statistics

© 2013 IBM Corporation

Information Management

27

Query Costing is available

© 2013 IBM Corporation

Information Management

28

Data Studio - Query Tuning Interface

Many SQL sources

© 2013 IBM Corporation

Information Management

29

Data Studio – Provides a subset of Optim Query Workload Tuner’s features

© 2013 IBM Corporation

Information Management

30

Data Studio Additional ways to launch Query Tuner from the GUI

© 2013 IBM Corporation

Information Management

31

Data Studio filtering is available for the Dynamic Statement Cache

© 2013 IBM Corporation

Information Management

32

Data Studio Query Tuning:Statistics Advisor

© 2013 IBM Corporation

Information Management

33

Data Studio Query Tuning:Formatted query after Optimizer rewrite

© 2013 IBM Corporation

Information Management

34

Data Studio Query Tuning:Access Plan Graph

© 2013 IBM Corporation

Information Management

35

Data Studio Query Tuning:Summary Report

© 2013 IBM Corporation

Information Management

36

Data Studio Query Tuning:Access Plan Report

© 2013 IBM Corporation

Information Management

37

Optim Query Workload Tuner – for purchase

Optimize performance

Reduce costs– Increase overall system capacity

– Simplify analysis for DBAs, developers,

designers, and others

– Reduce time to respond

Development Environment– Tune SQL pre-production while costs and

impact are low

Production Environment– Optimize workload for peak performance

Identify query candidates from

numerous sources– DB2 catalog

– Dynamic statement cache

– Data Studio hot spots

– Query or performance monitors

Get expert tuning advice

– Improve query design

• Get recommendations regarding how to

rewrite the query for better efficiency

– Improve statistics quality

• Get recommendations on the best

statistics to capture to influence access

path selection

– Improve index design

• Get recommendations on additional

indexes that can reduce database scans

• View the effects of dropping indices

Analyse Access Plans

– Visualize access path

– Assess access path stability to reduce risk of

performance regression

Eclipse based

– Allows for shell sharing with other tools

© 2013 IBM Corporation

Information Management

IMS Enterprise Suite Explorer for DevelopmentA recent addition

http://www.ibm.com/software/data/ims/soa-integration-suite/enterprise-suite/

© 2013 IBM Corporation

Information Management

IMS Enterprise Suite Explorer for DevelopmentRequirements

Use with 32-Bit Data Studio Version 3.2 Only

© 2013 IBM Corporation

Information Management

IMS Enterprise Suite Explorer for DevelopmentShell Share with Data Studio

© 2013 IBM Corporation

Information Management

IMS Enterprise Suite Explorer – z/OS Editor and SDSF DisplayCool tool….

PDS

& Dataset

List

zOS

Editor

SDSF

Held

Output

© 2013 IBM Corporation

Information Management

DB2 9 for z/OS has two types of SQL Stored procedures

SQL Procedural Language or SQL PL

– External SQL procedures:

• This is what we know and love before DB2 9 for z/OS

• Generated C program which runs in a WLM environment

– Native SQL procedures:

• The SQL procedure logic runs in the DBM1 address space

• Extensive support for versioning:– VERSION keyword on CREATE PROCEDURE

– CURRENT ROUTINE VERSION special register

– ALTER ADD VERSION

– ALTER REPLACE VERSION

– ALTER ACTIVATE VERSION

– BIND PACKAGE with new DEPLOY keyword

• FOR Statement - Executes one or multiple statements for each row of a table. Statements within the FOR are executed for each row selected

• Compound SQL statements - A compound statement contains a block of SQL statements and declarations for SQL variables, cursors, and condition handlers.

• Native SQL procedures support zIIP Processors with DRDA SQL

– Unified Debugger support for Java and SQL-PL

• BIND PACKAGE with new DEPLOY keyword

42

© 2013 IBM Corporation

Information Management

Upward compatibility

External SQL procedures will continue to work in V9 either in CM or

NFM

External SQL procedures can continue to be created in V9 NFM

– CREATE PROCEDURE ... FENCED or EXTERNAL keyword

required

Native SQL procedures can be created starting in V9 NFM

– CREATE PROCEDURE ... (FENCED or EXTERNAL keyword not

used)

Both native and external SQL procedures can be called in V9 in NFM

43

© 2013 IBM Corporation

Information Management

SQL PL / Generated C Implementation in V8 or V9 External Stored Procedures

Appl pgm

CALL SP1

Appl pgm

CALL SP1

DB2

DBM1

WLM

WLM

//STEPLIB DD

SP1

logic

(load

module)

EDM

pool

SP1

pkg

DDF

or

SP1

Load

module

SP1 pkgDB2

directory

44

© 2013 IBM Corporation

Information Management

SQL PL Native Stored Procedure Execution in V9

Appl pgm

CALL SP1

Appl pgm

CALL SP1

DB2

DBM1

EDM pool

DDF

or

DB2

directory

SQL PL native logic

SQL

SQL

SP1

SQL PL native logic

SQL

SQL

SP1

45

© 2013 IBM Corporation

Information Management

Comparison of External and Native Stored Procedures

Redbook DB2 9 for z/OS Performance Topics SG24-7473

46

© 2013 IBM Corporation

Information Management

47

New Template-based Routine Creation

Faster

Easier

Compliant

Name procedure

Select Template

Preview template

© 2013 IBM Corporation

Information Management

48

Stored Procedure – Edit / Customize

© 2013 IBM Corporation

Information Management

49

Stored Procedure – Deployment

1. Select stored procedure for deployment

© 2013 IBM Corporation

Information Management

50

Stored Procedure – Deployment

2. Customize deployment options

Specify target database

Specify target schema

Specify default pathSpecify how to

handle duplicates

© 2013 IBM Corporation

Information Management

51

Stored Procedure – Deployment

3. Customize precompiled options

Options for z/OS

Options for LUW

© 2013 IBM Corporation

Information Management

52

Stored Procedure - Run

Run executes a call of the stored

procedure

Asks for input parameters values

View result set

Customize run settings

© 2013 IBM Corporation

Information Management

53

Preparing for Debugging

1. Deploy stored procedure with "Enable debugging"

2. Select stored procedure for Debug…

© 2013 IBM Corporation

Information Management

54

Debug Perspective

resume

terminate step intostep over

step return

variables

current value

right click to change value

break point

current location

© 2013 IBM Corporation

Information Management

55

Debug Perspective– Breakpoints

Clicking resume will stop at next

break point

Debugger stops at line 11

All breakpoints in this session

© 2013 IBM Corporation

Information Management

56

Useful information on Data Studio and Stored Procedures – Unified Debugger & Session Manger Setup on z/OS

Data Studio and DB2 for z/OS Stored Procedures

http://www.redbooks.ibm.com/abstracts/redp4717.html?Open

Redbook on Stored Procedures

http://www.redbooks.ibm.com/abstracts/sg247604.html?Open

Favorite!

© 2013 IBM Corporation

Information Management

57

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z1

0.doc/src/alltoc/db2z_10_prodhome.htm

The main place for all documentation is InfoCenter

© 2013 IBM Corporation

Information Management

58

DB2 LUW Information Centers

https://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp?topic=/com.i

bm.db2.luw.common.doc/doc/t0021844.html

© 2013 IBM Corporation

Information Management

59

Data Studio’s Information Center

http://publib.boulder.ibm.com/infocenter/dstudio/v3r1/index.jsp

© 2013 IBM Corporation

Information Management

60

The End!