Escolar Documentos
Profissional Documentos
Cultura Documentos
By:
Parag K Bhayani
Learning Objectives
Day# 1
Understanding physical architecture
Understanding logical architecture
DB2 and OS/390 environment
Start and Stop database
Estimating the storage space
Learning Obj contd…
Day# 2
Performance goals
Analyzing performance data
Tuning memory
Tuning application
EXPLAIN
Learning Obj contd…
Day# 3
DB2 Utilities
Overview to DBMS
Table,
User Views Logical
View
VSAM Physical
Data Sets Storage
Physical Structure
Storage Groups
Boot Strap Data Sets (BSDS)
Active and Archive Logs
Storage Groups Storage
Application Process
Unit of Recovery
SQL Transaction 1 SQL Transaction 2
Time Line
Database
Tablespace
Pages
Objects
Database
Tablespace
Table
View Index
Database
Collection of DB2 logical structures
Default database DSNDB04
Catalog resides in DSNDB06
DB2 Directory in DSNDB01
Work file in DSNDB07
Segment
Segment 5
Segment
Segment 4 Table B
Segment 3
2 Table A
1 Table C
Space Table B
Header Table A
Map
Page
Partitioned Tablespace
A table space that can contain only single table
The space is divided into partitions based on the key
ranges
Each partition can be processed concurrently
Where to use?
v
Storage Storage
Group# 2
Phy & Logical contd…
Storage Group “G1” Storage Group “G2”
Vol 1 Vol 2
Header
Design and
Performance Free Space
Implications
Used Space
Choosing page size
DB2 provides many options for data page size
The size of the data page is determined by the buffer
pool in which you define the tablespace
For example, Tablespace defined in 4 KB buffer pool
has 4K page size
Scenarios:
When the size of individual rows is greater than 4K
2100 byte record – what size of page?
Larger page size can reduce data sharing overhead –
reduces the no. of times coupling is accessed
DB2 Catalog
Data dictionary tables residing at DSNDB06 database
SYSIBM.SYSTABLES
SYSIBM.SYSCOLUMNS
Sample queries
SELECT NAME, TBNAME, COLTYPE, LENGTH, NULLS, DEFAULT
FROM SYSIBM.SYSCOLUMNS
WHERE TBNAME = ‘DEPT’
AND TBCREATOR = ‘DSN8610’
SELECT *
FROM SYSIBM.SYSINDEXES
WHERE NAME = ‘XEMPL2’
AND CREATOR = ‘DSN8610’
Sample queries
SELECT A.DBNAME, A.NAME, B.CREATOR, B.NAME
FROM SYSIBM.SYSTABLESPACE A, SYSIBM.SYSTABLES B
WHERE A.DBNAME = B.DBNAME
AND (A.STATUS = ‘P’ OR A.STATUS=‘S’)
ORDER BY 1,2,3,4;
DB2 Directory
Residing at DSNDB01
Stored in RDBMS form but not accessible through
SQL
Its consists of following tablespaces:
SCT01 (Skeleton Cursor Table)
• Internal Form of SQL Statements
SPT01 (Skeleton Package Table)
• Created when you bind a package
SYSLGRNX (Long Range Tablespace)
• Used to track opening / closing of tablespaces, indexes, or partitions
SYSUTILX (System Utility)
• Contains row for every utility job running
DBD01 (Database descriptor)
• Internal information about database
DB2 and OS/390
Address Spaces
Data Services (DSN1DBM1)
System Services (DSN1MSTR)
IRLM (IRLMPROC)
Stored Procedure (DSN1SPAS)
Distributed Data Facility (DSN1DIST)
Various components
Distributed
Database System
Data
Services Services
Facilities
Locking User
BSDS
Active
Data Logs
Services
Catalog Directory
Archive
Logs
Buffer Pools (BPnn)
Also known as “Virtual Buffer Pools”
Temporarily stores the pages of table spaces and
indexes
Application program requesting a row of a table, DB2
retrieves of page from DASDs and placing it into
buffer pool
Buffer pool can reside at any of the following:
Within DB2’s DBM1 primary address space – limit 1.6 GB
Partly within DBM1 address space and using ESO HiperSpace
– limit 1.6 GB in DBM1 and 8 GB of ESO
Solely with MVS Data Space – limit 8 million buffers and for
32K Buffer pool – 256 GB
Decisions related to BPs
Decisions are made during installation
How many virtual buffer pools of each size you need?
50 – 4 KB virtual buffer pool
10 each of 8 KB, 16KB, and 32 KB virtual buffer pools
Do you want buffer pools to use hiperspaces, data
spaces or neither?
Which buffer pool is to be the default for user data
and which is to be for indexes?
Buffer Pool Sizes
Start Database
Controls availability of objects residing in that
database.
ACCESS(RO)
ACCESS(RW)
ACCESS(UT)
Day# 2
Performance Goals
Acceptable response time
A duration within which some percentage of all applications
have completed
First response from system to the application
Average throughput
The total number of transactions or queries that complete
within a given time
System Availability
MTTR (Mean-Time-To-Recover)
MTBF (Mean-Time-Between-Failure)
Response Time
Application
Database Tuning
Tuning
Improving response time
General Tips:
Reduce I/O Operations
Use RUNSTATS to keep access paths statistics current
Reserve free space in table spaces and indexes
Make buffer pool large enough
Tuning Buffer Pools
90% 95% 97.5%
Normal Read
Queue
Being Sequential prefetech
Handled queue
Queued per
Data set
• Effects:
The suspended process resumes running when:
– All processes that hold the conflicting lock release it.
– The requesting process times out or deadlocks and the process
resumes to deal with an error condition.
Concurrency issues
Effects of Locks contd… …
Time out:
• Example:
An application process attempts to update a large table space that is
being reorganized by the utility REORG TABLESPACE with
SHRLEVEL NONE. It is likely that the utility job will not release control
of the table space before the application process times out.
• Effects:
DB2 terminates the process, issues two messages to the console, and
returns SQLCODE -911 or -913 to the process
Concurrency Issues
Effects of Locks:
Deadlock:
• Example:
• Effects:
After a preset time interval (the value of DEADLOCK TIME), DB2 can
roll back the current unit of work for one of the processes or request a
process to terminate. That frees the locks and allows the remaining
processes to continue.
Concurrency Issues
Concurrency Issues
Recommendations for design
Keep like things together
Plan for batch inserts
Use LOCKSIZE ANY until you have reason not to
Fewer rows of data per page, but not at the cost of I/O
Commit work as soon as is practical
Retry an application after deadlock or timeout
Close cursors
Bind plans with ACQUIRE(USE)
Bind with ISOLATION(CS)
EXPLAIN for tuning
EXPLAIN provides information on:
The order in which tables will be accessed
How the tables will be accessed
Whether the index will be used
The types of joins and the order
Internal Sorts
Table locks
Tool which helps understanding optimizer
EXPLAIN contd…
OPTIMIZER:
Checks the authority
Resolves names of tables, views and columns against the
catalog
Validates the semantics
Determines the best mechanism execute the SQL statement
Strategy decided based upon statistics stored in catalog
tables
EXPLAIN contd…
Step# 1: Create PLAN_TABLE
EXPLAIN contd…
Step# 2 Populate PLAN_TABLE table
EXPLAIN PLAN
SET QUERYNO=1
FOR “explainable statement”
DB2 Utilities
CHECK DATA
The CHECK DATA online utility checks table spaces
for violations of referential and table check
constraints,and reports information about violations
that are detected.
CHECK DATA also checks for consistency between a
base table space and a LOB table space.
CHECK DATA contd…
Output:
CHECK DATA optionally deletes rows that violate referential
or table check constraints.A row that violates one or more
constraints is copied to an exception table.
If any violation of constraints is found,CHECK DATA puts the
table space being checked in the CHECK pending status.
On successful execution,CHECK DATA resets the CHECK
pending status.
Authorization Required:
STATS privilege for the database
DBADM,DBCTRL,or DBMAINT authority for the database
SYSCTRL or SYSADM authority
CHECK DATA contd…
Phases:
UTILINIT Initialization
SCANTAB Extract foreign keys; use foreign key
index if it matches exactly, else scan
table
SORT Sort foreign keys if not extracted
from foreign key index
CHECKDAT Look in primary indexes for foreign
key parents,and issue messages to
report errors detected
REPORTCK Copy error rows into exception tables,
and delete them from source table if
DELETE YES is specified
UTILTERM Cleanup
CHECK DATA contd…
Sample JCL:
COPY
The COPY online utility creates up to four image
copies of any of the following objects:
Table space
Table space partition
Data set of a linear table space
Indexspace
Index space partition
There are two types of image copies:
A full image copy is a copy of all pages in a table space,
partition, data set, or index space.
An incremental image copy is a copy only of pages that have
been modified since the last use of the COPY utility.
COPY contd…
The copies are used by the RECOVER utility when
recovering a table space or index space to the most
recent time or to a previous time.
SHRLEVEL
REFERENCE
CHANGE
COPY contd…
Output:
Up to four sequential data sets containing the image copy.
Rows in the SYSIBM.SYSCOPY catalog table that describe
the image copy data sets available to the RECOVER utility.
Phases:
UTILINIT Initialization and setup
REPORT Reporting for CHANGELIMIT option
COPY Copying
UTILTERM Cleanup
COPY contd…
Sample JCL:
COPY contd…
More options:
COPY contd…
Incremental Copy:
LOAD
Use LOAD to load one or more tables of a table
space.
LOAD loads records into the tables and builds or
extends any indexes defined on them.
If the table space already contains data, you can
choose whether you want to add the new data to the
existing data or replace the existing data.
LOAD
Output:
A loaded table space or partition
A discard file of rejected records
A summary report of errors encountered during
processing,generated only if you specify ENFORCE
CONSTRAINTS or if the LOAD involves unique indexes
LOAD contd…
Sample Example:
MERGECOPY
The MERGECOPY online utility merges image copies
produced by the COPY utility or inline copies
produced by the LOAD or REORG utilities.
It can also merge incremental copies with a full
image copy to make a new full image copy.
MERGECOPY operates on the image copy data sets of
a table space,and not on the table space itself.
MERGECOPY contd…
Output:
A new single incremental image copy
A new full image copy
Authorization Required:
IMAGCOPY privilege for the database
DBADM, DBCTRL, or DBMAINT authority for the database
SYSCTRL or SYSADM authority
MERGECOPY
Sample JCL:
REORG
The REORG TABLESPACE utility reorganizes a table
space to improve access performance and reclaim
fragmented space.
Can reorganize a |single partition or range of
partitions of a partitioned table space.
REORG contd…
Output:
Reorganizes all data,entire partitioning index,and all non-
partitioning indexes.
Authorization Required:
REORG privilege for the database
DBADM or DBCTRL authority for the database
SYSCTRL authority
SYSADM authority
RUNSTATS
Online utility gathers summary information about the
characteristics of data in table spaces,indexes,and
partitions
DB2 records this information in the DB2 catalog and
uses it to select access paths to data during the bind
process.
RUNSTATS TABLESPACE gathers statistics on a table
space and optionally on indexes or columns
RUNSTATS INDEX gathers statistics only on indexes.
Use the STATISTICS keyword with LOAD,REBUILD
INDEX,and REORG jobs to eliminate the need to
execute RUNSTATS for updating catalog statistics.
RUNSTATS contd…
Sample JCL: