DB2 for z/os: Utilities and Application Development



Similar documents
Session: Archiving DB2 comes to the rescue (twice) Steve Thomas CA Technologies. Tuesday Nov 18th 10:00 Platform: z/os

David Dye. Extract, Transform, Load

IBM DB2 for z/os. DB2 Version 9 - Zusammenfassung. (DB2_V9_SUMMARYnews.ppt) Dez, 09 1 (*)

Migrate Topaz databases from One Server to Another

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

A basic create statement for a simple student table would look like the following.

Top 25+ DB2 SQL Tuning Tips for Developers. Presented by Tony Andrews, Themis Inc.

System Copy GT Manual 1.8 Last update: 2015/07/13 Basis Technologies

Performance rule violations usually result in increased CPU or I/O, time to fix the mistake, and ultimately, a cost to the business unit.

Using SQL Server Management Studio

Data Masking Secure Sensitive Data Improve Application Quality. Becky Albin Chief IT Architect

Best Practices for DB2 on z/os Performance

Revolutionized DB2 Test Data Management

IBM DB2 Data Archive Expert for z/os:

CA Log Analyzer for DB2 for z/os

ETL Overview. Extract, Transform, Load (ETL) Refreshment Workflow. The ETL Process. General ETL issues. MS Integration Services

MS SQL Performance (Tuning) Best Practices:

Physical DB design and tuning: outline

Oracle Database: SQL and PL/SQL Fundamentals NEW

SQL Server Database Coding Standards and Guidelines

Version 5.0. MIMIX ha1 and MIMIX ha Lite for IBM i5/os. Using MIMIX. Published: May 2008 level Copyrights, Trademarks, and Notices

SQL Server. 1. What is RDBMS?

Database Replication with MySQL and PostgreSQL

5.1 Database Schema Schema Generation in SQL

Data Compression in Blackbaud CRM Databases

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Using AS/400 Database Monitor To Identify and Tune SQL Queries

IBM TRIRIGA Application Platform Version 3 Release 4.0. Application Building for the IBM TRIRIGA Application Platform 3: Data Management

Comparing Microsoft SQL Server 2005 Replication and DataXtend Remote Edition for Mobile and Distributed Applications

Data security best practices

Integrating VoltDB with Hadoop

SQL Server Replication Guide

SQL NULL s, Constraints, Triggers

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Oracle Database 10g: Introduction to SQL

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

Basics Of Replication: SQL Server 2000

High Speed Transaction Recovery By Craig S. Mullins

DBAs having to manage DB2 on multiple platforms will find this information essential.

Microsoft SQL Server Scheduling

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Oracle 10g PL/SQL Training

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

New Security Options in DB2 for z/os Release 9 and 10

OLTP Meets Bigdata, Challenges, Options, and Future Saibabu Devabhaktuni

Release Notes LS Retail Data Director August 2011

How to Implement Multi-way Active/Active Replication SIMPLY

File Manager base component

Instant SQL Programming

Optimizing Your Database Performance the Easy Way

In this session, we use the table ZZTELE with approx. 115,000 records for the examples. The primary key is defined on the columns NAME,VORNAME,STR

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

Controlling Dynamic SQL with DSCC By: Susan Lawson and Dan Luksetich

Database Administration with MySQL

Database Replication with Oracle 11g and MS SQL Server 2008

Restoring Microsoft SQL Server 7 Master Databases

Hyperoo 2 User Guide. Hyperoo 2 User Guide

Oracle Database: SQL and PL/SQL Fundamentals

Performance Tuning for the Teradata Database

How To Use The Correlog With The Cpl Powerpoint Powerpoint Cpl.Org Powerpoint.Org (Powerpoint) Powerpoint (Powerplst) And Powerpoint 2 (Powerstation) (Powerpoints) (Operations

Connectivity. Alliance Access 7.0. Database Recovery. Information Paper

Chancery SMS Database Split

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

SQL Performance for a Big Data 22 Billion row data warehouse

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

CA IDMS SQL. Programming Guide. Release

Guide to Upsizing from Access to SQL Server

How To Improve Your Database Performance

SQL Server An Overview

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC

Best Practices for DB2 on z/os Backup and Recovery

This Tech Note provides detailed guidelines and options for defragmenting and maintaining your production databases.

Getting to Know the SQL Server Management Studio

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts

Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

FHE DEFINITIVE GUIDE. ^phihri^^lv JEFFREY GARBUS. Joe Celko. Alvin Chang. PLAMEN ratchev JONES & BARTLETT LEARN IN G. y ti rvrrtuttnrr i t i r

Database Programming with PL/SQL: Learning Objectives

Data Warehouse Center Administration Guide

Extraction Transformation Loading ETL Get data out of sources and load into the DW

Data Access Guide. BusinessObjects 11. Windows and UNIX

Top Ten SQL Performance Tips

StreamServe Persuasion SP5 Oracle Database

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Move Data from Oracle to Hadoop and Gain New Business Insights

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Access Database Design

Lecture 7: Concurrency control. Rasmus Pagh

Architecture and Mode of Operation

SQL Query Evaluation. Winter Lecture 23

Handling Exceptions. Schedule: Timing Topic. 45 minutes Lecture 20 minutes Practice 65 minutes Total

Maintaining Stored Procedures in Database Application

1. INTRODUCTION TO RDBMS

Transcription:

TRAINING & CONSULTING DB2 for z/os: Utilities and Application ABIS Training & Consulting www.abis.be training@abis.be 2005, 2006 Document number: 0092_03b.fm 11 January 2006 Address comments concerning the contents of this publication to: ABIS Training & Consulting, P.O. Box 220, B-3000 Leuven, Belgium Tel.: (+32)-16-245610, Fax: (+32)-16-245691 Copyright ABIS N.V.

TABLE OF CONTENTS UTILITIES & APPLICATION DEVELOPMENT 5 1 Introduction 6 1.1 Utilities and application-related functionality 6 1.2 Utility processing versus SQL processing 7 1.3 Usability 8 1.4 Alternative: dropping indexes 9 2 Supported functionality 10 2.1 UNLOAD utility for READ activities 10 2.2 LOAD utility for WRITE activities 13 2.3 REORG utility for REMOVE activities 15 2.4 REORG utility for REWRITE activities 16 3 Examples of simple scenarios 17 3.1 Adding many rows 17 3.2 Copying many rows 19 3.3 Deleting many rows 22 4 Examples of mixed scenarios 24 4.1 Deleting many parent rows 24 4.2 Use of INCURSOR 26 4.3 INSERT after complex control 29 4.4 Utilities and remote access 33 DB2 for z/os: Utilities and Application iii

DB2 for z/os: Utilities and Application iv

Objectives : to introduce the main difference between SQL processing and the execution of utilities to give an overview of utility functions that can replace SQL processing to show with simple and more complex examples how and when you can take advantage from this functionality ABIS Training & Consulting 5

Introduction 1 Utilities and application-related functionality 1.1 UNLOAD: for READ actions LOAD: for WRITE actions REORG: for REMOVE actions REORG PAUSE or UNLOAD - (RE)LOAD: for REWRITE or COMPLEX actions DB2 for z/os: Utilities and Application ABIS 6

Utility processing versus SQL processing 1.2 SQL modifications: a lot of overhead: - logging - locking - on the fly: index maintenance referential integrity control (and/or actions: cascade/nullifies) In addition, if large amount of modifications: ---> often, a REORGANISATION needed For simple actions on 1 table: ---> UTILITIES are much cheaper most actions directly on VSAM files DB2 for z/os: Utilities and Application ABIS 7

Usability 1.3 In general: - for simple actions on high volumes stand-alone tables and activities - if application activity is always (or often) combined with utility processing e.g. batch job followed by a REORG - if asynchronous execution is allowed e.g action is not a part of a larger transaction DB2 for z/os: Utilities and Application ABIS 8

Alternative: dropping indexes 1.4 If SQL is needed for the modifications more tables involved in the process SQL functions needed... using utilities is no option any more Alternative: - DROP the INDEXES that cause overhead, before processing indexes that are maintained in flight and not needed for the process itself - CREATE them again after processing BE prepared for INVALID application plans and packages - Ask a REBIND for these plans/packages: check the related access paths (EXPLAIN) DB2 for z/os: Utilities and Application ABIS 9

Supported functionality 2 UNLOAD utility for READ activities 2.1 Example of a Select of many rows UNLOAD TABLESPACE TBD7971.TBSSTMOD FROM TABLE STOCKMODIFICATIONS (SMID, SM_PRNO, SMTIMESTAMP, SMQUANTITY) WHEN (SMTIMESTAMP BETWEEN 01.01.2004 AND 31.12.2004 ) SHRLEVEL CHANGE ISOLATION UR - one scan of the input data set (no indexes are used) - selected rows are written as records in an output file - base table stays intact and available (see SHRLEVEL) Remark: UNLOAD utility = COPY of a formatted SUBSET COPY utility = exact replication (backup) DB2 for z/os: Utilities and Application ABIS 10

UNLOAD utility for READ activities (I) Additional possibilities: UNLOAD TABLESPACE TBD7971.TBSSTMOD FROMCOPYDDN DB2COPY1 FROM TABLE STOCKMODIFICATIONS SAMPLE 5 LIMIT 2500 (SMID, SMTIMESTAMP TIMESTAMP EXTERNAL, SMCOMMENT VARCHAR STRIP TRAILING) WHEN (SMTIMESTAMP BETWEEN 01.01.2004 AND 31.12.2004 ) PUNCHDDN DB2PUNCH DELIMITED COLDEL, SHRLEVEL CHANGE ISOLATION UR DB2 for z/os: Utilities and Application ABIS 11

UNLOAD utility for READ activities (II) - FROMCOPYDDN to use an IMAGE COPY as input - PUNCHDDN to create corresponding LOAD utility statements - SAMPLE - LIMIT to limit the number of output records - TIMESTAMP EXTERNAL - VARCHAR STRIP TRAILING to format output fields - DELIMITED COLDEL, to format output records DB2 for z/os: Utilities and Application ABIS 12

LOAD utility for WRITE activities 2.2 Example of an Insert of many rows LOAD DATA RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS FORMAT UNLOAD or <FIELD-specifications> - input records are added as rows to the table(space) - new index entries are sorted - they are merged with the existing entries - corrections are done for: duplicate keys R.I. violations DB2 for z/os: Utilities and Application ABIS 13

LOAD utility for WRITE activities (II) Additional possibilities: LOAD DATA LOG NO NOCOPYPEND ENFORCE NO RESUME YES SHRLEVEL CHANGE INTO TABLE STOCKMODIFICATIONS FORMAT UNLOAD or <FIELD-specifications> - LOG NO NOCOPYPEND - ENFORCE NO less overhead - faster processing only for controlled data - SHRLEVEL CHANGE: no solution for performance (= mass insert with in flight maintenance of indexes) DB2 for z/os: Utilities and Application ABIS 14

REORG utility for REMOVE activities 2.3 Example of a Delete of many rows REORG TABLESPACE TBD7971.TBSSTMOD LOG NO SORTKEYS COPYDDN(SYSCOPY) STATISTICS TABLE ALL INDEX ALL SHRLEVEL REFERENCE DISCARD FROM TABLE STOCKMODIFICATIONS WHEN (SMTIMESTAMP < CURRENT DATE - 3 YEAR) - one scan of the input data set (tablespace) (clustering index may be used) - non-discarded rows are written as records in an output file - they are rewritten in clustering sequence into the table(space) - remaining index entries are sorted and used to rebuild indexes DB2 for z/os: Utilities and Application ABIS 15

REORG utility for REWRITE activities 2.4 Example of an Update of many rows REORG TABLESPACE TBD7971.TBSSTMOD UNLOAD PAUSE Do while READ from <unload-file> modify record WRITE to <reload-file> End RESTART REORG TABLESPACE... - unload-file has no indexes - indexes are REBUILT after restart - remarks: constraints (check and R.I.) are not checked there will be no CHKP-status DB2 for z/os: Utilities and Application ABIS 16

Examples of simple scenarios 3 Adding many rows 3.1 Do while READ input-record... INSERT INTO StockModifications VALUES(:WS-StockModifications:WS-SMInd) End Problem: - large input-files and 4 indexes --> long execution time - locking: from exclusive table lock and low commit frequency to page locks and high commit frequency: --> more concurrency --> +/- doubled elapsed time DB2 for z/os: Utilities and Application ABIS 17

Adding many rows (II) Alternative LOAD DATA RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS <FIELD-specifications> - Plus: less execution time (between 25 and 50%) no programming effort - Minus: FIELD-specifications SHRLEVEL NONE (SHRLEVEL CHANGE = INSERT) only KEY and R.I. control no TRIGGER support DB2 for z/os: Utilities and Application ABIS 18

Copying many rows 3.2 DECLARE CopyStM CURSOR FOR SELECT * FROM StockModifications WHERE SMTimestamp = CURRENT DATE - 1 DAY LOCK TABLE StockModifications IN SHARE MODE OPEN CopyStM Do while FETCH CopyStM INTO :WS-StockModifications:WS-SMInd... WRITE uotput-record end Problem: - time that the table is unavailable (exclusively locked) is too long - lock is needed: concurrent updates can give a wrong result DB2 for z/os: Utilities and Application ABIS 19

Copying many rows (II) Alternative 1: UNLOAD DATA FROM TABLE STOCKMODIFICATIONS WHEN (SMTIMESTAMP = CURRENT DATE - 1 DAY) SHRLEVEL REFERENCE - Plus: faster than SQL (typical value: 3 times faster) no programming effort format of output records is controllable - Minus: no complex conditions DB2 for z/os: Utilities and Application ABIS 20

Copying many rows (III) Alternative 2: COPY TABLESPACE TBD7971.TBSSTMOD SHRLEVEL REFERENCE UNLOAD TABLESPACE TBD7971.TBSSTMOD FROMCOPYDDN... FROM TABLE STOCKMODIFICATIONS WHEN (SMTIMESTAMP = CURRENT DATE - 1 DAY) - Plus: COPY +/- 2 times faster than UNLOAD (of alternative 1) - Minus: second job (UNLOAD) (but without impact on the base table) DB2 for z/os: Utilities and Application ABIS 21

Deleting many rows 3.3 DELETE FROM StockModifications WHERE SMTimestamp < CURRENT DATE - 2 DAYS AND SMStatus = 7 Problem: - +/- 50% of the rows are deleted - table has 4 indexes --> very long execution time (60 minutes) - space management --> REORG needed after execution - remarks: locking: exclusive table lock --> low CPU-usage, many time-outs R.I. is no problem (dependent table) DB2 for z/os: Utilities and Application ABIS 22

Deleting many rows (II) Alternative REORG TABLESPACE TBD7971.TBSSTMOD LOG NO SORTKEYS COPYDDN(SYSCOPY) STATISTICS TABLE ALL INDEX ALL SHRLEVEL REFERENCE DISCARD FROM TABLE STOCKMODIFICATIONS WHEN (SMTIMESTAMP = CURRENT DATE - 2 DAYS AND SMSTATUS = 7 ) - Plus: much faster than SQL (few minutes) no programming effort REORG and DISCARD: one job - Minus: no complex conditions if parent table: CHKP for dependent tables DB2 for z/os: Utilities and Application ABIS 23

Examples of mixed scenarios 4 Deleting many parent rows 4.1 Process: - parent rows with a given status must be deleted (+/- 75%) - delete rule is cascade - on average 500 dependents for a parent row SQL solution DELETE FROM LastOrders WHERE LOStatus = OK - Problem: index maintenance on LastStockModifications (dependent table) (index maintenance on LastOrders) DB2 for z/os: Utilities and Application ABIS 24

Deleting many parent rows (II) Alternative UPDATE LastStockModifications SET LSMStatus = OK WHERE EXISTS (SELECT 1 FROM LastOrders WHERE LOStatus = OK AND LO_PrNo = LSM_PrNo) efficient UPDATE process if no indexes on LSMStatus REORG TABLESPACE TBD7971.TBSLSTSM DISCARD FROM TABLE LASTSTOCKMODIFICATIONS WHEN (LSMSTATUS = OK ) REORG TABLESPACE TBD7971.TBSLSTOR DISCARD FROM TABLE LASTORDERS WHEN (LOSTATUS = OK ) DISCARD of parent rows --> dependent table: CHKP DB2 for z/os: Utilities and Application ABIS 25

Use of INCURSOR 4.2 Process: - information must be copied from a source table to a target table - availability of the target table is critical - complex selection criteria for the source table SQL solution INSERT INTO StockModifications SELECT * FROM LastStockModifications T WHERE NOT EXISTS (SELECT 1 FROM Products WHERE PrNo = T.LSM_PrNo AND PrStatus = 7 ) - Problem: index maintenance on StockModifications DB2 for z/os: Utilities and Application ABIS 26

Use of INCURSOR (II) Alternative 1: EXEC SQL DECLARE GETSTMOD CURSOR FOR SELECT * FROM LASTSTOCKMODIFICATIONS T WHERE NOT EXISTS (SELECT 1 FROM PRODUCTS WHERE PRNO = T.LSM_PRNO AND PRSTATUS = 7 ) ORDER BY LSMTIMESTAMP ENDEXEC LOAD DATA INCURSOR GETSTMOD RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS DB2 for z/os: Utilities and Application ABIS 27

Use of INCURSOR (III) - Alternative 2: INSERT INTO TempStockModifications SELECT * FROM LastStockModifications T WHERE NOT EXISTS (SELECT 1 FROM Products WHERE PrNo = T.LSM_PrNo AND PRStatus = 7 ) efficient SQL if no indexes on TempStockModifications UNLOAD DATA SHRLEVEL NONE FROM TABLE TEMPSTOCKMODIFICATIONS LOAD DATA RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS DB2 for z/os: Utilities and Application ABIS 28

INSERT after complex control 4.3 Process: - uncontrolled information (but correct format) must be copied from an input-file into a target table - availability of the target table is critical - complex control criteria for the input information SQL solution Do while READ input-record <control activities> If OK INSERT INTO StockModifications VALUES(:WS-StockModifications:WS-SMInd) End - Problem: again index maintenance on StockModifications DB2 for z/os: Utilities and Application ABIS 29

INSERT after complex control (II) Alternative 1: LOAD DATA RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS <FIELD>-specifications by default: SMStatus = NULL (i.e. not yet available) --> additional VIEW (SMStatus IS NOT NULL)? DECLARE NewStMod CURSOR FOR SELECT * FROM StockModifications WHERE SMStatus IS NULL Do while FETCH NewStMod INTO :WS-StockModifications:WS-SMInd <control activities> If NOT-OK <correction> End DB2 for z/os: Utilities and Application ABIS 30

INSERT after complex control (III) Alternative 2: LOAD DATA RESUME YES SHRLEVEL NONE INTO TABLE NEWSTOCKMODIFICATIONS <FIELD>-specifications no impact on the base table DECLARE NewStMod CURSOR FOR SELECT * FROM NewStockModifications Do while FETCH NewStMod INTO :WS-StockModifications:WS-SMInd <control activities> If NOT-OK <correction> End no impact on the base table DB2 for z/os: Utilities and Application ABIS 31

INSERT after complex control (IV) - Alternative 2 (cont.): EXEC SQL DECLARE GETSTMOD CURSOR FOR SELECT * FROM NEWSTOCKMODIFICATIONS WHERE NSMSTATUS IS NOT NULL ORDER BY NSMTIMESTAMP ENDEXEC LOAD DATA INCURSOR GETSTMOD RESUME YES SHRLEVEL NONE INTO TABLE STOCKMODIFICATIONS efficient index manipulation of StockModifications DB2 for z/os: Utilities and Application ABIS 32

Utilities and remote access 4.4 Process: - refresh of a replicated table inside DB2 - at runtime initiated by a remote Java application Standard solution using SQL: DELETE FROM LastStockModifications Problem: INSERT INTO LastStockModifications SELECT * FROM STOCKMODIFICATIONS WHERE SMTIMESTAMP = CURRENT DATE - in flight index maintenance - how to use utilities as alternative? DB2 for z/os: Utilities and Application ABIS 33

Stored Procedure: DSNUTILS St Proc to execute utilities: - allocates dynamically data sets - creates the utility statements - invokes DB2 utilities using program DSNUTILB - inserts the result (SYSPRINT) into a temporary table (SYSIBM.SYSPRINT) - declares a cursor: DECLARE Sysprint CURSOR WITH RETURN FOR SELECT seqno, text FROM sysibm.sysprint ORDER BY seqno - OPENs the cursor and RETURNs DB2 for z/os: Utilities and Application ABIS 34

Stored Procedure: DSNUTILS (II) Calling DSNUTILS: CALL DSNUTILS (<utility-id>, <restart-indicator>, <utility-statements>, <return-code>, <ANY / <utility-name>, <dataset-name1>,...) Utility statements UNLOAD DATA FROM TABLE STOCKMODIFICATIONS WHEN (SMTIMESTAMP = CURRENT DATE) LOAD DATA REPLACE INTO TABLE LASTSTOCKMODIFICATIONS DB2 for z/os: Utilities and Application ABIS 35

Stored Procedure: DSNUTILS (III) Checking the execution - SQLCODE (in calling program): 466: PROCEDURE... RETURNED... QUERY RESULTS SETS - return-code (out parameter from St Proc) utility RETURN CODE (0, 4, 8...) - utility report: can be fetched from SYSIBM.SYSPRINT DB2 for z/os: Utilities and Application ABIS 36