Professional Documents
Culture Documents
Db2 App DBA - Module I
Db2 App DBA - Module I
1. LOGICAL ARCHITECTURE..........................................................................7
1.1 UNIT OBJECTIVES....................................................................................7
1.2 INTRODUCTION.......................................................................................7
1.3 DATABASE.............................................................................................7
1.3.1 Storage Group...............................................................................10
1.3.2 Address Space...............................................................................10
1.3.3 Exercise........................................................................................11
1.4 TABLE SPACE.......................................................................................11
1.4.1 Simple Table Space........................................................................12
1.4.2 Partitioned Table Space..................................................................12
1.4.3 Segmented Table Space.................................................................12
1.4.4 Large Object (LOB) Table Spaces.....................................................12
1.4.5 Exercise........................................................................................12
1.5 TABLE................................................................................................13
1.6 VIEW.................................................................................................13
1.7 INDEX................................................................................................13
1.7.1 Partitioning Index..........................................................................14
1.7.2 Non-partitioning Index...................................................................14
1.7.3 Exercise........................................................................................14
1.8 DB2 PACKAGES AND PLANS......................................................................14
1.8.1 Package Versioning........................................................................16
1.8.2 Exercise........................................................................................17
1.9 ALIASES AND SYNONYMS..........................................................................18
1.10 SCHEMA...........................................................................................19
1.10.1 Exercise.....................................................................................19
1.11 LOB...............................................................................................20
1.12 SYSTEM CATALOG TABLES......................................................................20
1.13 CATALOG CONTENTION.........................................................................21
1.13.1 Contention within table space SYSDBASE.......................................21
1.13.2 Contention independent of databases:...........................................21
1.14 DATABASE DIRECTORIES.......................................................................22
1.14.1 Exercise.....................................................................................23
1.15 REVIEW QUESTIONS.............................................................................23
1.16 REFERENCE.......................................................................................23
2. TRIGGERS.............................................................................................24
2.1 UNIT OBJECTIVES..................................................................................24
2.2 INTRODUCTION.....................................................................................24
2.3 DEFINITIONS........................................................................................24
2.3.1 Creating and Adding Triggers..........................................................25
2.3.2 Description....................................................................................25
2.4 TRIGGERS V/S TABLE CHECK CONSTRAINTS...................................................27
2.5 TRIGGERS AND DECLARATIVE RI.................................................................28
2.6 PERFORMANCE ISSUES.............................................................................28
2.7 MONITORING AND CONTROLLING TRIGGERS....................................................28
2.7.1 Catalog Information.......................................................................29
2.7.2 Exercise........................................................................................29
2.8 USER DEFINED FUNCTIONS (UDF)..............................................................30
2.8.1 Sourced Scalar Functions................................................................30
2.8.2 External Functions.........................................................................31
2.8.3 UDF Restrictions............................................................................33
2.8.4 UDF Performance Considerations.....................................................33
2.8.5 Monitoring and Controlling UDFs......................................................33
2.8.6 Stopping UDFS..............................................................................34
2.8.7 Exercise........................................................................................34
2.9 REVIEW QUESTIONS...............................................................................34
2.10 REFERENCE.......................................................................................34
3. PHYSICAL ARCHITECTURE.......................................................................35
3.1 UNIT OBJECTIVES..................................................................................35
3.2 INTRODUCTION.....................................................................................35
3.3 BOOT STRAP DATASET.............................................................................35
3.3.1 Introduction..................................................................................35
3.3.2 Recovery of BSDS..........................................................................35
3.3.3 Naming Convention........................................................................36
3.3.4 Exercise........................................................................................36
3.4 ACTIVE AND ARCHIVE LOGS.......................................................................36
3.4.1 Introduction..................................................................................36
3.4.2 Unit of Recovery............................................................................37
3.4.3 Rolling back Work..........................................................................37
3.4.4 Creation of log records...................................................................38
3.4.5 Retrieval of Log records..................................................................39
3.4.6 Writing the Active log.....................................................................39
3.4.7 Writing the archive log...................................................................39
3.4.8 Triggering log offload.....................................................................40
3.4.9 The offloading process....................................................................40
3.4.10 Archive log datasets....................................................................41
3.4.11 Archiving the log.........................................................................42
3.4.12 Naming convention.....................................................................45
3.4.13 Performance considerations..........................................................45
3.4.14 Exercise.....................................................................................53
3.5 DSNZPARMS......................................................................................54
3.5.1 IRLMRWT......................................................................................54
3.5.2 RECURHL......................................................................................54
3.5.3 XLKUPDLT.....................................................................................54
3.5.4 NUMLKTS......................................................................................54
3.5.5 NUMLKUS.....................................................................................55
3.5.6 LOGLOAD......................................................................................55
3.5.7 Other Zparms................................................................................55
3.5.8 Exercise........................................................................................55
3.6 STORAGE GROUPS.................................................................................55
3.6.1 Retrieving Catalog Info about DB2 Storage Groups............................55
3.6.2 Designing Storage Groups and Managing DB2 Data............................56
3.6.3 Managing Your Own DB2 Data Sets..................................................56
3.6.4 Requirements for Your Own Data Sets..............................................57
3.6.5 Implementing Your Storage Groups..................................................58
3.6.6 Exercise........................................................................................59
3.7 REVIEW QUESTIONS...............................................................................59
3.8 REFERENCE..........................................................................................59
4. DATA SERVICES.....................................................................................60
4.1 UNIT OBJECTIVES..................................................................................60
4.2 INTRODUCTION.....................................................................................60
4.3 BUFFER POOLS......................................................................................60
4.3.1 Introduction..................................................................................60
4.3.2 Tuning Buffer Pools........................................................................60
4.3.3 Write operations............................................................................63
4.3.4 Exercise........................................................................................72
4.4 EDM POOLS.........................................................................................72
4.4.1 Introduction..................................................................................72
4.4.2 Tuning the EDM Pool......................................................................73
4.4.3 Exercise........................................................................................75
4.5 RID POOLS..........................................................................................75
4.5.1 Introduction..................................................................................75
4.5.2 Increasing RID Pool Size.................................................................75
4.5.3 Exercise........................................................................................76
4.6 SORT POOLS........................................................................................76
4.6.1 Introduction..................................................................................76
4.6.2 Controlling Sort Pool Size and Sort Processing...................................76
4.6.3 Understanding How Sort Work Files Are Allocated..............................77
4.6.4 Factors That Influence Sort Processing.............................................78
4.6.5 Exercise........................................................................................79
4.7 DB2 DIRECTORY...................................................................................79
4.7.1 Introduction..................................................................................79
4.7.2 Contents for this directory...............................................................79
4.7.3 Exercise........................................................................................80
4.8 DB2 CATALOG TABLES............................................................................80
4.8.1 Introduction..................................................................................80
4.8.2 Examples......................................................................................81
4.8.3 Exercise........................................................................................81
4.9 REVIEW QUESTIONS...............................................................................81
4.10 REFERENCE.......................................................................................81
5. LOCKING, IRLM AND CONCURRENCY........................................................82
5.1 UNIT OBJECTIVES..................................................................................82
5.2 INTRODUCTION.....................................................................................82
5.3 IRLM – CONTROLLING THE IRLM...............................................................82
5.3.1 Starting the IRLM...........................................................................84
5.3.2 Monitoring the IRLM Connection......................................................84
5.3.3 Stopping the IRLM.........................................................................84
5.4 LOCK COMPATIBILITY...............................................................................85
5.4.1 Modes of Page and Row Locks.........................................................85
5.4.2 Modes of table, partition, and table space locks.................................86
5.4.3 Exercise........................................................................................87
5.5 LOCK CONVERSION / LOCK PROMOTION........................................................87
5.6 SUSPENSION........................................................................................88
5.7 LOCK DURATION....................................................................................88
5.7.1 ACQUIRE (ALLOCATE) Vs ACQUIRE (USE).........................................88
5.7.2 RELEASE (COMMIT) Vs RELEASE (DEALLOCATE)................................88
5.7.3 ISOLATION...................................................................................89
5.7.4 CURRENTDATA..............................................................................90
5.7.5 Exercise........................................................................................93
5.8 LOCKSIZE............................................................................................93
5.8.1 Tablespace Lock............................................................................93
5.8.2 Table Lock....................................................................................93
5.8.3 Page Lock.....................................................................................93
5.8.4 Row Lock......................................................................................94
5.8.5 Page Lock Vs Row Lock...................................................................94
5.8.6 Row Level Locking V/S Maxrows = 1................................................94
5.8.7 Lockmax.......................................................................................95
5.8.8 Lock Escalation..............................................................................95
5.8.9 Exercise........................................................................................97
5.9 CLAIMS AND DRAINS..............................................................................97
5.9.1 Claims..........................................................................................98
5.9.2 Drains..........................................................................................98
5.9.3 Compatibility Rules for Claims and Drains.......................................100
5.10 LOCK TUNING..................................................................................100
5.10.1 Deadlock..................................................................................100
5.10.2 Resource Timeout......................................................................104
5.10.3 Idle Thread Timeout..................................................................105
5.10.4 Utility Timeout..........................................................................106
5.10.5 Lock Wait Time.........................................................................106
5.10.6 Monitoring Locking....................................................................106
5.10.7 Exercise...................................................................................111
5.11 CONCURRENCY.................................................................................111
5.11.1 Introduction to Concurrency.......................................................111
5.11.2 ISOLATION Level.......................................................................112
5.11.3 Concurrency vs Lock Size...........................................................117
5.11.4 Deadlock..................................................................................118
5.11.5 Lock Compatibility.....................................................................118
5.11.6 Lock Conversion........................................................................118
5.11.7 Lock Escalation.........................................................................119
5.11.8 Basic recommendations to promote concurrency...........................119
5.11.9 Exercise...................................................................................123
5.12 DB2 SUBSYSTEM OBJECT LOCKING.........................................................123
5.12.1 Locks on the DB2 Catalog and Directory.......................................123
5.12.2 Locks on Skeleton Cursor Tables (SKCT)......................................124
5.12.3 Locks on Database Descriptors....................................................125
5.13 REVIEW QUESTIONS...........................................................................126
5.14 REFERENCE.....................................................................................126
6. DYNAMIC SQL......................................................................................127
6.1 UNIT OBJECTIVES................................................................................127
6.2 INTRODUCTION....................................................................................127
6.3 CODING DYNAMIC SQL IN APPLICATION PROGRAM.........................................127
6.3.1 Choosing between static and dynamic SQL......................................128
6.3.2 Performance of static and Dynamic SQL..........................................128
6.3.3 Caching Dynamic SQL statements and KEEPDYNAMICS.....................128
6.3.4 Dynamic SQL with resource limit facility..........................................131
6.3.5 Dynamic SQL for non-SELECT statements.......................................131
6.3.6 Dynamic SQL for fixed-list SELECT statements.................................133
6.3.7 Dynamic SQL for varying-list SELECT statements.............................134
6.3.8 Exercise......................................................................................136
6.4 REVIEW QUESTIONS..............................................................................136
6.5 REFERENCE........................................................................................136
7. STORED PROCEDURES..........................................................................137
7.1 UNIT OBJECTIVES................................................................................137
7.2 INTRODUCTION....................................................................................137
7.2.1 What are Stored Procedures?........................................................137
7.2.2 When do we use them?.................................................................138
7.2.3 Advantage...................................................................................139
7.2.4 Disadvantages.............................................................................139
7.2.5 Types of Stored Procedures...........................................................139
7.2.6 Exercise......................................................................................140
7.3 SP RELATED TERMINOLOGY.....................................................................140
7.4 EXAMPLE OF STORED PROCEDURE..............................................................141
7.4.1 A few salient points about the Stored Procedure:.............................141
7.5 RUNNING YOUR SP (THE CALLING PROGRAM)................................................142
7.5.1 When the Result Set concept is used..............................................142
7.5.2 When the Result Set concept is not used.........................................142
7.5.3 Exercise......................................................................................143
7.6 SP ADDRESS SPACE.............................................................................143
7.6.1 Changing the RACF Started Procedures Table..................................144
7.6.2 Guidelines for effective use of address space...................................144
7.6.3 Dynamically Extending Load Libraries.............................................145
7.6.4 Exercise......................................................................................148
7.7 SP RUNTIME ENVIRONMENTS...................................................................148
7.8 SP BUILDER.......................................................................................148
7.8.1 Overview of DB2 Stored Procedure Builder......................................148
7.8.2 How has DB2 SP Builder changed the process of creating SPs?..........149
7.8.3 Exercise......................................................................................151
7.9 PERFORMANCE CONSIDERATIONS...............................................................152
7.9.1 Reentrant Code............................................................................152
7.9.2 Fenced and Non-fenced Procedures................................................152
7.9.3 Limiting Resources Used...............................................................152
7.9.4 Workload Manager.......................................................................152
7.9.5 CICS EXCI...................................................................................153
7.9.6 Exercise......................................................................................153
7.10 DB2-DELIVERED SPS.........................................................................153
7.10.1 DSNWZP..................................................................................153
7.10.2 DSNWSPM................................................................................153
7.10.3 DSNACCMG..............................................................................153
7.10.4 DSNACCAV...............................................................................154
7.10.5 DSNUTILS................................................................................154
7.11 DOS AND DONTS.............................................................................154
7.11.1 Do’s.........................................................................................154
7.11.2 DON’T’s....................................................................................154
7.12 REVIEW QUESTIONS...........................................................................155
7.13 REFERENCE.....................................................................................155
GLOSSARY...................................................................................................156
APPENDIX A - LIST OF DSNZPARMS................................................................160
APPENDIX B - PACKAGE BIND PARAMETERS....................................................167
APPENDIX C - LOCK COMPATIBILITY MATRIX...................................................168
APPENDIX D - CLAIMS AND DRAINS COMPATIBILITY MATRICES.........................169
APPENDIX E - DB2 ADDRESS SPACE IDS AND ASSOCIATED RACF USER IDS AND
GROUP NAMES.............................................................................................170
APPENDIX F - SAMPLE JOB TO REASSEMBLE THE RACF STARTED PROCEDURES...171
APPENDIX G - COMPARING WLM-ESTABLISHED AND DB2-ESTABLISHED STORED
PROCEDURES...............................................................................................173
Appendix H - Sample Stored Procedure...........................................................175
Infosys Technologies Ltd. Logical Architecture
___________________________________________________________________
UNIT - I
1. Logical Architecture
1.1 Unit Objectives
This section provides the overview of some of the key database objects.
1.2 Introduction
A DB2 database involves more than just a collection of tables. It also includes table
spaces, storage groups, views, indexes, and other items. These are all collectively
referred to as DB2 structures.
STORAGEGROUP
DATABASE
TABLE SPACE
TABLE
INDEX
VIEW
COLUMN
ALIAS
SYNONYM
1.3 Database
In DB2, a database is a set of DB2 structures. When you define a DB2 database, you
give a name to an eventual collection of tables and associated indexes, as well as to
the table spaces in which they reside. A single database, for example, can contain all
the data associated with one application or with a group of related applications.
Collecting that data into one database allows you to start or stop access to all the
data in one operation and grant authorization for access to all the data as a single
unit.
If you create a table space or a table and do not specify a database, the table or
table space is created in the default database, DSNDB04, which is defined for you at
installation time. All users have the authority to create tables in database DSNDB04.
However, the system administrator can revoke those privileges and grant them only
to particular users as necessary. The default database is predefined in the
installation process; its default DB2 storage group is SYSDEFLT, and you can specify
its default buffer pool at installation time.
After that, all users have the authority to create table spaces or tables in database
DSNDB04. The system administrator can revoke those privileges and grant them
only to particular users as necessary.
DB2 requires several different address spaces for the following purposes:
One for distributed data facility, DSN1DIST, which provides support for
remote requests.
One for the internal resource lock manager (IRLM), IRLMPROC, which controls
DB2 locking.
1.3.3 Exercise
Questions:
1. When the user creates a table space or table in which database it is
created by default?
2. What is the default storage Group for a DB2 installation?
Answers:
1. DSNDB04
2. SYSDEFLT
A table space is one or more data sets in which one or more tables are stored. A
table space can consist of a number of VSAM data sets. Data sets are VSAM linear
data sets (LDSs). Table spaces are divided into equal-sized units, called pages, which
are written to or read from DASD in one operation. You can specify page sizes for the
data; the default page size is 4 KB.
Tables containing user data exist in regular table spaces. The default user table
space is called USERSPACE1. Indexes are also stored in regular table spaces. The
system catalog tables exist in a regular table space. The default system catalog table
space is called SYSCATSPACE.
When you create a table space, you can specify the database to which the table
space belongs and the storage group it uses. If you do not specify the database and
storage group, DB2 assigns the table space to the default database and the default
storage group. You also determine what kind of table spaces is created: simple,
segmented, partitioned, or a table space for LOBs.
1.4.5 Exercise
Questions:
1. What is the default system catalog table space?
Answers:
1. The default system catalog table space is SYSCATSPACE.
2. USERSPACE1
1.5 Table
1.6 View
A view can include all or some of the columns or rows contained in the tables on
which it is based. For example, you can join a department table and an employee
table in a view, so that you can list all employees in a particular department.
1.7 Index
An index is an ordered set of pointers to the data in a DB2 table. The index is stored
separately from the table. Each index is based on the values of data in one or more
columns of a table. After you create an index, DB2 maintains the index, but you can
perform necessary maintenance such as reorganizing it or recovering it, as
necessary. The main purposes of indexes are:
Except for changes in performance, users of the table are unaware that an index is
being used. DB2 decides whether or not to use the index to access the table.
Indexes take up physical storage in what are called index spaces. Each index
occupies its own index space. The maximum size of an index space depends on the
type of index (partitioning or non-partitioning) and the type of table on which the
index is created. When you create an index, an index space is automatically defined
in the same database as the table.
1.7.3 Exercise
Questions:
1. What is the difference between table and view?
2. List the two main reason for having index in a table?
Answers:
1. A view is an efficient way of representing data without needing to maintain it. A
view is not an actual table and requires no permanent storage.
2. To improve performance, To ensure that the row is unique.
The first step in DB2 program preparation is writing a program that contains
embedded SQL statements. You could write the program to run on the system on
which the DB2 for OS/390 subsystem resides, or to access the DB2 database from a
remote client via distributed relational database architecture (DRDA).
Once you've written the program, the DB2 precompiler processes it and generates
two outputs:
The pre-compiler places a unique identifier, called a consistency token, into each of
these outputs.
Following the precompile process, you compile and link-edit the modified source
program into an executable load module and bind the associated DBRM. In the DB2
for OS/390 bind process, such tasks as access path selection (optimization), access
authorization, and database object validation are performed. The output of the bind
process is a control structure that DB2 will use to execute the SQL statements when
the application program is run. The control structure will either be part of a plan (if
the DBRM is bound directly into a plan) or contained within a package that will be
executed via a plan.
If you use the package bind process, you have to bind the package into what is
called a collection. You can create a collection by binding a package into it.
Of course, even if you're using packages, you still need to bind one or more plans if
the program in question will run on the local or a remote DB2 for OS/390 subsystem.
Programs that run on other remote clients and access DB2 via DRDA use a default
plan called DISTSERV. You can execute a particular package using a plan if the
collection into which you've bound the package appears in what is called the plan's
package list (a list of one or more collections specified via the PKLIST option of the
BIND PLAN command). The program, in turn, invokes the plan through a
specification in the resource control table (or a DB2ENTRY if you're using resource
definition online) for a CICS transaction, via the application program load module
name for an IMS transaction, or with a control statement in the job control language
(JCL) for a batch job.
When you execute the application program, each call to DB2 directs the database
manager to execute the corresponding prebound SQL statement in the package
associated with the program. (Recall that the precompiler comments out SQL
statements in the source program and adds calls to DB2.) DB2 searches for the
package in one or more collections using as search criteria the package name (same
as the program name) and the consistency token accompanying the call. (Recall that
the consistency token, generated at precompile time, is carried in both the
application program and the related package.) When a match is found, the statement
is executed and control passes back to the application program until the next DB2
call is issued.
Given this database and application architecture, accessing the right data means
executing the right package; in other words, the package bound into the collection
associated with the database segment of interest. Given a plan with a multi collection
package list, how does DB2 know where to look for the package when executing an
SQL statement? The search process is as follows (assuming that programs are not
bound directly into the plan):
Given a situation in which multiple collections appear in a plan's package list and all
packages are bound into each collection, some people assume that the first collection
listed will serve, in effect, as the default collection. In other words, if the REGION1
collection is listed first, the package from that collection will be selected if the value
of CURRENT PACKAGESET is blank when an application program issues a call to DB2.
The problem with this assumption is that it does not take into account the possibility
that the package might already be allocated to the thread, as I mentioned earlier. If,
for example, DB2 needs to find package PROGABC, and if the version of that
package bound into the REGION3 collection is already allocated to the program's
DB2 thread, that version of the PROGABC package - and not the version in the
REGION1 collection - will be used for SQL statement execution if CURRENT
PACKAGESET is blank, even though the REGION1 collection is listed first in the plan's
package list. If, for performance reasons, you drive thread reuse and bind your most
frequently executed programs with RELEASE (DEALLOCATE), you'd better not think
of any collection in a multi collection package list as the default. Instead, explicitly
direct DB2 to the desired collection by way of SET CURRENT PACKAGESET. Even if all
of your packages are bound with RELEASE (COMMIT), you should probably use SET
CURRENT PACKAGESET to get where you want to go, in terms of collections.
Allowing more than one version of a package (say, the newest and the next-most-
recent versions) to exist within the package list of a plan can help in providing a
quick backout capability in the event that a new version of a package causes
problems. If such a situation occurs, you simply free the just-added version of the
package (the one associated with a new and problematic version of the application
program). When the previous (and well-behaved) version of the program is
executed, the right package will be found because the previous version of the
package is already in the collection list. If the previous version of the package had
been removed from the collection list upon the bind of the new version, falling back
to the old version would have required a rebind - an additional step that could delay
the backout process and perhaps make the process more error-prone.
If you want to use package versioning in this way, you have at least two choices:
1. You could keep the two versions of the package in two separate
collections, with the newer version going in the collection listed first in the
package list of the plan. (I will refer to the two collections as CURRENT and
FALLBACK.) Before a new version of a package is bound, the version of the
package in the FALLBACK collection is freed. Then, you move the version
of the package in the CURRENT collection from that collection to the
FALLBACK collection. Then you bind the new version of the package into
the CURRENT collection. If a problem necessitating a fallback occurs, the
version of the package in the CURRENT collection is freed. When you
execute the previous version of the program, DB2 will search for the
package in the CURRENT collection, since it is listed first in the plan's
package list. On not finding the package in the collection (because it was
freed), DB2 will search for the package in the FALLBACK collection,
resulting in the previous version of the package being found and utilized
for SQL statement execution.
2. Alternatively, you could keep multiple versions of the package in the same
collection, with the version ID (specified at precompile time) serving to
distinguish one version of the package from another. (Version ID is intended
primarily for user management of package versions; DB2 for OS/390 uses the
consistency token to find the correct version of a package at program
execution time, as I mentioned previously.) In this case, you'd want to ensure
that you periodically remove old and unneeded package versions (those older
than the current and next-most-recent versions) from the collection. You
could accomplish this goal with a user-written program, in which case you
could opt for a DB2-supplied version ID. (Specifying VERSION AUTO at
precompile time causes DB2 to use a timestamp value as the package version
ID.) The program would use the version ID to identify and free packages
older than the current and next-most-recent versions. If you want to remove
old package versions manually, you might want to go for a version ID that is
shorter and easier to specify than the timestamp value generated by DB2
with VERSION AUTO. (You can specify your own version ID when a program is
precompiled.)
1.8.2 Exercise
Questions:
1. What are the outputs from the DB2 pre-compiler?
2. What are consistency tokens?
3. What is the advantage of multiple package versioning?
Answers:
1. Modified Program source module and Database request Module.
2. The precompiler places a unique identifier, called a consistency token, into each
of these outputs.
3. Allowing more than one version of a package to exist within the package list of a
plan can help in providing a quick backout capability in the event that a new
version of a package causes problems.
A table or view can be referred to in an SQL statement by its name, by an alias that
has been defined for its name, or by a synonym that has been defined for its name.
Thus, aliases and synonyms can be thought of as alternate names for tables and
views.
1.10 Schema
A schema is a collection of named objects. The objects that a schema can contain
include distinct types, functions, stored procedures, and triggers. An object is
assigned to a schema when it is created.
Schemas extend the concept of qualifiers for tables, views, indexes, and aliases to
enable the qualifiers for distinct types, functions, stored procedures, and triggers to
be called schema names.
You can create a schema with the schema processor by using the CREATE SCHEMA
statement. CREATE SCHEMA cannot be embedded in a host program or executed
interactively. The ability to process schema definitions is provided for conformance to
ISO/ANSI standards. The result of processing a schema definition is identical to the
result of executing the SQL statements without a schema definition.
Outside of the schema processor, the order of statements is important. They must be
arranged so that all referenced objects have been previously created. This restriction
is relaxed when the schema processor processes the statements if the object table is
created within the same CREATE SCHEMA. The requirement that all referenced
objects have been previously created is not checked until all of the statements have
been processed. For example, within the context of the schema processor, you can
define a constraint that references a table that does not exist yet or GRANT an
authorization on a table that does not exist yet.
1.10.1Exercise
Questions:
Answers:
1. Tables and views
2. None
3. TRUE
4. A schema can be created with the schema processor by using the CREATE
SCHEMA statement.
1.11 LOB
A LOB table space is required to hold large object data such as graphics, video, or
very large text strings. A LOB table space is always associated with the table space
that contains the logical LOB column values. The table space that contains the table
with the LOB columns is called, in this context, the base table space.
The LOB data is logically associated with the base table, but it is physically stored in
an auxiliary table that resides in a LOB table space. There can only be one auxiliary
table in a large object table space. A LOB value can span several pages, however
only one LOB value is stored per page.
You must have a LOB table space for each LOB column that exists in the table. For
example, if your table has LOB columns for both resumes and photographs, you
must have one LOB table space (and one auxiliary table) for each of those columns.
If the base table space is partitioned, you must have one LOB table space for each
partition.
Each DB2 maintains a set of tables that contain information about the data under its
control. These tables are collectively known as the catalog. The catalog tables
contain information about DB2 objects such as tables, views, and indexes. In this
book, "catalog" refers to a DB2 catalog unless otherwise indicated. In contrast, the
catalogs maintained by access method services are known as "integrated catalog
facility catalogs."
Each database includes a set of system catalog tables, which describe the Logical
and physical structure of the data. DB2 creates and maintains an extensive set of
system catalog tables for each database. These tables contain information about the
definitions of database objects such as user tables, views, and indexes, as well as
security information about the authority that users have on these objects. They are
created when the database is created, and are updated during the course of normal
operation. You cannot explicitly create or drop them, but you can query and view
their contents using the catalog views.
Tables in the catalog are like any other database tables with respect to retrieval. If
you have authorization, you can use SQL statements to look at data in the catalog
tables in the same way that you retrieve data from any other table in the system.
Each DB2 ensures that the catalog contains accurate descriptions of the objects that
the DB2 controls. DB2 for OS/390 maintains a set of tables (in database DSNDB06)
called the DB2 catalog.
The DB2 catalog consists of tables of data about everything defined to the DB2
system, including table spaces, indexes, tables, copies of table spaces and indexes,
storage groups, and so forth. The DB2 catalog is contained in system database
DSNDB06. When you create, alter, or drop any structure, DB2 inserts, updates, or
deletes rows of the catalog that describe the structure and tell how the structure
relates to other structures.
To illustrate the use of the catalog, here is a brief description of some of what
happens when the employee table is created:
To record the name of the structure, its owner, its creator, its type (alias,
table, or view), the name of its table space, and the name of its database,
DB2 inserts a row into the catalog table SYSIBM.SYSTABLES.
To record the name of the table to which the column belongs, its length, its
data type, and its sequence number in the table, DB2 inserts rows into
SYSIBM.SYSCOLUMNS for each column of the table.
To increase by one the number of tables in the sample table space
DSN8S61E, DB2 updates the row in the catalog table
SYSIBM.SYSTABLESPACE.
To record that the owner (DSN8610) of the table has all privileges on the
table, DB2 inserts a row into table SYSIBM.SYSTABAUTH.
SQL data definition statements, GRANT statements, and REVOKE statements require
locks on the DB2 catalog. If different application processes are issuing these types of
statements, catalog contention can occur.
SQL statements that update the catalog table space SYSDBASE contend with each
other when those statements are on the same table space. Those statements are:
CREATE, ALTER, and DROP TABLESPACE, TABLE, and INDEX
CREATE and DROP VIEW, SYNONYM, and ALIAS
COMMENT ON and LABEL ON
GRANT and REVOKE of table privileges
Reduce the concurrent use of statements that update SYSDBASE for the same table
space.
CREATE, ALTER, and DROP DATABASE, and GRANT and REVOKE database
privileges all contend with each other and with any other function that
requires a database privilege.
CREATE, ALTER, and DROP STOGROUP contend with any SQL statements that
refer to a storage group, and with extensions to table spaces and indexes that
use a storage group.
GRANT and REVOKE for plan, package, system, or use privileges contend with
other GRANT and REVOKE statements for the same type of privilege, and with
data definition statements that require the same type of privilege.
The DB2 directory contains information used by DB2 during normal operation. You
cannot access the directory using SQL, although much of the same information is
contained in the DB2 catalog, for which you can submit queries. The structures in the
directory are not described in the DB2 catalog.
The directory consists of a set of DB2 tables stored in five table spaces in system
database DSNDB01. Each of the following table spaces is contained in a VSAM linear
data set:
SCT02 is the skeleton cursor table space (SKCT), which contains the internal
form of SQL statements contained in an application. When you bind a plan,
DB2 creates a skeleton cursor table in SCT02.
SPT01 is the skeleton package table space, which is similar to SCT02 except
that the skeleton package table is created when you bind a package.
SYSLGRNX is the log range table space, used to track the opening and closing
of table spaces, indexes, or partitions. By tracking this information and
associating it with relative byte addressees (RBAs) as contained in the DB2
log, DB2 can reduce recovery time by reducing the amount of log that must
be scanned for a particular table space, index, or partition.
SYSUTILX is the system utilities table space, which contains a row for every
utility job that is running. The row stays until the utility is finished. If the
utility terminates without completing, DB2 uses the information in the row
when you restart the utility.
DBD01 is the database descriptor (DBD) table space, which contains internal
information, called database descriptors (DBDs), about the databases existing
within DB2.
Each database has exactly one corresponding DBD that describes the database,
table spaces, tables, table check constraints, indexes, and referential
relationships. A DBD also contains other information about accessing tables in
the database. DB2 creates
1.14.1Exercise
Questions:
1. The table space that contains the table with the LOB columns is called, in
this context, the ________.
2. The DB2 catalog tables are contained in which database?
3. You can access the DB2 directory using SQL. True/False
4. The DB2 directory consists of _______ in system database _______.
Answers:
1. Base table space
2. DSNDB06
3. False
4. Five table spaces, DSNDB01
1.16 Reference
www.ibm.com
www.db2azine.com
www.db2mag.com
www.idug.org
IBM DB2 V6 Administration Guide
UNIT - II
2. Triggers
2.1 Unit Objectives
2.2 Introduction
DB2’s support for triggers and user-defined functions (UDFs) brings users a vast
capacity to invent many new ways of enhancing applications limited only by their
imagination. But with any extension of user code into a database, many
considerations for achieving good performance are required. User code embedded
using these facilities can completely obliterate any service-level agreement. This
chapter covers the performance and implementation issues surrounding these
features.
2.3 Definitions
A trigger defines a set of actions that are executed when a delete, insert, or update
operation occurs on a specified table. When such an SQL operation is executed, the
trigger is activated. Triggers can be used along with referential constraints and check
constraints to enforce data integrity rules. Triggers are more powerful than
constraints because they can also be used to cause updates to other tables,
automatically generate or transform values for inserted or updated rows, or invoke
functions that perform operations both inside and outside of DB2. For example,
instead of preventing an update to a column if the new value exceeds a certain
amount, a trigger can substitute a valid value and send a notice to an administrator
about the invalid update.
Triggers are useful for defining and enforcing business rules that involve different
states of the data, for example, limiting a salary increase to 10%. Such a limit
requires comparing the value of a salary before and after an increase. For rules that
do not involve more than one state of the data, consider using referential and check
constraints.
Triggers also move the application logic that is required to enforce business rules
into the database, which can result in faster application development and easier
maintenance. With the logic in the database, for example, the previously mentioned
limit on increases to the salary column of a table, DB2 checks the validity of the
changes that any application makes to the salary column. In addition, the application
programs do not need to be changed when the logic changes.
Triggers are optional and are defined using the CREATE TRIGGER statement.
Syntax:
Notes:
1. The same clause must not be specified more than once. OLD TABLE and NEW
TABLE must be specified only for AFTER triggers.
2. OLD_TABLE is a synonym for OLD TABLE.
3. NEW_TABLE is a synonym for NEW TABLE.
4. FOR EACH STATEMENT must not be specified for BEFORE triggers.
2.3.2 Description
trigger-name
Names the trigger. A schema implicitly or explicitly qualifies the name. The name,
including the implicit or explicit schema name, must not identify a trigger that exists
at the current server. The name is also used to create the trigger package;
therefore, the name must also not identify a package that is already described in the
catalog. The schema name becomes the collection-id of the trigger package. The
unqualified form of trigger-name is a short SQL identifier. The unqualified name is
implicitly qualified with a schema name according to the following rules:
If the statement is embedded in a program, the schema name of the trigger is the
AUTHORIZATION ID in the QUALIFIER bind-option when the plan or package was
created or last rebound. If QUALIFIER was not used, the schema name of the trigger
is the owner of the package or plan.
If the statement is dynamically prepared, the schema name of the trigger is the SQL
authorization ID of the process.
The qualified form of trigger-name is a short SQL identifier (the schema name)
followed by a period and a short SQL identifier. The schema name must not begin
with 'SYS unless the name is ‘SYSADM. The schema name that qualifies the trigger
name is the trigger's owner.
The owner of the trigger is determined by how the CREATE TRIGGER statement is
invoked:
If the statement is embedded in a program, the owner is the authorization ID
of the owner of the plan or package.
NO CASCADE BEFORE
Specifies that the trigger is a before trigger. DB2 executes the triggered action
before it applies any changes caused by an insert, delete, or update operation on the
triggering table. It also specifies that the triggered action does not activate other
triggers because the triggered action of a before trigger cannot contain any updates.
AFTER
Specifies that the trigger is an after trigger. DB2 executes the triggered action after
it applies any changes caused by an insert, delete, or update operation on the
triggering table.
INSERT
Specifies that the trigger is an insert trigger. DB2 executes the triggered action
whenever there is an insert operation on the triggering table. However, if the insert
trigger is defined on PLAN_TABLE, DSN_STATEMNT_TABLE, or
DSN_FUNCTION_TABLE, and the insert operation was caused by DB2 adding a row
to the table, the triggered action is not be executed.
DELETE
Specifies that the trigger is a delete trigger. DB2 executes the triggered action
whenever there is a delete operation on the triggering table.
UPDATE
Specifies that the trigger is an update trigger. DB2 executes the triggered action
whenever there is an update operation on the triggering table. If you do not specify
a list of column names, an update operation on any column of the triggering table,
including columns that are subsequently added with the ALTER TABLE statement,
activates the triggered action.
OF column-name,...
Each column-name that you specify must be a column of the subject table and must
appear in the list only once. An update operation on any of the listed columns
activates the triggered action.
ON table-name
Identifies the subject table with which the trigger is associated. The name must
identify a base table at the current server. It must not identify a temporary table, an
auxiliary table, an alias, a synonym, or a catalog table.
REFERENCING
Specifies the correlation names for the transition variables and the table names for
the transition tables. For the rows in the subject table that are modified by the
triggering SQL operation (insert, delete, or update), a correlation name identifies the
columns of a specific row. A table name identifies the complete set of modified rows.
Each row that is modified by the triggering operation is available to the triggered
action by using column names that are qualified with correlation names that are
specified as follows:
OLD AS correlation-name
Specifies the correlation name that identifies the state of the row prior to the
triggering SQL operation.
NEW AS correlation-name
Specifies the correlation name that identifies the state of the row as modified by the
triggering SQL operation and by any SET statement in a before trigger that has
already been executed.
The complete set of rows that is modified by the triggering operation is available to
the triggered action by using a temporary table name that is specified as follows:
At most, the trigger definition can include two correlation names (OLD and NEW) and
two table names (OLD TABLE and NEW TABLE). All the names must be unique from
one another.
OLD and OLD TABLE are valid only if the triggering SQL operation is a delete or an
update. For a delete operation, OLD captures the values of the columns in the
deleted row, and OLD TABLE captures the values in the set of deleted rows. For an
update operation, OLD captures the values of the columns of a row before the
update, and OLD TABLE captures the values in the set of updated rows.
NEW and NEW TABLE are valid only if the triggering SQL operation is an insert or an
update. For both operations, NEW captures the values of the columns in the inserted
or updated row. For before triggers, the values of the updated rows include the
changes from any SET statement in the triggered action if the trigger is a before
trigger.
OLD and NEW are valid only if you also specify FOR EACH ROW, and OLD TABLE and
NEW TABLE are valid only if you specify AFTER.
Generally, use constraints rather than triggers to enforce database rules. Use
triggers when a constraint cannot be used to enforce the rule. Check constraints and
referential integrity constraints are usually better suited for rules that only involve
only one state. Constraints offer these advantages over triggers:
Constraints are written in a less procedural way than triggers and give the
system more opportunities for optimization.
Constraints are enforced when they are created for existing data in the
database.
Constraints protect data against being placed into an invalid state by any kind
of statement, but each trigger applies only to a specific kind of statement
such as an update or delete.
Triggers are more powerful because they can enforce many rules that constraints
cannot. Use triggers to capture rules that involve different states of data. For
example, a rule that salaries cannot increase more than ten percent requires
knowledge of the before and after state of the data. Constraints cannot enforce such
a rule.
Recursive triggers are updates applied by trigger that cause the same trigger to fire
off. These can easily lead to loops and can be very complex statements. However,
they may be required by some applications for related rows. You need code to stop
the trigger.
Ordering multiple triggers can be an issue because triggers on the same table are
activated in the order they were created (identified in the creation time stamp). The
interaction among triggers and referential constraints can also be an issue because
the order of processing can significantly affect the results produced.
Invoking stored procedures and UDFs from triggers present some performance and
manageability concerns. Triggers can include only SQL but can call stored procedures
and UDFs that are user written and therefore have many implications for integrity
and performance. Transaction tables can be passed to stored procedures and UDFs
also.
Trigger cascading is when a trigger modifies the triggering table or another table.
Triggers can be activated at the same level or different levels, and when AFTER
triggers are activated at different levels, cascading occurs. Cascading can occur for
UDFs, stored procedures, and triggers.
There are various ways to monitor the various actions of triggers. The DB2PM
statistics and accounting reports include these statistics:
Other details can be found in the traces. For example, in IFCID 16 you can find
information about the materialization of a work file in support of a transaction table,
where TR indicates transaction table for triggers. Other information in IFCID 16
includes the depth of the trigger (0-16), where 0 indicates that there are no triggers.
You can also find the type of SQL that invoked the trigger: I = INSERT, U =
INSERT into a transaction table because of update, D = INSERT into a transaction
table because of a delete. The type of referential integrity that caused an insert into
a transaction table for a trigger is also indicated with an S for SET NULL (which can
occur when the SQL type is U) or C for CASCADE DELETE (which can occur when the
SQL type is D).
You can get the actual text of the trigger with the following statement:
2.7.2 Exercise
1. It is possible to activate a trigger without executing a SQL. True/False?
2. For rules that involve multiple states, it is better to use constraints rather
than Triggers. True/False?
3. Triggers on the same table are executed in the _____ of their definition.
4. Is it possible to invoke SPs from triggers?
5. What SYSIBM table gives you information about triggers?
Answers:
1. False
2. False
3. ORDER
4. Yes
5. SYSIBM.SYSTRIGGERS
User-defined functions (UDFs) allow users and developers to extend the function of
the DBMS by applying function definitions provided by users to the database engine
itself. This provides more synergy between application and database and helps with
the development cycle because it is more object-oriented and can be used for
application improvements in many areas. This ability leads to a new breed of
developers: the database procedural programmers.
UDFs are functions that are created by the user through DDL using the CREATE
FUNCTION statement. This statement can be issued in an interactive query interface
or in an application program. UDFs can be simple or complex, inside data or outside
data. They can provide application-specific functions or business-specific functions
that cross application. They provide a performance advantage because they execute
on the server, not client. Also, they are stored in one location, so change control
issues need to be revisited but are less problematic.
Use UDFs with LOBs (large objects) for both searching and analysis and with UDTs
(user-defined data types) for object processing unique to your business and
application complex needs. These functions can provide simple data transformations,
financial calculations, imagination and good performance guidelines (discussed later
in the chapter).
UDFs are created with CREATE FUNCTION statement and are used in SQL just like
built-in functions. They define the behavior of a user-defined data type as a method
and encapsulation.
There are three types of UDFs: sourced functions, external scalar functions, and
external table functions. Basically, sourced functions are based on existing built-in
functions, while external functions are written in a host language.
Sourced functions mimic other functions. They can be column functions that
work on a collection of values and return a single value (e.g., MAX, SUM,
AVG), or scalar functions that work on individual values and return a single
value (CHAR, CONCAT), or operator functions such as >, <, or =.
External scalar functions are written in a programming language, such as C,
C++, or Java, and return a scalar value. External scalar functions cannot
contain SQL, cannot be column functions, cannot access or modify the
database, and can perform calculations only on parameters.
External table functions can return a table and can be written in C or Java.
These functions work on scalar values that may be of different data types
with different meanings and return a table. For example:
o CREATE FUNCTION EXM ()
o RETUTNS TABLE (COL1 DATE . . ..))
Just like user-defined data types, UDFs, which are user-created SQL functions; play a
role in both normal data types and object types.
of the extenders, but large libraries of scalar functions are included. Extenders
include user-defined functions required for each of the distinct data types supported.
These UDFs perform operations unique to image, audio, video, XML, and spatial
objects. Any developer can create additional UDFs for the objects supported by the
extenders as well as for any other reason. UDFs are created with SQL CREATE
FUNCTION statement. The parameter list is rather large but easily understood. In the
following example, a UDF is created that specifies the data type to which the UDF
can be applied, and it performs a financial calculation on the data.
The previous statement defines the data type of the parameter and the data type of
the returned information, both as UDTs. It also states that it is an external function,
written in the C language, and contains no SQL. UDFs can be used in SQL statements
the same way as built-in functions. For example:
UDFs open up a world of options for highly specialized processing for a wide variety
of applications. UDFs are basically subroutines that can be invoked through SQL
statements and can range from simple SQL statements to large COBOL programs.
We could create a UDF called EURO_TO_DOLLAR and use a parameter EURO
amounts or columns, with the result as a dollar amount. The UDF could get
conversion data in real time from another source, but the UDF has to be written only
once and can be used everywhere. UDFs can search and index LOB data, while
others define the behavior of a UDT.
There are about 100 built-in functions, some of which are supplied as example of
UDFs. Casting functions are helpful when dealing with UDTs. Other very important
built-in functions are ROUND, JULIAN_DAY, LOCATE, LTRIM, RTRIM, RAISE_ERROR.
TRIM, and TRUNCATE. The list is long, but these functions help keep more of that
program-code processing inside the engine via SQL, where it belongs and is better
optimized. Among the sample UDFs is ALTDATE, which can return the current date in
any of 34 possible formats, DAYNAME for weekday name, and MONTHNAME for the
name of the month. Watch for many others coming from IBM and elsewhere.
Basically, this example invokes a UDF that gets from somewhere else and returns it
as columns and rows to the SQL statement. There are many implications, such as
how the optimizer can determine which table is the inner and which is the outer for
the join process.
The START FUNCTION SPECIFIC command activates an external function that has
been stopped. You cannot start built-in functions or user-defined functions that are
sourced on another function. You can use the START FUNCTION SPECIFIC command
to activate all or a specific set of stopped external functions.
The new SCOPE (GROUP) option can also be used on the START PROCEDURE
command to allow you to start a UDF on all subsystems in a data sharing group.
The DB2 command DISPLAY FUNCTION SPECIFIC displays statistics about external
user-defined functions that are accessed by DB2 applications. This command displays
an output line for each function that a DB2 application has accessed. The information
that is returned by this command reflects a dynamic status for a point in time that
may change before another DISPLAY is issued. This command does not display
information about built-in functions or user-defined functions that are sourced on
another function.
Use the START FUNCTION SPECIFIC command to activate all or a specific set of
stopped external functions.
To prevent DB2 from accepting SQL statements with invocations of the specified
functions, issue the following statement:
2.8.7 Exercise
1. UDFs are created using DDL using ______ _______ statement.
2. Sourced functions are written using hot language like C, C++, etc.
True/False?
3. Table functions return a _____.
4. Data from non-DB2 objects could be used in DB2 SQLs. _____ functions are
used for this purpose.
5. The DB2 command _____ ______ _______ prevents DB2 from accepting SQL
statements with invocations of UDFs.
Answers:
1. CREATE FUNCTION
2. False
3. Table
4. Table
5. STOP FUNCTION SPECIFIC
2.10 Reference
DB2 High Performance Design and Tuning by Richard Yevich and Susan
Lawson.
UNIT - III
3. Physical Architecture
3.1 Unit Objectives
This unit introduces the physical architecture of DB2. It deals with the Bootstrap
dataset, Active and archive logs, DSNZPARMS and storage groups.
3.2 Introduction
Understanding the journalizing process in DB2 gives much insight into the
architecture of DB2. More or less the same concept is adopted in all the RDBMS.
Here the maintenance of Active and archive logs fall sin the purview of the system
DBA but its understanding helps a great deal in performance tuning critical
applications. The DSNZPARMS are the DB2 installation parameters most of which
cannot be changed without shutting down DB2. But now days the recent versions are
giving the flexibility to change these parameters when actually DB2 is running for
performance improvement.
3.3.1 Introduction
The bootstrap data set (BSDS) is a VSAM key-sequenced data set (KSDS) that
contains information critical to DB2. Specifically, the BSDS contains:
An inventory of all active and archive log data sets known to DB2. DB2 uses
this information to track the active and archive log data sets. DB2 also uses
this information to locate log records to satisfy log read requests during
normal DB2 system activity and during restart and recovery processing.
A wrap-around inventory of all recent DB2 checkpoint activity. DB2 uses this
information during restart processing.
The distributed data facility (DDF) communication record, which contains
information necessary to use DB2 as a distributed server or requester.
Information about buffer pools.
If a BSDS copy fails while DB2 is starting, the startup does not complete.
To recover a lost BSDS, when DB2 is stopped:
hlq.BSDS0n
3.3.4 Exercise
Questions
1. What are the contents of BSDS ?
2. Is BSDS updated when actually DB2 is running
3. Does BSDS give info about the active log dataset names
Answers
1. An inventory of all active and archive log data sets known to DB2 , A wrap-around
inventory of all recent DB2 checkpoint activity , The distributed data facility (DDF)
communication record , about buffer pools
2.YES
3. YES
3.4.1 Introduction
DB2 records all data changes and significant events in a log as they occur. In the
case of failure, DB2 uses this data to recover.
DB2 writes each log record to a disk data set called the active log. When the active
log is full, DB2 copies the contents of the active log to a disk or magnetic tape data
set called the archive log.
A single active log contains between 2 and 31 active log data sets.
With dual logging, the active log has the capacity for 4 to 62 active log data
sets, because two identical copies of the log records are kept.
Each active log data set is a single-volume, single-extent VSAM LDS.
Before you can fully understand how logging works, you need to be familiar with how
database changes are made to ensure consistency. In this section, we discuss units
of recovery and rollbacks.
Application Process
Unit of Recovery
Point of Consistency
Figure 1: A unit of recovery within an application process
For example, a bank transaction might transfer funds from account A to account B.
First, the program subtracts the amount from account A. Next, it adds the amount to
account B. After subtracting the amount from account A, the two accounts are
inconsistent. These accounts are inconsistent until the amount is added to account B.
When both steps are complete, the program can announce a point of consistency and
thereby make the changes visible to other application programs.
If failure occurs within a unit of recovery, DB2 backs out any changes to data,
returning the data to its state at the start of the unit of recovery; that is, DB2
undoes the work. The events are shown in Figure 2 The SQL ROLLBACK statement,
and deadlocks and timeouts (reported as SQLCODE -911, SQLSTATE 40001), cause
the same events.
The effects of inserts, updates, and deletes to large object (LOB) values are backed
out along with all the other changes made during the unit of work being rolled back,
even if the LOB values that were changed reside in a LOB table space with the LOG
NO attribute.
An operator or an application can issue the CANCEL THREAD command with the
NOBACKOUT option to cancel long running threads without backingout data changes.
As a result, DB2 does not read the log records and does not write or apply the
compensation log records. After CANCEL THREAD NOBACKOUT processing, DB2
marks all objects associated with the thread as refresh pending (REFP) and puts the
objects in a logical page list (LPL). The NOBACKOUT request might fail for either of
the following two reasons:
DB2 does not completely back out updates of the catalog or directory
(message DSNI032I with reason 00C900CC).
The thread is part of a global transaction (message DSNV439I).
1. DB2 registers changes to data and significant events in recovery log records.
2. DB2 processes recovery log records and breaks them into segments if
necessary.
3. Log records are placed sequentially in output log buffers, which are formatted
as VSAM control intervals (CIs). Each log record is identified by a continuously
The log buffers are written to an active log data set when they become full, when the
write threshold is reached (as specified on the DSNTIPL panel), or, more often, when
the DB2 subsystem forces the log buffer to be written (such as, at commit time). In
the last case, the same control interval can be written several times to the same
location. The use of dual active logs increases the reliability of recovery.
When DB2 is initialized, the active log data sets named in the BSDS are dynamically
allocated for exclusive use by DB2 and remain allocated exclusively to DB2 (the data
sets were allocated as DISP=OLD) until DB2 terminates. Those active log data sets
cannot be replaced, nor can new ones be added, without terminating and restarting
DB2. The size and number of log data sets is indicated by what was specified by
installation panel DSNTIPL.
The process of copying active logs to archive logs is called offloading. The relation of
offloading to other logging events is shown schematically in Figure 3.
Write to Triggering
active log event
Write to
archive log
Offload
process Record on
Figure 3: The offloading process
BSDS
3.4.8 Triggering log offload
An offload of an active log to an archive log can be triggered by several events. The
most common are when:
During the process, DB2 determines which data set to offload. Using the last log RBA
offloaded, as registered in the BSDS, DB2 calculates the log RBA at which to start.
DB2 also determines the log RBA at which to end, from the RBA of the last log record
in the data set, and registers that RBA in the BSDS.
When all active logs become full, the DB2 subsystem runs an offload and halts
processing until the offload is completed. If the offload processing fails when the
active logs are full, then DB2 cannot continue doing any work that requires writing to
the log.
When an active log is ready to be offloaded, a request can be sent to the MVS
console operator to mount a tape or prepare a disk unit. The value of the field WRITE
TO OPER of the DSNTIPA installation panel determines whether the request is
received. If the value is YES, the request is preceded by a WTOR (message number
DSNJ008E) informing the operator to prepare an archive log data set for allocating.
The operator can respond by canceling the offload. In that case, if the allocation is
for the first copy of dual archive data sets, the offload is merely delayed until the
next active log data set becomes full. If the allocation is for the second copy, the
archive process switches to single copy mode, but for the one data set only.
Archive log data sets can be placed on standard label tapes or disks and can be
managed by DFSMShsm (Data Facility Hierarchical Storage Manager). They are
always written by QSAM. Archive logs on tape are read by BSAM; those on disk are
read by BDAM. Each MVS logical record in an archive log data set is a VSAM CI from
the active log data set. The block size is a multiple of 4 KB.
Output archive log data sets are dynamically allocated, with names chosen by DB2.
The data set name prefix, block size, unit name, and disk sizes needed for allocation
are specified when DB2 is installed, and recorded in the DSNZPxxx module. You can
also choose, at installation time, to have DB2 add a date and time to the archive log
data set name.
It is not possible to specify specific volumes for new archive logs. If allocation errors
occur, offloading is postponed until the next time offloading is triggered.
If you specify dual archive logs at installation time, each log CI retrieved from the
active log is written to two archive log data sets. The log records that are contained
on a pair of dual archive log data sets are identical, but end-of-volumes are not
synchronized for multivolume data sets.
Archiving to disk offers faster recoverability but is more expensive than archiving to
tape. If you use dual logging, you can specify on installation panel DSNTIPA that the
primary copy of the archive log go to disk and the secondary copy go to tape.
This feature increases recovery speed without using as much disk. The second tape
is intended as a backup or can be sent to a remote site in preparation for disaster
recovery. To make recovering from the COPY2 archive tape faster at the remote site,
use the new installation parameter, ARC2FRST, to specify that COPY2 archive log
should be read first. Otherwise, DB2 always attempts to read the primary copy of the
archive log data set first.
If the unit name reflects a tape device, DB2 can extend to a maximum of twenty
volumes. DB2 passes a file sequence number of 1 on the catalog request for the first
file on the next volume. Though that might appear to be an error in the integrated
catalog facility catalog, it causes no problems in DB2 processing.
If you choose to offload to tape, consider adjusting the size of your active log data
sets such that each set contains the amount of space that can be stored on a nearly
full tape volume. That adjustment minimizes tape handling and volume mounts and
maximizes the use of tape resources. However, such an adjustment is not always
necessary.
If you want the active log data set to fit on one tape volume, consider placing a copy
of the BSDS on the same tape volume as the copy of the active log data set. Adjust
the size of the active log data set downward to offset the space required for the
BSDS.
All archive log data sets allocated on disk must be cataloged. If you choose to
archive to disk, then the field CATALOG DATA of installation panel DSNTIPA must
contain YES. If this field contains NO, and you decide to place archive log data sets
on disk, you receive message DSNJ072E each time an archive log data set is
allocated, although the DB2 subsystem still catalogs the data set.
If you use disk storage, be sure that the primary and secondary space quantities and
block size and allocation unit are large enough so that the disk archive log data set
does not attempt to extend beyond 15 volumes. That minimizes the possibility of
unwanted MVS B37 or E37 abends during the offload process. Primary space
allocation is set with the PRIMARY QUANTITY field of the DSNTIPA installation panel.
The primary space quantity must be less than 64K tracks because of the DFSMS
Direct Access Device Space Management limit of 64K tracks on a single volume when
allocating a sequential disk data set.
A properly authorized operator can archive the current DB2 active log data sets,
whenever required, by issuing the ARCHIVE LOG command. Using ARCHIVE LOG can
help with diagnosis by allowing you to quickly offload the active log to the archive log
where you can use DSN1LOGP to further analyze the problem.
To issue this command, you must have either SYSADM authority, or have been
granted the ARCHIVE privilege.
-ARCHIVE LOG
When you issue the above command, DB2 truncates the current active log data sets,
then runs an asynchronous offload, and updates the BSDS with a record of the
offload. The RBA that is recorded in the BSDS is the beginning of the last complete
log record written in the active log data set being truncated.
You could use the ARCHIVE LOG command as follows to capture a point of
consistency for the MSTR01 and XUSR17 databases:
In this simple example, the STOP command stops activity for the databases before
archiving the log.
Another method of ensuring that activity has stopped before the log is archived is
the MODE(QUIESCE) option of ARCHIVE LOG. With this option, DB2 users are
quiesced after a commit point, and the resulting point of consistency is captured in
the current active log before it is offloaded. Unlike the QUIESCE utility, ARCHIVE LOG
MODE(QUIESCE) does not force all changed buffers to be written to disk and does
not record the log RBA in SYSIBM.SYSCOPY. It does record the log RBA in the boot
strap data set.
The MODE(QUIESCE) option suspends all new update activity on DB2 up to the
maximum period of time specified on the installation panel DSNTIPA. If the time
needed to quiesce is less than the time specified, then the command completes
successfully; otherwise, the command fails when the time period expires. This time
amount can be overridden when you issue the command, by using the TIME option:
The above command allows for a quiesce period of up to 60 seconds before archive
log processing occurs.
Use the LOGLOAD or CHKTIME option of the SET LOG command to dynamically
change the checkpoint frequency without recycling DB2. The LOGLOAD value
specifies the number of log records that DB2 writes between checkpoints. The
CHKTIME value specifies the number of minutes between checkpoints. Either value
affects the restart time for DB2.
For example, during prime shift, your DB2 shop might have a low logging rate, but
require that DB2 restart quickly if it terminates abnormally. To meet this restart
requirement, you can decrease the LOGLOAD value to force a higher checkpoint
frequency. In addition, during off-shift hours the logging rate might increase as
batch updates are processed, but the restart time for DB2 might not be as critical. In
that case, you can increase the LOGLOAD value which lowers the checkpoint
frequency.
You can also use the LOGLOAD or CHKTIME option to initiate an immediate system
checkpoint:
The CHKFREQ value that is altered by the SET LOG command persists only while DB2
is active. On restart, DB2 uses the CHKFREQ value in the DB2 subsystem parameter
load module.
Use the DB2 command SET ARCHIVE to set the upper limit for the number of and the
deallocation time of tape units for the archive log. This command overrules the
values specified during installation or in a previous invocation of the SET ARCHIVE
command. The changes initiated by SET ARCHIVE are temporary; at restart, DB2
uses the values that were set during installation.
Use the DISPLAY LOG command to display the current checkpoint frequency (either
the number of logs records or the minutes between checkpoints to obtain additional
information about log data sets and checkpoints from the Print Log Map utility
(DSNJU004).
3.4.12Naming convention
hlq.LOGCOPYn.DSmm
hlq.ARCHLOGn.Dyyddd.Thhmmsst.axxxxxx
3.4.13Performance considerations
Because these operations are independent from the application program, the DB2
accounting trace cannot show these writes. The DB2 PM statistics report is required
to see the asynchronous writes.
The virtual buffer pool is too small and the immediate write threshold (IWTH) is
exceeded.
More than two DB2 checkpoints have been taken during the execution of a unit of
work, and an updated page has not been written out to disk.
When the conditions for synchronous write occur, the updated page is written to disk
as soon as the update completes. The write is synchronous with the application
program SQL request; that is, the application program waits until the write has been
completed. These writes are shown in the DB2 accounting trace and in the DB2PM
statistics report
Table spaces containing pages, which are frequently reread and updated, should
have a high threshold, placing them in a virtual buffer pool with a high DWQT, orhigh
VDWQT. This ensures that pages are reused in storage. The higher this rate, the
better the page reuse for write is in this virtual buffer pool. Large table spaces,
where updates are very scattered and page reuse is infrequent or improbable, can
have their threshold set low, even to zero. A zero threshold means that updated
pages are written to disk very frequently. In this case, the probability of finding the
update page still on the disk cache is higher (cache hit) helping with disk
performance. A low threshold also reduces the write impact at checkpoint time.
Following figure 5 gives the DB2 PM accounting trace buffer pool report extract
Care must be taken if trying to tune the write efficiency with the LOGLOAD value.
DB2 checkpoint performance can be adversely impacted by the LOGLOAD value set
too high. LOGLOAD is the installation parameter that establishes the number of LOG
control intervals generated before taking a checkpoint. If this value is excessive, a
large amount of disk writing takes place at checkpoint, and the DB2 restart time in
case of failure is also impacted. With DB2 V6 the LOGLOAD value can be dynamically
changed to reflect changes in the workload.
TOT4K TOTAL
--------------------- --------
BPOOL HIT RATIO (%) 2
GETPAGES 6135875
BUFFER UPDATES 48
SYNCHRONOUS WRITE 0 F
SYNCHRONOUS READ 19559 A
SEQ. PREFETCH REQS 164649 B
LIST PREFETCH REQS 0 C
DYN. PREFETCH REQS 26065 D
PAGES READ ASYNCHR. 5943947 E
HPOOL WRITES 0
HPOOL WRITES-FAILED 0
PAGES READ ASYN-HPOOL 0
HPOOL READS 0
HPOOL READS-FAILED 0
Figure 5: DB2PM accounting trace
Application programs create log records when data is updated. Each data update
requires two log records, one with the data before the update, and another with the
data after the update, generally combined into one physical record. The application
program uses two methods to move log records to the log output buffer:
NOWAIT
FORCE
3.4.13.7.1 No Wait
Most log records are moved to the log output buffer, and control is immediately
returned to the application program. These moves are the most common. If no log
buffer is available, the application must wait for one to become available. Log
records moved into the output buffer by an application program appear in a DB2 PM
statistics report as the number of NOWAIT requests
3.4.13.7.2 Force
At commit time, the application must wait to ensure that all changes have been
written to the log. In this case, the application forces a write of the current and
previous unwritten buffers to disk. Because the application waits for this to be
completed, it is also called a synchronous write.
3.4.13.7.3 Physical writes
The log records in the log output buffer are written from the output buffer to disk.
DB2 uses two types of log writes: asynchronous and synchronous, which will be
explained further.
DB2 writes the log records (the control intervals) from the output buffer to the active
log data set when the number of log buffers used reaches the value the installation
set for the WRITE THRESHOLD field of installation panel DSNTIPL . The application is
not aware of these writes.
Synchronous writes usually occur at commit time when an application has updated
data. This write is called forcing the log, because the application must wait for DB2
to write the log buffers to disk before control is returned to the application. If the log
data set is not busy, all log buffers are written to disk. If the log data set is busy, the
requests are queued until it is freed.
3.4.13.7.4 Writing to two logs
If there are two logs (recommended for availability), the write to the first log, in
general, must complete before the write to the second log begins. The first time alog
control interval is written to disk, the write I/Os to the log data sets are done in
parallel. However, if the same 4 KB log control interval is again written to disk, then
the write I/Os to the log data sets must be done serially to prevent any possibility of
losing log data in case of I/O errors occurring on both copies simultaneously. This
method improves system integrity. I/O overlap in dual logging occurs whenever
multiple log control intervals have to be written; for example, when the WRITE
THRESHOLD value is reached, or when log records accumulate because of a log
device busy condition
3.4.13.7.5 Two phase commit log writes
IMS applications with DB2, and CICS and RRS applications with additional resources
besides DB2 to manage, use two-phase commit protocol. Because they use two-
phase commit, these applications force writes to the log twice. The first write forces
all the log records of changes to be written (if they have not been written previously
because of the write threshold being reached). The second write writes a log record
that takes the unit of recovery into an in-commit state.
No Wait Force
Async Sync
Active log
Dataset
Force Force
End of Phase 1 Beginning of Phase 2
End of
I/O I/O
COMMIT
Log1
I/O I/O
Log2
The OUTPUT BUFFER field of installation panel DSNTIPL lets the system administrator
specify the size of the output buffer used for writing active log data sets. With DB2
V6, the maximum size of this buffer (OUTBUFF) is 400000 KB. Choose as large a size
as the MVS system can support without incurring additional paging. A large buffer
size will improve both log read and log write performance. If the DB2 PM statistics
report shows a non-zero value, the log output buffer is too small.
The WRITE THRESHOLD field of installation panel DSNTIPL indicates the number of
contiguous 4KB output buffer pages that are allowed to fill before data is written to
the active log data set. The default is 20 buffers, and this is recommended. Never
choose a value that is greater than 20% of the number of buffers in the output
buffer.
The devices assigned to the active log data sets must be fast. In a transactional
environment, the DB2 log may have a very high write I/O rate and will have direct
impact on the transaction response time. In general, log data sets can make
effective use of the DASD Fast Write feature of IBM's 3990 cache.
To avoid contention on the disks containing active log data sets, place the data sets
so that the following objectives are achieved:
Do not place any other data sets on disks containing active log data sets. Place the
copy of the bootstrap data set and, if using dual active logging, the copy of the
active log data sets, on volumes that are accessible on a path different from that of
their primary counterparts. Place sequential sets of active log data sets on different
access paths to avoid contention while archiving. To achieve all this, a minimum of
three volumes on separate access paths is required for the log data sets.
If the log records are in the output buffer, DB2 reads the records directly from that
buffer. If the log records are in the active or archive log, DB2 moves those log
records into the input buffer used by the reading process (such as a recovery job or
a rollback). From a performance point of view, it is always best for DB2 to obtain the
log records from the output buffer. These accesses are reported by DB2 PM; The
next fastest access for DB2 is the active log. Access to the archive log is not
desirable; it can be delayed for a considerable length of time. For example, tape
drives may not be available, or a tape mount can be required.
3.4.13.8.1 Improving log read performance
In this section we present some considerations on choices to improve log read
performance.
Active Log Size: Active logs should be large enough to avoid reading the archives,
especially during restart, rollback, and recovery. When data is backed out,
performance is optimal if the data is available from the output buffer or from the
active log. If the data is no longer available from the active log, the active log is
probably too small.
Log Input Buffer: The default size for the input buffer is 60 KB. It is specified in the
INPUT BUFFER field of installation panel DSNTIPL . The default value is
recommended.
Avoid Device Contention: Avoid device contention on the log data sets.
Archive to Disk or Tape: If the archive log data set resides on disk, it can be
shared by many log readers. In contrast, an archive on tape cannot be shared
among log readers. Although it is always best to avoid reading archives altogether, if
a process must read the archive, that process is serialized with anyone else who
must read the archive tape volume. For example, every rollback that accesses the
archive log must wait for any previous rollback work that accesses the same archive
tape volume to complete.
Recovery times can be reduced by eliminating tape mounts and rewind time for
archive logs kept on tape.
Multiple RECOVER utilities can be run in parallel.
DB2 log data can span a greater length of time than what is currently kept in
your active log data sets.
Need for tape drives during DB2 archive log creation is eliminated. If DB2 needs
to obtain a tape drive on which to create the archive logs and it cannot allocate
one, all activity will stop until DB2 can create the archive log data sets.
If you allow DB2 to create the archive log data sets on RVA disks, you can take
advantage of the compression capability offered by the device. Depending on the
type of application data DB2 is processing and storing in the log data sets, you could
obtain a very good reduction in DASD occupancy with RVA and achieve good
recoverability at a reasonable price.
Archive to Disk and Tape: DB2 V5 has introduced the option to archive one copy
of the log to disk and the other one to tape. This allows more flexibility than when
archiving only to tapes and disk space savings when compared to archiving only to
disk.
In case of unavailability of tape units, you can, in fact, cancel the request for
allocation (having previously set the WRITE TO OPER parameter to YES in the
Archive Log) and let DB2 continue with a single archiving.
Disk space utilization is improved by reducing the number of data sets for the
dual copy of active logs to one copy of the archive log data set on disk and one
on tape.
Active Log Size: The capacity the system administrator specifies for the active log
can affect DB2 performance significantly. If the capacity is too small, DB2 might
need to access data in the archive log during rollback, restart, and recovery.
Accessing an archive log generally takes longer than accessing an active log. An
active log, which is too small, is shown by a non-zero value in.
Log Sizing Parameters: The following DB2 parameters affect the capacity of the
active log. In each case, increasing the value the system administrator specifies for
the parameter increases the capacity of the active log. The parameters are:
The NUMBER OF LOGS field on the installation panel DSNTIPL controls the number
of active log data sets.The ARCHIVE LOG FREQ field on the installation panel
DSNTIPL controls how often active log data sets are copied to the archive log. The
UPDATE RATE on the installation panel DSNTIPL is an estimate of how many
database changes (inserts, update, and deletes) are expected per hour. The
CHECKPOINT FREQ on the installation panel DSNTIPN specifies the number of log
records that DB2 writes between checkpoints. The DB2 installation CLIST uses
UPDATE RATE and ARCHIVE LOG FREQ to calculate the data set size of each active
log data set.
Calculating Average Log Record Size: One way to determine how much log
volume is needed is to calculate the average size in bytes of log records written. To
do this, the DB2 system administrator needs values from the statistics report: the
NOWAIT counter C, and the number of control intervals created in the active log,
counter D. Use the following formula:
Using this value to estimate logging needs, plus considering the available device
sizes, the DB2 system administrator can update the output of the installation CLIST
to modify the calculated values for active log data set sizes.
3.4.14Exercise
Questions
1. list down the points which affects the log read and log write performance
2. What is the log dataset name of your installation
Answers
1. Log write performance : OUTPUT BUFFER , WRITE THRESHOLD , data set on
dedicated volumes , access path for primary and secondary log data sets and Log
read performance : INPUT BUFFER , Archive to Disk or Tape , NUMBER OF LOGS ,
Average Log Record Size
2. Depends on your installation .
3.5 DSNZPARMS
The subsystem parameter module is generated by job DSNTIJUZ each time you
install, migrate, or update DB2. Seven macros expand to form this data-only
subsystem parameter load module. It contains the DB2 execution-time parameters
that you selected using the ISPF panels. These seven macros are DSN6ARVP,
DSN6ENV, DSN6FAC, DSN6LOGP, DSN6SPRM, DSN6SYSP, and DSN6GRP. These
parameters provide DB2 subsystem with lots of control information for its
functioning. Here we will just discuss a few and the following table will give the
exhaustive list of DSNZPARMS.
3.5.1 IRLMRWT
This is the number of seconds that a transaction will wait for a lock before a time out
is detected. The IRLM uses this value for timeout and deadlock detection. Most shops
take this default as 60 seconds but more and more high performance situations
where detection should occur sooner (so that the application do not incur excessive
wait lock times) it is set to lower. Is this threshold is exceeded the application is
often reviewed and tuned. The simple philosophy in practice is that in high
performance applications those that do 10000 to 20000 SQL statements per second,
waiting more than 5 seconds for a lock signals there that is something really wrong
has happened.
3.5.2 RECURHL
The use of this can help in concurrency. When its set to YES it allows DB2 to release
the locks that are held by cursor defined WITH HOLD but still to maintain the position
of the open cursor.
3.5.3 XLKUPDLT
This is new in version 6. It allows you to specify the locking method to use when
searched update or delete is performed. The default is no which is best for
concurrency. When its set to NO DB2 uses S or U lock when scanning qualifying rows
and then upgrades to X lock when the qualifying rows are found. The value of YES is
useful in data sharing environments when the search involves index because it takes
X lock on the qualifying rows or pages. During the scan of the index no data rows are
touched but when the qualifying row is found and immediate request for an X lock is
issued thus assuring that the update or delete completes rapidly when the lock is
acquired and that the transaction
3.5.4 NUMLKTS
It represents the maximum number of locks on an object. If you turn off lock
escalation (LOCKMAX 0 on the tabelspace), you need to increase this number. If you
use LOCKMAX SYSTEM on any individual tablespace, the value defined here in
NUMLKTS is the value of the system.
3.5.5 NUMLKUS
Its the maximum number of page or row locks that a single application can hold
concurrently on all table spaces. This includes data pages, index pages, index sub
pages (only for Type 1 index) and rows. If you specify 0 there is not limit on the
number of locks. You should be careful with 0, because of you turn off lock escalation
and do not commit frequently enough, you could run into storage problems (DB2
uses approximately 250 bytes for each lock). These storage problems can completely
consume all available storage and potentially shut down the system.
3.5.6 LOGLOAD
The DB2 Checkpoint Interval It is the factor that has the most influence on the speed
of DB2 startup. This is the number of log records that DB2 writes between successive
checkpoints. This value is controlled by the DB2 subsystem parameter LOGLOAD.
Choosing a reasonable LOGLOAD value involves balancing speed of restart with the
overhead of taking more frequent checkpoints. Generally it is best to set the
LOGLOAD so that a checkpoint is taken every 10 to 15 minutes during periods of
peak activity. In a data-sharing environment, carefully evaluate the value of
LOGLOAD for each member separately. If one member does frequent updates, its
LOGLOAD may be lower than the one for a member that is mainly issuing queries. It
is not recommended to have a LOGLOAD value higher then 500,000.
3.5.8 Exercise
Questions
1. List down the DSNZPARM used by the IRLMPROC?
2. What are the parameters for DB2 thread control?
Answers
1. IRLMRWT, RECURHL, XLKUPDLT, NUMLKTS, NUMLKUS
2. CMTSTAT, CTHREADS, IDTHTOIN, MAXTYPE1, POOLINAC
A DB2 storage group is a set of volumes on direct access storage devices (DASD).
The volumes hold the data sets in which tables and indexes are actually stored. The
description of a storage group names the group and identifies its volumes and the
VSAM catalog that records the data sets.
All volumes of a given storage group must have the same device type. But, parts of
a single database can be stored in different storage groups.
It is a list of DASD volumes you specify to hold your DB2 objects. Storage is then
allocated from these volumes as your tables are loaded with data.
DB2 manages the auxiliary storage requirements of a DB2 database by using DB2
storage groups. Data sets in these DB2 storage groups are DB2-managed data sets.
These DB2 storage groups are not the same as storage groups defined by
DFSMS/MVS's storage management subsystem (DFSMS). A DB2 storage group is a
named set of DASD volumes, in which DB2 does the following:
catname
Integrated catalog name or alias (up to eight characters). Use the same name
or alias here as in the USING VCAT clause of the CREATE TABLESPACE and
CREATE INDEX statements.
x
C (for VSAM clusters) or D (for VSAM data components).
dbname
DB2 database name. If the data set is for a table space, dbname must be the
name given in the CREATE TABLESPACE statement. If the data set is for an
index, dbname must be the name of the database containing the base table.
If you are using the default database, dbname must be DSNDB04.
psname
Tablespace name or index name. This name must be unique within the
database. You will use this name on the CREATE TABLESPACE or CREATE
INDEX statement. (You can use a name longer than eight characters on the
CREATE INDEX statement, but the first eight characters of that name must be
the same as in the data set's psname.)
nnn
Dataset number. For partitioned table spaces, the number is 001 for the first
partition, 002 for the second, and so forth, up to the maximum of 254
partitions. For a non-partitioning index on a partitioned table space that you
defined using the LARGE option, the maximum data set number is 128.For
simple or segmented tablespaces, the number is 001 for the first data set.
When space runs short, DB2 issues a warning message. If the size of the data
set for a simple or segmented table space approaches 2 gigabytes, define
another data set. Give it the same name as the first data set, and the number
002. The next data set will be 003, and so forth. You might eventually need
up to 32 data sets (the maximum) for a simple or segmented table space. For
table spaces, it is possible to reach the 119-extent limit for the data set
before reaching the 2-gigabyte limit for a Nonpartitioned table space or the 4-
gigabyte limit for a partitioned table space. If this happens, DB2 does not
extend the data set.
3. You must use the DEFINE CLUSTER command to define the size of the
primary and secondary extents of the VSAM cluster. If you specify zero for
the secondary extent size, data set extension does not occur.
4. If you specify passwords when defining a VSAM data set, give your highest-
level password in the DSETPASS clause (in the CREATE TABLESPACE or
CREATE INDEX statement).
5. Define the data sets as LINEAR. Do not use RECORDSIZE or
CONTROLINTERVALSIZE; these attributes are invalid, and are replaced by the
specification LINEAR.
6. Use the REUSE option. You must define the data set as REUSE in order to use
the DSN1COPY utility.
7. Use SHAREOPTIONS (3,3).
The DEFINE CLUSTER command has many optional parameters that do not apply
when the data set is used by DB2. If you use the parameters SPANNED,
EXCEPTIONEXIT, SPEED, BUFFERSPACE, or WRITECHECK, VSAM applies them to
your data set, but DB2 ignores them when it accesses the data set. The OWNER
parameter value for clusters defined for storage groups is the first SYSADM
authorization ID specified at installation. When you drop indexes or table spaces for
which you defined the data sets, you must delete the data sets yourself unless you
want to reuse them. To reuse a data set, first commit, and then create a new table
space or index with the same name. When DB2 uses the new object, it overwrites
the old information with new information, destroying the old data.
Likewise, if you delete data sets, you must drop the corresponding table spaces and
indexes; DB2 does not do it automatically.
When you want to move data sets to a new volume, you can alter the volumes list in
your storage group. DB2 will automatically relocate your data sets during utility
operations that build or rebuild a data set (LOAD REPLACE, REORG, and RECOVER).
With user-defined data sets, on the other hand, you must delete and redefine your
data sets in order to move them.
After you define a storage group, DB2 stores information about it in the DB2 catalog.
(This catalog is not the same as the integrated catalog facility catalog that describes
DB2 VSAM data sets). The catalog table SYSIBM.SYSSTOGROUP has a row for each
storage group and SYSIBM.SYSVOLUMES has a row for each volume. With the proper
authorization, you can display the catalog information about DB2 storage groups by
using SQL statements. Use storage groups whenever you can, either specifically or
by default. However, if you want to maintain closer control over the physical storage
of your tables and indexes, you can define and manage your own VSAM data sets
using VSAM access method services. For both user-managed and DB2-managed
data sets, you need at least one integrated catalog facility catalog, either user or
master, created with the integrated catalog facility. You must identify the integrated
catalog facility catalog (the "integrated catalog") when you create a storage group or
when you create a table space that does not use storage groups.
3.6.6 Exercise
Questions:
1. Given a table space how do we find out the values that it resides
2. Write A SQL to find out the information about a specific storage group
Answers:
1. Using the SYSIBM.SYSTABLESPACE AND SYSIBM.SYSTABLES
2. SELECT SGNAME, VOLID, SPACE, SPCDATE
FROM SYSIBM.SYSVOLUMES, SYSIBM.SYSSTOGROUP
WHERE SGNAME=NAME
3.8 Reference
UNIT - IV
4. Data Services
4.1 Unit Objectives
We will be dealing with the various memory handling detail of the DB2 subsystem.
This is the maximum memory area that DB2 requires for its functioning
4.2 Introduction
There are four pool types used by DB2 to cache information in memory as it
operates: buffer, EDM, RID and sort. The longer information can be cached in
memory, the better the chance the data can be reused by other processes – without
reading it from disk again. When disk I/O can be avoided, database performance is
enhanced.
4.3.1 Introduction
Buffer pools are areas of virtual storage that temporarily store pages of table spaces
or indexes. When an application program accesses a row of a table, DB2 places the
page containing that row in a buffer. If the requested data is already in a buffer, the
application program does not have to wait for it to be retrieved from DASD. Avoiding
the need to retrieve data from DASD results in faster performance.
If the row is changed, the data in the buffer must be written back to DASD
eventually. But that write operation might be delayed until DB2 takes a checkpoint,
or until one of the related write thresholds is reached.
The data remains in the buffer until DB2 decides to use the space for another page.
Until that time, the data can be read or changed without a DASD I/O operation.
DB2 allows you to use up to 50 buffer pools that contain 4KB buffers and 10 buffer
pools that contain 32KB buffers. You can set the size of each of those buffer pools
separately when installing DB2. You can change the sizes and other characteristics of
a buffer pool at any time while DB2 is running, by using the ALTER BUFFERPOOL
command.
happens for both data pages and index pages. Whenever a user or program accesses
a particular piece of data, DB2 first checks for it in the buffer pools. If it exists there,
DB2 can avoid an expensive I/O to disk, thereby enhancing performance.
DB2 buffer pools provide one of the most productive areas for performance tuning
and optimization. In general, DB2 loves large buffer pools. But buffer pools are
backed by memory, and memory is expensive. So tuning the size of the DB2 buffer
pools appropriately, based on application workload, is important. However, it is also
complex: there are 80 different buffer pools used by DB2, each of which can have
multiple DB2 tablespaces and indexes assigned to them. And there are tuning knobs
for each of the 80 buffer pools that control things such as how the buffer pool is
optimized for random versus sequential access and how parallel operations are
handled.
Tuning considerations include determining how many buffer pools and hiperpools to
define, the size and settings of each pool, which objects should be grouped together
into which pools, and how the configuration should be impacted as workloads
change. Each of these tuning options can have a tremendous impact on the
performance of database applications.
Monitoring activity in the buffer pools for multiple, concurrent applications is often
too difficult for resource-constrained DBA groups. As such, buffer pool tuning is
usually accomplished only when a problem occurs. And therefore, resources may be
wasted (because buffer pools are over-allocated) or applications may be running
slower (if buffer pools are under-allocated).
Without Pool Advisor, the task of properly configuring buffer pools is typically too
great to be performed. First, the data required to classify and group similar objects is
not readily available without expensive, high-volume buffer traces. Second, data
objects at a typical DB2 site now number in the thousands or tens of thousands, as
seen in an ERP shop. The primary tuning methodology that Pool Advisor uses is
based on standard industry techniques advocated by IBM® and tuning professionals
for years. This methodology involves:
DB2 cannot directly manipulate data that resides in hiperspace, but it can transfer
the data from hiperspace into a regular DB2 buffer pool much faster than it could get
it from DASD. To distinguish between hiperpools and buffer pools, we now refer to
the regular DB2 buffer pools as virtual buffer pools.
On systems that have the prerequisite hardware and software, DB2 maintains two
levels of storage for each buffer pool:
The first level of storage, the virtual buffer pool, is allocated from
DB2’s ssnmDBM1 address space. A virtual buffer pool is backed by
central storage, expanded storage, or auxiliary storage. The sum of all
DB2 virtual buffer pools cannot exceed 1.6GB.
The second level of storage, the hiperpool, uses the MVS/ESA
hiperspace facility to utilize expanded storage only (ESO) hiperspace.
The sum of all hiperpools cannot exceed 8GB. Hiperpools are optional.
Virtual buffer pools hold the most frequently accessed data, while hiperpools serve
as a cache for data that is accessed less frequently. When a row of data is needed
from a page in a hiperpool, the entire page is read into the corresponding virtual
buffer pool. If the row is changed, the page is not written back to the hiperpool until
it has been written to DASD: all read and write operations to data in the page, and
all DASD I/O operations, take place in the virtual buffer pool. The hiperpool holds
only pages that have been read into the virtual buffer pool and might have been
discarded; they are kept in case they are needed again.
Because DASD read operations are not required for accessing data that resides in
hiperspace, response time is shorter than for DASD retrieval. Retrieving pages
cached in hiperpools takes only microseconds, rather than the milliseconds needed
for retrieving a page from DASD, which reduces transaction and query response
time.
Reducing the size of your virtual buffer pools and allocating hiperpools provides
better control over the use of central storage and can reduce overall contention for
central storage. The maximum expanded storage available on ES/9000 processors is
8GB.
A virtual buffer pool and its corresponding hiperpool, if defined, are built dynamically
when the first page set that references those buffer pools is opened.
Sequential prefetch can be used to read data pages, by table space scans or index
scans with clustered data reference. It can also be used to read index pages in an
index scan. Sequential prefetch allows CP and I/O operations to be overlapped.
List Sequential Prefetch: This mechanism is used to prefetch data pages that are not
contiguous (such as through non-clustered indexes). List prefetch can also be used
by incremental image copy. For a complete description of the mechanism .
The table spaces and indexes of the directory (DSNDB01) and catalog (DSNDB06)
are assigned to BP0; you cannot change that assignment. BP0 is also the default
virtual buffer pool for sorting. It has a default size of 2000 buffers, and a minimum
of 56 buffers.
4.3.3.2.1Fixed Thresholds
Fixed Thresholds: SPTH DMTH IWTH
Queued
Per dataset
Unavailable Pages Available pages
Some thresholds, like the immediate write threshold, you cannot change. Monitoring
buffer pool usage includes noting how often those thresholds are reached. If they are
reached too often, the remedy is to increase the size of the virtual buffer pool or
hiperpool, which you can do with the ALTER BUFFERPOOL command. Increasing the
size, though, can affect other buffer pools, depending on the total amount of central
and expanded storage available for your buffers.
The fixed thresholds are more critical for performance than the variable thresholds.
Generally, you want to set virtual buffer pool sizes large enough to avoid reaching
any of these thresholds, except occasionally. Each of the fixed thresholds is
expressed as a percentage of the buffer pool that might be occupied by unavailable
pages.
4.3.3.2.2The fixed thresholds are (from highest to lowest value):
Immediate Write Threshold (IWTH)--97.5% This threshold is checked
whenever a page is to be updated. If it has been exceeded, the
updated page is written to DASD as soon as the update completes.
The write is synchronous with the SQL request; that is, the request
waits until the write has been completed and the two operations are
not carried out concurrently. Reaching this threshold has a significant
effect on processor usage and I/O resource consumption. For example,
updating three rows per page in 10 sequential pages ordinarily
requires one or two write operations. When IWTH is exceeded,
however, the updates require 30 synchronous writes.
Sometimes DB2 uses synchronous writes even when the IWTH is not exceeded; for
example, when more than two checkpoints pass without a page being written.
Situations such as these do not indicate a buffer shortage.
4.3.3.2.3Variable Thresholds
Changing a threshold in one virtual buffer pool or hiperpool has no effect on any
other virtual buffer pool or hiperpool. The variable thresholds are (from highest to
lowest default value):
you to set VDWQT to a value greater than DWQT. This threshold is overridden
by certain DB2 utilities, which use a constant limit of 64 pages rather than a
percentage of the virtual buffer pool size. LOAD, REORG, and RECOVER use a
constant limit of 128 pages.
4.3.3.2.4Guidelines for Setting Buffer Pool Thresholds
Because increasing DWQT and VDWQT allows updated pages to use a larger portion
of the virtual buffer pool, setting DWQT and VDWQT to large values can have a
significant effect on the other thresholds. For example, for a work load in which
pages are frequently updated, and the set of pages updated exceeds the size of the
virtual buffer pool, setting both DWQT and VDWQT to 90% would probably cause the
sequential prefetch threshold (and possibly the data management threshold and the
immediate write threshold) to be reached frequently.
If a virtual buffer pool is large enough, it is unlikely that the default values of either
DWQT or VDWQT will ever be reached. In this case, there tend to be surges of write
I/Os as deferred writes are triggered by DB2 checkpoints. Lowering the VDWQT and
the DWQT could improve performance by distributing the write I/Os more evenly
over time.
If you set VPSEQT to 0%, the value of HPSEQT is essentially meaningless: because
when sequential pages are not kept in the virtual buffer pool, they have no chance of
ever going to the hiperpool. But there is no restriction against having a non-zero
value for HPSEQT with a zero value for VPSEQT. Buffer Pools Used for Queries and
Transactions: For a buffer pool used exclusively for query processing, it is reasonable
to set VPSEQT and HPSEQT to 100%. For a buffer pool used for both query and
transaction processing, the values you set for VPSEQT and HPSEQT should depend
on the respective priority of the two types of processing. The higher you set VPSEQT
and HPSEQT, the better queries tend to perform, at the expense of transactions.
The highest possible value for the hit ratio is 1.0, which is achieved when every page
requested is always in the buffer pool. The lowest hit ratio is when the requested
page is not in the buffer pool; in this case, the hit ratio is 0 or less. When the hit
ratio is negative, it means that prefetch has brought pages into the buffer pool that
are not subsequently referenced, either because the query stops before it reaches
the end of the table space, or because the prefetched pages are stolen by DB2 for
reuse before the query can access them.
Hit Ratios for Additional Processes: The hit ratio measurement becomes less
meaningful if additional processes, such as work files or utilities, are using the buffer
pool. Some utilities use a special type of getpage request that reserve an empty
buffer without requiring that the page be read from DASD.
For work files, there is always a hit as DB2 reads the empty buffer for the input to
sort, and then there is a read for the output. The hit ratio can be calculated if the
work files are isolated in their own buffer pools. If they are, then the number of
getpages used for the hit ratio formula is divided in half as follows:
Measure the looks and the reads with the DB2 Server .Calculate the hit ratio using
LPAGBUFF (the number of requests) and PAGEREAD (the number of misses). Divide
the hits (LPAGBUFF - PAGEREAD) by the number of looks (LPAGBUFF):
As a rule of thumb, anything below 90% is poor, and more buffers should be used.
Your hit ratio has improved if it has increased in value. You will be using less I/Os to
do the same processing. You should repeat this process until your hit ratio no longer
increases or until your system paging begins to increase.
Method 1:
You should increase your number of buffers by a small amount at a time and monitor
the change in hit ratio, repeating this until you find your peak hit ratio. If you
increase your buffers by a large number, you may exceed the optimal number of
buffers without knowing it. This is because you may see an increase in the hit ratio,
but you will not know if a smaller number of buffers would give you the same
increase in hit ratio. To be sure, you would need to start decreasing the number of
buffers to see if the hit ratio decreases. If it does not decrease, you may still have
more than the optimal number of buffers. If it does decrease, then you have less
than the optimal number of buffers. It is better to have slightly more than the
optimal number of buffers than slightly less and by increasing the number of buffers
by small increments, you will probably be able to determine the optimal number of
buffers more quickly.
Method 2:
An alternative is the following, knowing that more buffers will almost always reduce
database I/O:
Work out how much storage you can spend without hitting paging problems.
Give all that space to the database.
Define 500 directory buffers and give all the remaining space to page buffers.
NPAGBUF should be at least 1000 to take advantage of blocking (Multi-Block
*BLOCKIO in VM or Extended user buffering in VSE).
Monitor the COUNTER values for DASD I/O and calculate the buffer hit ratios.
Increase the directory buffers decreasing the page buffers until you get the best
results, monitoring as described in step 4. Add eight directory buffers for every
page buffer removed.
Decrease the page buffers until you notice that the results get worse. Thus you
determine how much buffer space you really exploit.
For processors dedicated to DB2, start with the default buffer pool sizes. You can
increase the buffer pool size as long as the number of I/Os continues to decrease, or
until paging becomes a problem. If your application uses random I/Os to access the
data, the number of I/Os might not decrease significantly unless the buffer pool is
larger than the table, and other applications require little concurrent buffer pool
usage.
Problems with Paging: When the buffer pool size requirements are excessive (real
storage plus expanded storage), the oldest buffer pool pages migrate to auxiliary
paging storage. Subsequent access to these pages results in a page fault. I/O must
bring the data into real storage. Paging of buffer pool storage impacts DB2
performance. The statistics for PAGE-INS REQUIRED FOR WRITE and PAGE-INS
REQUIRED FOR READ are useful in determining if the buffer pool size setting is too
large for available real storage.
Prevent I/O contention for the most frequently used DASD devices,
particularly the catalog tables and frequently referenced user tables
and indexes. In addition, a large buffer pool is beneficial when a DB2
sort is used during a query, because I/O contention on the devices
containing the work file table spaces is reduced.
Watch for Storage Paging: If the large buffer pool size results in excessive real
storage paging to expanded storage, consider using hiperpools.
Reasons to Choose More than One Buffer Pool: The following are some
advantages to having more than one buffer pool:
You can isolate data in separate buffer pools to favor certain
applications, data, and indexes.
For example, if you have large buffer pools, putting indexes into separate
pools from data might improve performance. You might want to put tables
and indexes that are updated frequently into a buffer pool with different
characteristics from those that are frequently accessed but infrequently
updated.
You can put work files into a separate buffer pool. This can provide
better performance for sort-intensive queries. Applications that use
temporary tables use work files for those temporary tables. Keeping
work files separate allows you to monitor temporary table activity
more easily.
This process of segregating different activities and data into separate buffer
pools has the advantage of providing good and relatively inexpensive
performance diagnosis data from statistics and accounting traces.
Since version 5, DB2 breaks up these queues into multiple LRU chains, resulting in
less overhead of queue management. The latch taken at head of queue is latched
less due to smaller queue size. Multiple subpools are created for a large virtual buffer
pool and threshold is controlled by DB2 and does not exceed 4000 VBP buffers in
each subpool. The LRU queue is managed within each of the each of the subpools in
order to reduce buffer-pool latch contention when concurrency is high. These buffers
are stolen in round-robin fashion through the subpools.
In version 6, a new page-stealing option was introduced with a new method of queue
management. FIFO can now be used instead of default of LRU. With this method,
oldest pages are always moved out. This decreases cost of doing GET-PAGE
operation and reduces internal latch contention for high concurrency. This should be
used only where there is little or no I/O and where table space or index is resident in
buffer pool. Separate buffer pools for LRU and FIFO objects can be set via ALTER
BUFFERPOOL command with a new PGSTEAL option for FIFO. LRU is the PGSTEAL
option default.
PAGES READ value by the PREFETCH I/O, you get 7.99. This is
because the prefetch quantity for sort work files is 8 pages. For
operations other than sorts, the prefetch quantity could be up to 32
pages, depending on the application. SYS PAGE UPDATES ( E )
corresponds to the number of buffer updates. SYS PAGES WRITTEN ( F
) is the number of pages written to DASD. DWT HIT ( G ) is the
number of times the deferred write threshold (DWQT) was reached.
This number is workload dependent.
VERTICAL DWT HIT ( H ) is the number of times the vertical deferred
write threshold (VDWQT) was reached. This value is per data set, and
it is related to the number of asynchronous writes.
If the number of synchronous read I/Os ( A ) and the number of sequential prefetch
I/Os ( C ) are relatively high, you would want to tune the buffer pools by changing
the buffer pool specifications. For example, you could make the buffer operations
more efficient by defining a hiperpool if you have expanded storage on your
machine. To do that, enter the following command:
To obtain buffer pool information on a specific data set, you can use the LSTATS
option of the DISPLAY BUFFERPOOL command. For example, you can use the
LSTATS option to Provide page count statistics for a certain index. With this
information, you could determine whether a query used the index in question, and
perhaps drop the index if it was not used. And also to Monitor the response times on
a particular data set. If you determine that I/O contention is occurring, you could
redistribute the data sets across your available DASD.
4.3.4 Exercise
Questions
1. List the different types of buffer pool thresholds
2. If you have 1000 getpages and 100 pages were read from trhe DASD then
what would be the hit ratio
Answers
1.Fixed thresholds: Immediate Write Threshold (IWTH) , Data Management
Threshold (DMTH) , Sequential Prefetch Threshold (SPTH)
Variable thresholds: Sequential Steal Threshold (VPSEQT) , Hiperpool Sequential
Steal Threshold (HPSEQT) , Virtual Buffer Pool Parallel Sequential Threshold
(VPPSEQT) , Virtual Buffer Pool Assisting Parallel Sequential Threshold
(VPXPSEQT) , Deferred Write Threshold (DWQT) , Vertical Deferred Write
Threshold (VDWQT)
2. ((1000-100)/1000 The hit ratio in this case is 0.9)
4.4.1 Introduction
The second of DB2’s four pools is the EDM pool. The EDM pool is used by DB2 to
control programs as they execute against DB2. It contains structures that house the
access paths of the SQL statements for running programs. The EDM pool also
contains database information (DBDs) for the databases being accessed. Managing
the size and efficiency of the EDM pool is vitally important because if there is no
room in the EDM pool, a critical application may not be allowed to run.
The EDM pool is also used to cache prepared dynamic SQL statements. Caching can
help when statements are recalled from memory, using far fewer resources than
statements that need to be prepared again. However, DB2 caches all prepared
dynamic statements, not just those that are used repetitively.
By designing the EDM pool this way, you can avoid allocation I/Os, which can
represent a significant part of the total number of I/Os for a transaction. You can
also reduce the processing time necessary to check whether users attempting to
execute a plan are authorized to do so.
An EDM pool that is too small causes: Increased I/O activity in DSNDB01.SCT02,
DSNDB01.SPT01, and DSNDB01.DBD01 Increased response times, due to loading
the SKCTs, SKPTs, and DBDs. If caching of dynamic SQL is used, and the needed
SQL statement is not in the EDM pool, that statement has to be re-prepared. Fewer
threads used concurrently, due to a lack of storage
An EDM pool that is too large might use more virtual storage than necessary.
Implications for Database Design: When you design your databases, be aware that a
very large number of objects in your database mean a larger DBD for that database.
And when you drop objects, storage is not automatically reclaimed in that DBD,
which can mean that DB2 must take more locks for the DBD. To reclaim storage in
the DBD, use the MODIFY utility. The DB2 statistics record provides information on
the EDM pool.
These ratios for the EDM pool depend upon your location’s workload. In most DB2
subsystems, a value of 5 or more is acceptable. This means that at least 80% of the
requests were satisfied without I/O. The number of free pages is shown in FREE
PAGES IN FREE CHAIN B in. If this value is more than 20% of PAGES IN EDM POOL A
during peak periods, the EDM pool size is probably too large. In this case, you can
reduce its size without affecting the efficiency ratios significantly. Calculating the
EDM Pool Hit Ratio for Cached Dynamic SQL: If you have caching turned on for
dynamic SQL, the EDM pool statistics have information that can help you determine
how successful your applications are at finding statements in the cache. See
mapping macro DSNDQISE for descriptions of these fields. QISEDSG records the
number of requests to search the cache. QISEDSI records the number of times that a
statement was inserted into the cache, which can be interpreted as the number of
times a statement was not found in the cache. Use the following calculation to
determine how often the dynamic statement was used from the cache:
4.4.3 Exercise
Questions
1. list down the problems that are caused when the EDM pool is small or large ?
2. What are the ratios which indicate the efficiency of the pool ?
Answers
1. Increased I/O activity in DSNDB01.SCT02, DSNDB01.SPT01, and
DSNDB01.DBD01, Increased response times, due to loading the SKCTs, SKPTs, and
DBDs, Fewer threads used concurrently, due to a lack of storage
2. CT REQUESTS/CT NOT IN EDM C , PT REQUESTS/PT NOT IN EDM D , DBD
REQUESTS/DBD NOT IN EDM
4.5.1 Introduction
The RID pool, third of the four pools, is used by DB2 to sort RIDs for List Prefetch,
Multiple Index Access and Hybrid Join access paths. RID pool failures can cause
performance degradation as alternate access paths are invoked, such as scans, and
the CPU invested up to the point of the failure is wasted.
RID pool storage is also used when DB2 enforces unique keys while updating
multiple rows. SQL statements that use those methods of access can benefit from
using the RID pool. RID pool processing can help reduce I/O resource consumption
and elapsed time. However, if there is not enough RID pool storage, it is possible
that the statement might revert to a table space scan. To determine if a transaction
used the RID pool, see the RID Pool Processing section of the DB2 PM accounting
trace record. The RID pool, which concurrent processes share, is limited to a
maximum of 1000MB. The RID pool is created at system initialization, but no space
is allocated until RID storage is needed. It is then allocated above the 16MB line in
16KB blocks as needed, until the maximum size you specified on installation panel
DSNTIPC is reached.
For example, three concurrent RID processing activities, with an average of 4000
RIDs each, would require 120KB of storage, because:
3 * 4000 * 2 * 5 = 120KB
Whether your SQL statements that use RID processing complete efficiently or not
depends on other concurrent work using the RID pool.
When the DSNTINST CLIST calculates the value for RID POOL SIZE on panel
DSNTIPC, the default is calculated as 50% of the sum of virtual buffer pools BP0,
BP1, BP2, and BP32K.
You can modify the maximum RID pool size that you specified on installation panel
DSNTIPC by using the installation panels in UPDATE mode, as follows:
To favor the selection and efficient completion of list prefetch, multiple index access,
or hybrid join, you can increase the maximum RID pool size.
To disable list prefetch, multiple index access, and hybrid join, specify a RID pool
size of 0.
If you do this, plans or packages that were previously bound with a non-zero RID
pool size might experience significant performance degradation. Rebind any plan or
package that include SQL statements that use RID processing.
4.5.3 Exercise
Questions
1. How much of storage three concurrent RID processing activities with an average
of 4000 RIDs each would require?
Answers
1. Ans : 3 * 4000 * 2 * 5 = 120KB
4.6.1 Introduction
Sort pool is used by DB2 to perform highly efficient internal sorts of data. Sort pool
performance degradations can impact elapsed times dramatically, and sort failures
can terminate a statement.
When the DSNTINST CLIST calculates the value for SORT POOL SIZE on panel
DSNTIPC, the default is calculated as 10% of the sum of virtual BP0, BP1, BP2, and
BP32K. The default is limited as follows:
MINIMUM = 240KB
MAXIMUM = 64000KB
You can change this value by using the installation panels in UPDATE mode. A rough
formula for determining the maximum sort pool size is as follows:
16000 * (12 + sort key length + sort data length + 4 (if hardware sort))
For sort key length and sort data length, use values that represent the maximum
values for the queries you run. To determine these values, refer to fields QW0096KL
(key length) and QW0096DL (data length) in IFCID 0096, as mapped by macro
DSNDQW01. You can also determine these values from an SQL activity trace.
and C1, C2, and C3 are each 10 bytes in length, for an MVS/ESA system you could
estimate the sort pool size as follows:
16000 * (12 + 4 + 10 + (10 + 10 + 10)) = 896000 bytes
The work files used in sort are logical work files, which reside in work file table
spaces in your work file database (which is DSNDB07 in a non data-sharing
environment). DB2 uses the buffer pool when writing to the logical work file. The
number of work files that can be used for sorting is limited only by the buffer pool
size when you have the sort assist hardware. If you do not have the sort hardware,
up to 140 logical work files can be allocated per sort, and up to 255 work files can be
allocated per user.
It is possible for a sort to complete in the buffer pool without I/Os. This is the ideal
situation, but it might be unlikely, especially if the amount of data being sorted is
large. The sort row size is actually made up of the columns being sorted (the sort
key length) and the columns the user selects (the sort data length). When your
application needs to sort data, the work files are allocated on a least recently used
basis for a particular sort. For example, if five logical work files (LWFs) are to be
used in the sort, and the installation has three work file table spaces (WFTSs)
allocated, then:
To support large sorts, DB2 can allocate a single logical work file to several physical
work file table spaces.
Allocate additional physical work files in excess of the defaults, and put those work
files in their own buffer pool. Segregating work file activity enables you to better
monitor and tune sort performance. It also allows DB2 to handle sorts more
efficiently because these buffers are available only for sort without interference from
other DB2 work. Applications using temporary tables use work file space until a
COMMIT or ROLLBACK occurs. (If a cursor is defined WITH HOLD, then the data is
held past the COMMIT.) If sorts are happening concurrently with the temporary
table's existence, then you probably need more space to handle the additional use of
the work files.
The size of the sort pool affects the performance of the sort. The larger the work
area, the more efficient is the sort. When the sort occurs, the sort row size depends
on the data fields that need to be sorted. Therefore, your applications should only
sort those columns that need to be sorted, as these key fields appear twice in the
sort row size. The smaller the sort row size, there are more rows that can fit.
VARCHARs are padded to their maximum length. Therefore, if VARCHAR columns are
not required, your application should not select them. This will reduce the sort row
size.
The better sorted the data is, the more efficient the sort will be. If the buffer pool
deferred write threshold (DWQT) or data set deferred write threshold (VDWQT) are
reached, writes are scheduled. For a large sort using many logical work files, this is
difficult to avoid, even if a very large buffer pool is specified.
If I/Os occur in the sorting process, in the merge phase DB2 uses sequential prefetch
to bring pages into the buffer pool with a prefetch quantity of one, two, four, or eight
pages. However, if the buffer pool is constrained, then prefetch could be disabled
because not enough pages are available.
If your DB2 subsystem is running on a processor that has the sort facility hardware
instructions, you will see an improvement in the performance of SQL statements that
contain any of the following: ORDER BY clause, GROUP BY clause, CREATE INDEX
statement, DISTINCT clause of subselect, and joins and queries that use sort.
For any SQL statement that initiates sort activity, the DB2 PM SQL activity reports
provide information on the efficiency of the sort involved.
4.6.5 Exercise
Questions:
1. If you wanted to run the following query:SELECT C1, C2, C3 FROM tablex ORDER
BY C1and C1, C2, and C3 are each 10 bytes in length, for an MVS/ESA system
estimate the sort pool size.
Answers:
1.
16000 * (12 + 4 + 10 + (10 + 10 + 10)) = 896000 bytes
where: 16000 = maximum number of sort nodes
12 = size (in bytes) of each node
4 = number of bytes added for each node if
sort facility hardware used
10 = sort key length (ORDER BY C1)
10+10+10 = sort data length (each column is 10 bytes in length)
4.7.1 Introduction
The DB2 directory contains information required to start DB2, and DB2 uses the
directory during normal operation. You cannot access the directory using SQL. The
structures in the directory are not described in the DB2 catalog.
The directory consists of a set of DB2 tables stored in five table spaces in system
database DSNDB01. Each of the following table spaces is contained in a VSAM linear
data set:
SCT02 is the skeleton cursor table space (SKCT).
SPT01 is the skeleton package table space.
SYSLGRNX is the log range table space.
SYSUTILX is the system utilities table space.
DBD01 is the database descriptor (DBD) table space.
Skeleton Cursor Table: The skeleton cursor table space (SCT02) contains a table
that describes the internal form of SQL statements of application programs. When
you bind a plan, DB2 creates a skeleton cursor table in SCT02. The index space for
the skeleton cursor table is DSNSCT02.
Skeleton Package Table: The skeleton package table space (SPT01) contains a
table that describes the internal form of SQL statements in application programs.
When you bind a package, DB2 creates a skeleton package table in SPT01. The index
spaces for the skeleton package table are DSNSPT01 and DSNSPT02.
Log Range: DB2 inserts a row in the log range table space (SYSLGRNX) every time
a table space or partition is opened and updated, and it updates SYSLGRNX
whenever that structure is closed. The row contains the opening log relative byte
address (RBA), the closing log RBA, or both for the structure. The log RBA is the
relative byte address in the log data set where open and close information about the
structure is contained. The use of SYSLGRNX speeds up recovery by limiting the log
information that must be scanned to apply changes to a table space or partition
being recovered.
The two indexes defined on SYSLGRNX are DSNLLX01 (a clustered index) and
DSNLLX02.
System Utilities: DB2 inserts a row in the system utilities table space (SYSUTILX)
for every utility job that is run. The row remains there until the utility completes its
full processing. If the utility terminates without completing, DB2 uses the information
in the row to restart the utility. The indexes defined on SYSUTILX are DSNLUX01 and
DSNLUX02.
4.7.3 Exercise
Questions
1. List down the contents of the DB2 directory.
Answers
1. SCT02 is the skeleton cursor table space (SKCT), SPT01 is the skeleton
package table space, SYSLGRNX is the log range table space, SYSUTILX is
the system utilities table space, DBD01 is the database descriptor (DBD)
table space
4.8.1 Introduction
The DB2 catalog consists of tables of data about everything defined to the DB2
system. The DB2 catalog is contained in system database DSNDB06. When you
create, alter, or drop any structure, DB2 inserts, updates, or deletes rows of the
catalog that describe the structure and tell how the structure relates to other
structures .For Version 5, the communications database (CDB) is moved into the
catalog.
4.8.2 Examples
DB2 has extensive support to help move your applications into the next millennium.
The Version 5 catalog supports timestamps generated both before and after the year
2000. To illustrate the use of the catalog, here is a brief description of some of what
happens when the employee table is created:
To record the name of the structure, its owner, its creator, its type (alias,
table, or view), the name of its table space, and the name of its database,
DB2 inserts a row into the catalog table SYSIBM.SYSTABLES.
To record the name of the table to which the column belongs, its length, its
data type, and its sequence number in the table, DB2 inserts rows into
SYSIBM.SYSCOLUMNS for each column of the table.
To increase by one the number of tables in the table space DSN8S51E, DB2
updates the row in the catalog table SYSIBM.SYSTABLESPACE.
To record that the owner (DSN8510) of the table has all privileges on the
table, DB2 inserts a row into table SYSIBM.SYSTABAUTH.
Because the catalog consists of DB2 tables in a DB2 database, you can use
SQL statements to retrieve information from it. There are many more catalog
tables with the creator as SYSIBM. For more information on these catalog
tables the SQL reference manual can be referred.
4.8.3 Exercise
Questions:
1. How can we find out the storage group on which a particular table resides?
2. List the catalog tables for finding out the plan and package privileges?
3. How do we find the keys (primary) of a table?
Answers:
1. From the SYSIBM.SYSTABLESPACE
2. From SYSIBM.SYSPLANAUTH
3. From the SYSIBM.SYSINDEXES and SYSIBM.SYSKEYS
1. What are the various tools available for tuning buffer pools and EDM pools and
how are they effective for performance tuning?
4.10 Reference
www.ibm.com
IBM Redbook - Storage Management with DB2 for OS/390 SG24-5462-00
UNIT - V
5. Locking, IRLM and Concurrency
5.1 Unit Objectives
This unit is meant to provide the aspiring DBA’s with an in-depth knowledge on DB2
LOCKING and its management. It also speaks about the various system and
application parameters that affect DB2 locking, and how to use the various resources
available properly to provide maximum value addition to the database system.
5.2 Introduction
In this chapter, we are going to see what are the different types of locks available,
how they are implemented by DB2, and the criteria of choosing the locking options.
We shall also have a look at the different problems normally associated with locks,
and how to tackle them.
The internal resource lock manager (IRLM) subsystem manages DB2 locks. The
particular IRLM to which DB2 is connected is specified in DB2's load module for
subsystem parameters. It is also identified as an MVS subsystem in the
SYS1.PARMLIB member IEFSSNxx. That name is used as the IRLM procedure name
(irlmproc) in MVS commands.
Often DB2 handles the locking itself. This type of call is called a latch. Since this
eliminates the cross-memory service calls to the IRLM, and avoids the overhead of
calling an external address space, latches are more efficient than locks, and requires
about one-third the amount of instructions needed for locks. These are mainly used
to lock index pages and internal DB2 resources, and also to lock data pages for very
small durations.
The internal resource lock manager (IRLM) subsystem manages DB2 locks. The
particular IRLM to which DB2 is connected is specified in DB2's load module for
subsystem parameters. It is also identified as an MVS subsystem in the
SYS1.PARMLIB member IEFSSNxx. That name is used as the IRLM procedure name
(irlmproc) in MVS commands.
Data Sharing: In a data sharing environment, the IRLM handles global locking, and
each DB2 member has its own corresponding IRLM. See Data Sharing: Planning and
Administration for more information about configuring IRLM in a data sharing
environment.
The following MVS commands can be used to monitor and control the IRLM:
MODIFY irlmproc,ABEND,DUMP
Abends the IRLM and generates a dump.
MODIFY irlmproc,ABEND,NODUMP
Abends the IRLM but does not generate a dump.
MODIFY irlmproc,DIAG,DELAY
Initiates diagnostic dumps for IRLM subsystems in a data sharing group when there is
a delay in the child-lock propagation process.
MODIFY irlmproc,SET
Sets dynamically the maximum amount of CSA storage or the number of trace
buffers used for this IRLM.
MODIFY irlmproc,SET,CSA=nnn
Sets dynamically the maximum amount of CSA storage that this IRLM can use for
lock control structures.
MODIFY irlmproc,SET,TRACE=nnn
Sets dynamically the maximum number of trace buffers used for this IRLM.
MODIFY irlmproc,STATUS
Displays the status for the subsystems on this IRLM.
MODIFY irlmproc,STATUS,irlmx
Displays the status of a specific IRLM.
MODIFY irlmproc,STATUS,ALLD
Displays the status of all subsystems known to this IRLM in the data sharing group.
MODIFY irlmproc,STATUS,ALLI
Displays the status of all IRLMs known to this IRLM in the data sharing group.
MODIFY irlmproc,STATUS,STOR
Displays the current and "high water" allocation for CSA and ECSA storage.
MODIFY irlmproc,STATUS,TRACE
Displays information about trace types of IRLM subcomponents.
START irlmproc
Starts the IRLM.
STOP irlmproc
Stops the IRLM normally.
TRACE CT,OFF,COMP=irlmx
Stops IRLM tracing.
TRACE CT,ON,COMP=irlmx
Starts IRLM tracing for all subtypes (DBM,SLM,XIT,XCF)
TRACE CT,ON,COMP=irlmx,SUB=(subname)
Starts IRLM tracing for a single subtype.
When DB2 is installed, you normally specify that the IRLM be started automatically.
Then, if the IRLM is not available when DB2 is started, DB2 starts it, and periodically
checks whether it is up before attempting to connect. If the attempt to start the
IRLM fails, DB2 terminates.
If an automatic IRLM start has not been specified, start the IRLM before starting
DB2, using the MVS START irlmproc command.
When started, the IRLM issues this message to the MVS console:
Consider starting the IRLM manually if you are having problems starting DB2 for
either of these reasons:
When you start the IRLM manually, you can generate a dump to collect diagnostic
information.
MODIFY irlmproc,STATUS
If you try to stop the IRLM while DB2 or IMS is still using it, the following message
appears:
If that happens, issue the STOP irlmproc command again, when the subsystems are
finished with the IRLM.
Or, if you must stop the IRLM immediately, enter the following command to force the
stop:
MODIFY irlmproc,ABEND
DB2 abends. An IMS subsystem using the IRLM does not abend, and can be
reconnected.
IRLM does exploit the MVS Automatic Restart Manager (ARM) services. However, it
de-registers from ARM for normal shutdowns. IRLM registers with ARM during
initialization and provides ARM with an event exit. The event exit must be in linklist.
It is part of the IRLM DXRRL183 load module. The event exit will make sure that the
IRLM name is defined to MVS when ARM restarts IRLM on a target MVS that is
different from the failing MVS. The IRLM element name used for the ARM registration
depends on the IRLM mode. For local mode IRLM, the element name is a
concatenation of the IRLM subsystem name and the IRLM ID. For global mode IRLM,
the element name is a concatenation of the IRLM data sharing group name, IRLM
subsystem name, and the IRLM ID.
# a STOP command
# auto-stop of IRLM.
Use the MODIFY command listed above to FORCE the DMBSs using the IRLM down
and stop IRLM without having it automatically restarted by ARM. IRLM will de-
register DB2 from ARM before DB2 abends to prevent ARM from restarting DB2 and
IRLM if using the auto-start feature.
5.4.1.1 S (SHARE)
The lock owner and any concurrent processes can read, but not change, the locked
page or row. Concurrent processes can acquire S or U locks on the page or row or
might read data without acquiring a page or row lock.
5.4.1.2 U (UPDATE)
The lock owner can read, but not change, the locked page or row. Concurrent
processes can acquire S locks or might read data without acquiring a page or row
lock, but no concurrent process can acquire a U lock.
U locks reduce the chance of deadlocks when the lock owner is reading a page or row
to determine whether to change it, because the owner can start with the U lock and
then promote the lock to an X lock to change the page or row.
5.4.1.3 X (EXCLUSIVE)
The lock owner can read or change the locked page or row. A concurrent process can
access the data if the process runs with UR isolation. (A concurrent process that is
bound with cursor stability and CURRENTDATA(NO) can also read X-locked data if
DB2 can tell that the data is committed.)
5.4.2.3 S (SHARE)
The lock owner and any concurrent processes can read, but not change, data in the
table, partition, or table space. The lock owner does not need page or row locks on
data it reads.
5.4.2.4 U (UPDATE)
The lock owner can read, but not change, the locked data; however, the owner can
promote the lock to an X lock and then can change the data. Processes concurrent
with the U lock can acquire S locks and read the data, but no concurrent process can
acquire a U lock. The lock owner does not need page or row locks.
U locks reduce the chance of deadlocks when the lock owner is reading data to
determine whether to change it. U locks are acquired on a table space when locksize
is TABLESPACE and the statement is SELECT FOR UPDATE OF. Similarly, U locks are
acquired on a table when lock size is TABLE and the statement is SELECT FOR
UPDATE OF.
5.4.2.6 X (EXCLUSIVE)
The lock owner can read or change data in the table, partition, or table space. A
concurrent process can access the data if the process runs with UR isolation or if
data in a LOCKPART (YES) table space is running with CS isolation and
CURRENTDATA (NO). The lock owner does not need page or row locks.
If the state of one lock placed on a data resource enables another lock to be placed
on the same resource, the two locks (or states) are said to be compatible. Whenever
one transaction holds a lock on data resource and a second transaction requests a
lock on the same resource, DB2 examines the two lock states to determine whether
they are compatible. If the locks are compatible, the lock is granted to the second
transaction (as long as no other transaction is waiting for the data resource). If the
locks are incompatible, however, the second transaction must wait until the first
transaction releases its lock. In fact, the second transaction must wait until all
existing incompatible locks are released.
Appendix C shows the compatibility matrices for page and tablespace locks.
5.4.3 Exercise
1. Latches are managed by IRLM. True/False?
2. If transaction A holds a U lock on a page, transaction B can acquire a S lock
on the same. True/False?
Answers:
1. False
2. True
Lock conversion / Lock promotion is the action of exchanging one lock on a resource
for a more restrictive lock on the same resource, held by the same application
process.
When a transaction accesses a data resource on which the transaction already holds
a lock, and the mode of access requires a more restrictive lock than the one the
transaction already holds, the state of the lock is changed to the more restrictive
state. The operation of changing the state of a lock already held to a more restrictive
state is called Lock conversion / Lock Promotion. Lock conversion occurs because a
transaction can hold one lock on a data resource at a time.
Effects: When promoting the lock, DB2 first waits until any incompatible locks held
by other processes are released. When locks are promoted, it is in the direction of
increasing control over resources: from IS to IX, S, or X; from IX to SIX or X; from S
to X; from U to X; and from SIX to X.
5.6 Suspension
Order of precedence for lock requests: Incoming lock requests are queued.
Requests for lock promotion, and requests for a lock by an application process that
already holds a lock on the same object, precede requests for locks by new
applications. Within those groups, the request order is "first in, first out."
Example: Using an application for inventory control, two users attempt to reduce
the quantity on hand of the same item at the same time. The two lock requests are
queued. The second request in the queue is suspended and waits until the first
request releases its lock.
The time during which a lock in maintained in DB2 is called Lock Duration. This has a
tremendous effect on the various aspects of an application – performance, integrity,
concurrency etc. This is mostly controlled by the BIND option of the plan or the
package (refer to Appendix B).
ACQUIRE (ALLOCATE) option specifies that the lock will be acquired at the time the
plan is allocated, i.e. the first SQL is executed. The merit of this option is that all the
resources required are allocated to the transaction at once and hence, at any point
during execution, the transaction does not need to worry about the availibity of the
resources. The demerit is that, this might lead to longer wait times for other jobs /
transaction which might require the same resources. ACQUIRE (USE) indicates that
the locks will be acquired only at the time of the execution of the SQL. This increases
the chance of deadlock / timeout, but gives better concurrency, and is preferred in a
multi-user environment.
The default option for DB2 (in case no parameter is mentioned) is ACQUIRE (USE).
RELEASE (DEALLOCATE) indicates that the locks would be released after the plan is
terminated. This also gives a better performance in case of a stand-alone job /
transaction. RELEASE (COMMIT) releases all locks after a syncpoint (COMMIT or
ROLLBACK) is issued. This is preferred for a multi-user environment.
The default option for DB2 (in case no parameter is mentioned) is RELEASE
(COMMIT).
5.7.3 ISOLATION
This is a very important parameter, which significantly affects how a program
processes page locks. Obviously this acts as a page level. This parameter specifies
the isolation level of a package or a plan by controlling the mode of page locking
implemented by the program when it runs.
Even if a program is bound with any other option, this can be overrirrden at an SQL
level by mentioning the WITH UR option, as demonstrated below.
This option gives a good concurrency and performance, but data integrity is risked
with this option. It is advisable not to use this when accurate data is necessary for
the transaction. However, this can be used in the following kind of applications:
This gives highest level of data integrity, but is associated with concurrency and
performance issues. Also has a potential of lock escalation. This is normally not used
in a busy multi-user environment. However, when the audience of the database is
limited and data integrity is of utmost importance, this might be preferred. Also, this
might be considered when a particular transaction / job has the possibilty of reading
the same pages more than once, for the sake of data integrity.
potentially be read twice. However, such situations are rare and CS is the favourite
ISOLATION option among most of trhe DBAs.
5.7.4 CURRENTDATA
The CURRENTDATA option has different effects, depending on if access is local or
remote:
For local access, the option tells whether the data upon which your cursor
is positioned must remain identical to (or "current with") the data in the
local base table. For cursors positioned on data in a work file, the
CURRENTDATA option has no effect. This effect only applies to read-only
or ambiguous cursors in plans or packages bound with CS isolation.
Local access: Locally, CURRENTDATA(YES) means that the data upon which the
cursor is positioned cannot change while the cursor is positioned on it. If the cursor
is positioned on data in a local base table or index, then the data returned with the
cursor is current with the contents of that table or index. If the cursor is positioned
on data in a work file, the data returned with the cursor is current only with the
contents of the work file; it is not necessarily current with the contents of the
underlying table or index.
As with work files, if a cursor uses query parallelism, data is not necessarily current
with the contents of the table or index, regardless of whether a work file is used.
Therefore, for work file access or for parallelism on read-only queries, the
CURRENTDATA option has no effect.
If parallelism is required along with maintenance of currency with the data, the
following options can be explored:
Figure 1: How an application using isolation CS with CURRENTDATA (YES) acquires locks. This
figure shows access to the base table. The L2 and L4 locks are released after DB2 moves to the
next row or page. When the application commits, the last lock is released.
To take the best advantage of this method of avoiding locks, the DBA should
make sure all applications that are accessing data concurrently issue
COMMITs frequently.
Figure 2 shows how DB2 can avoid taking locks and Figure 3 summarizes the
factors that influence lock avoidance.
Figure 2: Best case of avoiding locks using CS isolation with CURRENTDATA(NO). This figure
shows access to the base table. If DB2 must take a lock, then locks are released when DB2
moves to the next row or page, or when the application commits (the same as
CURRENTDATA(YES)).
Figure 3: Lock avoidance factors. "Returned data" means data that satisfies the predicate.
"Rejected data" is that which does not satisfy the predicate.
5.7.5 Exercise
1. When Transaction A holds an S lock on a particular page, and then it needs
to update one row in the page, a process comes into picture called
a) Lock Escalation
b) Lock Promotion
c) Deadlock
d) Timeout
2. A suspended process gets activated when the transaction holding the lock
on the page releases the lock. True/False?
Answers:
1. b
2. True
5.8 Locksize
Locks can be of various sizes – Row, Page, Table and Tablespace, giving different
levels of concurrency. Here the trade-off is between concurrency and amount of
resources to be allocated to the lock.
The size of a lock is determined by the LOCKSIZE parameter in the DDL of the
object. The DB2 default is LOCKSIZE ANY, which allows DB2 to choose a lock of its
choice, by looking at the request, at the time of execution. However, this can be
overridden by mentioning LOCKSIZE ROW or LOCKSIZE PAGE, depending on the
need of the application.
Page locks can be promoted from one type to another based on the processing
taking place. For example, when a FOR UPDATE cursor is fetched for a row, a U lock
is taken on the page. When the actual update takes place, the U lock is promoted to
the X lock.
Row level locks are taken when LOCKSIZE ROW is mentioned in the DDL. LOCKSIZE
ANY can also theoretically give rise to this kind of lock, but the possibility of this
happening is very small.
The lock compatibility matrix for Row locking is the same as that for Page locking.
If the application needs very high level of concurrency, then LOCKSIZE ROW may be
preferred as this allows a program to read / update a row while another row in the
same page is locked by some other transaction. But it is to be kept in mind that
LOCKSIZE ROW assumes far more amount of resources compared to LOCKSIZE
PAGE, and this can lead to degradation of performance as well.
Also, in certain cases, where the same data is read in different orders by two
transactions, running at the same time, row lock can actually increase the contention
level as each of the transactions may keep one row in the same page locked, which
is required by the other transaction.
In general, if there is no particular demand from the application size for a particular
lock size, it seems wise to leave the decision on DB2 by mentioning LOCKSIZE ANY
in the DDL.
Note: LOCKSIZE PAGE or LOCKSIZE ROW can be used more efficiently when you
commit your data more frequently or when you use cursor stability with
CURRENTDATA NO.
MAXROWS = 1 indicates that only one row can exist per page for that particular
tablespace.
This provides the same level of concurrency as Row-level locking. However, this can
create overallocation of space as only one row can reside in a page. But still, it is
preferred to Row-level locking in certain cases as in a data sharing environment,
row-level locking can lead to the propagation of a lot of additional page p-locks to
the XCF (Extended Coupling Facility).
The MAXROWS parameter can be altered for a tablespace, and this is takes effect
immediately. However, a REORG should be done after doing this kind of alteration.
5.8.7 Lockmax
This tablespace DDL parameter specifies the maximum numnber of page or row locks
that a single application process can hold on the tablespace before lock escalation
takes place.
The DBA can mention one of the three values for this parameter:
LOCKMAX <n>: Maximum n number of locks can be held by a single application
process on the tablespace.
LOCKMAX SYSTEM: Specifies that n is effectively equal to the system default set by
the field LOCKS PER TABLE(SPACE) of installation panel DSNTIPJ.
LOCKMAX 0: Disables lock escalation entirely.
The default value for this parameter depends on the LOCKSIZE parameter, as
follows:
LOCKSIZE ANY -> LOCKMAX SYSTEM
LOCKSIZE any other value -> LOCKMAX 0
lock escalations are also not sufficient to free enough space for the transaction to
continue, the transaction is asked to issue a COMMIT / ROLLBACK.
Lock escalation takes place when a limit is encountered by the transaction. However,
this limit can be at the system level also, caused by some other transaction. Say,
transaction A has taken a lot of locks on the tablespace T1, and the transaction B has
taken only a few locks. Now the number of locks reaches its limit at the system level,
though the limit might not have reached for the individual transactions. In such a
case, one of the transactions will be asked to escalate its locks. If B, which is holding
only a few locks, is asked to do so, it might attempt the same, fail to do so, and
terminate abnormally, while the main offending transaction was A. Thus, offending
transactions holding many locks over a long period of time can cause other
transactions to terminate abnormally.
The statistics and accounting trace records contain information on locking. The IBM
licensed program, DATABASE 2 Performance Monitor (DB2 PM), provides one way to
view the trace results.
Statistics Trace tells how many suspensions, deadlocks, timeouts, and lock
escalations occur in the trace record.
Accounting Trace gives the same information for a particular application. It also
shows the maximum number of concurrent page locks held and acquired during the
trace. Review applications with a large number to see if this value can be lowered.
This number is the basis for the proper setting of LOCKS PER USER and, indirectly,
LOCKS PER TABLE(SPACE).
For Simple tablespaces, where the rows corresponding to different tables reside in
same pages, a row or a page lock is escalated directly to a tablespace lock, which
locks all the tables in the tablespace.
For Segmented tablespaces, where rows from different tables reside in different
pages, row / page locks are escalated to the individual table level, allowing other
applications to access data from other tables of the same tablespace.
Figure 4 shows the difference in lock escalations for different types of tablespaces.
Tablespace
Table Partitione
containing
d
all tables
tablespac
5.8.9 Exercise
1. Which field in the catalog mentions the size of the lock to be taken?
2. Page lock gives higher level of concurrency than row lock. True / false?
3. Lock Escalation takes place in order to save resources. True / False?
4. What is the field that contains maximum number of locks to be taken, before lock
escalation?
Answers:
1. LOCKRULE of SYSIBM.SYSTABLESPACE
2. False
3. True
4. LOCKMAX
As of DB2 V3, resource serialization has been augmented to include claims and
drains in addition to transaction locking. The claim and drain process enables DB2 to
perform concurrent operations on multiple partitions on the same tablespace.
Claims and drains provide a new “locking” mechanism to control concurrency for
resources between SQL statements, utilities and commands. As with transaction
locks, claims and drains can time out while waiting for a resource.
5.9.1 Claims
DB2 uses a claim to register that a resource is being accessed. They can be
considered as usage indicators. The following resources can be claimed:
Simple tablespaces
Segmented tablespaces
A single data partition of a partitioned tablespace
A non-partitioned index space
A single index partition of a partitioned index
Claims prevent drains from acquiring a resource. A claim is acquired when a resource
is first accessed. This is true regardless of the ACQUIRE parameter specified (USE or
ALLOCATE). Claims are reelased at commit time, except for cursors declared using
the WITH HOLD clause or when the claimer is a utility.
Multiple agents can claim a single resource. Claims on objects are acquired by the
following:
SQL statements (SELECT, INSERT, UPDATE, DELETE)
DB2 restart on INDOUBT objects
Some utilities (e.g. COPY SHRLEVEL CHANGE, RUNSTATS SHRLEVEL CHANGE
and REPORT)
5.9.2 Drains
Drain is the act of acquiring a locked resource by quiescing access to that object.
Like claims, drains are also acquired when a resource is first accessed. A drain
acquires a resource by quiescing claims against that resource. Drains can be
requested by commands and utilities.
Multiple drainers can access a single resource. However, a process that drains all
claim classes cannot drain an object concurrently with any other process.
The process of quiescing a claim class and prohibiting new claims from being
acquired for the resource is called draining. Draining allows DB2 utilities and
commands to acquire partial or full control of a specific object with a minimal impact
on concurrent access.
A drain lock also prevents new claimers from accessing an object while a drainer has
control of it.
5.9.2.1.1Types of Drain Locks
Three types of drain locks on an object correspond to the three claim classes:
Write
Repeatable read
Cursor stability read
A drain requires either partial control of a resource, in which case a write drain lock
is taken, or complete control of a resource, accomplished by placing a CS drain lock,
an RR drain lock, and a write drain lock on an object.
In general, after an initial claim has been made on an object by a user, no other user
in the system needs a drain lock. When the drain lock is granted, no drains on the
object are in process for the claim class needed, and the claimer can proceed.
Drain locks are released when the utility or command completes. When the resource
has been drained of all appropriate claim classes, the drainer acquires sole access to
the resource.
I) Acquiring the drain lock. If another user holds the needed drain lock in an
incompatible lock mode, then the drainer waits.
II) Releasing all claims on the object. Even after the drain lock is acquired, the
drainer waits until all claims are released before beginning to process.
If the process drains more than one claim class, it must wait for those events to
occur for each claim class it drains.
Locking in DB2 is a very efficient mechanism, and can do wonders if used properly.
The implementation of locks is a very important part of a database set-up, and
extreme care should be taken while doing this. For a proper implementation of locks,
a DBA not only needs to know about how DB2 functions, and the databasew, but also
needs a very good understanding about the application from the database usage
perspective.
5.10.1Deadlock
When two or more transactions are contending for locks, a situation called deadlock
can occur. The example in figure 5 illustrates the scenario.
Because at least two transactions are involved in a deadlock cycle, one might
assume that two data objects are always involved in the deadlock. However, this is
not true. A certain type of deadlock, known as conversion deadlock, can occur on a
single data object. A conversion deadlock occurs when when two or more
transactions already hold compatible locks on an object, and then each transaction
requests new, incompatible lock modes on that same object. This often takes place
on index pages.
the detector selects one of the transactions in the cycle to roll back and terminate
with an SQLCODE of -911, releasing all its locks.
DB2 trace record IFCID 172 (statistics class 3) contains information about deadlock.
The DB2 PM report Locking Trace formats this information to outline all the resources
and agents involved in a deadlock and the significant locking parameters, such as
lock state and duration, related to their requests, for a given interval of time. Also,
an accompanying message DSNT375I helps identify the members on which deadlock
has been encountered.
Setting the proper Deadlock Time (interval for the deadlock detector) in the database
configuration file is necessary to ensure a good concurrent application performance.
An interval that is too short will cause unnecessary overhead, and an interval that is
too long will enable a deadlock cycle to delay a process for an unacceptable amount
of time. One must balance the possible delays in resolving deadlocks with the
overhead of detecting the possible delays.
5.10.1.4.2 Access data in a consistent order:
When different applications access the same data, attempt should be made to make
them do so in the same sequence. For example, one should make both access rows
1,2,3,5 in that order. In that case, the first application to access the data delays the
second, but the two applications cannot deadlock. For the same reason, one should
try to make different applications access the same tables in the same order.
5.10.1.4.3 Commit work as soon as is practical
To avoid unnecessary lock contentions, one should issue a COMMIT statement as
soon as possible after reaching a point of consistency, even in read-only applications.
To prevent unsuccessful SQL statements (such as PREPARE) from holding locks,
issue a ROLLBACK statement after a failure. The SPUFI autocommit feature can
commit statement issued through SPUFI immediately.
Taking commit points frequently in a long running unit of recovery (UR) has the
following benefits:
One should consider using the UR CHECK FREQ field or the UR LOG WRITE CHECK
field of installation panel DSNTIPN to help you identify those applications that are not
committing frequently. UR CHECK FREQ, which identifies when too many checkpoints
have occurred without a UR issuing a commit, is helpful in monitoring overall system
activity. UR LOG WRITE CHECK enables one to detect applications that might write
too many log records between commit points, potentially creating a lengthy recovery
situation for critical tables.
Even though an application might conform to the commit frequency standards of the
installation under normal operational conditions, variation can occur based on system
workload fluctuations. For example, a low-priority application might issue a commit
frequently on a system that is lightly loaded. However, under a heavy system load,
the use of the CPU by the application may be pre-empted, and, as a result, the
application may violate the rule set by the UR CHECK FREQ parameter. For this
reason, one should add logic to one’s application to commit based on time elapsed
since last commit, and not solely based on the amount of SQL processing performed.
In addition, take frequent commit points in a long running unit of work that is read-
only to reduce lock contention and to provide opportunities for utilities, such as
online REORG, to access the data.
Packages are always bound with ACQUIRE (USE), by default. ACQUIRE (ALLOCATE)
can provide better protection against timeouts. One should consider ACQUIRE
(ALLOCATE) for applications that need gross locks instead of intent locks or that run
with other applications that may request gross locks instead of intent locks.
Acquiring the locks at plan allocation also prevents any one transaction in the
application from incurring the cost of acquiring the table and table space locks. If one
needs ACQUIRE (ALLOCATE), one might want to bind all DBRMs directly to the plan.
5.10.1.4.7 Use ISOLATION (CS) and CURRENTDATA(NO)
ISOLATION (CS) lets DB2 release acquired row and page locks as soon as possible.
CURRENTDATA (NO) lets DB2 avoid acquiring row and page locks as often as
possible. After that, in order of decreasing preference for concurrency, these bind
options should be used:
ISOLATION (CS) with CURRENTDATA (YES), when data returned to the application
must not be changed before the next FETCH operation.
ISOLATION (RS), when data returned to the application must not be changed before
the application commits or rolls back. However, one does not care if other application
processes insert additional rows.
ISOLATION (RR), when data evaluated as the result of a query must not be changed
before the application commits or rolls back. New rows cannot be inserted into the
answer set.
For updateable scrollable cursors, ISOLATION (CS) provides the additional advantage
of letting DB2 use optimistic concurrency control to further reduce the amount of
time that locks are held.
5.10.1.4.8 Use ISOLATION (UR) cautiously
UR isolation acquires almost no locks on rows or pages. It is fast and causes little
contention, but it reads uncommitted data. Do not use it unless you are sure that
your applications and end users can accept the logical inconsistencies that can occur.
Attempts to update a partitioning key may deadlock or timeout because of the same
restrictions on claim/drain processing.
LOCK TABLE may deadlock or timeout across the branches of a global transaction.
5.10.2Resource Timeout
The cancellation applies only to active threads. If the installation permits distributed
threads to be inactive and hold no resources, those threads are allowed to remain
idle indefinitely.
Default: 0. That value disables the scan to time out idle threads. The threads can
then remain idle indefinitely.
5.10.4Utility Timeout
In most cases, it is not practical to have the timeout for an utility the same as that
for an SQL application. Utility Timeout is controlled by a parameter, UTIMOUT, to be
specified on installation panel DSNTIPI, which acts as an operation multiplier for
utilities waiting for a drain lock, for a transaction lock, or for claims to be released.
Default value: 6.
If the lock suspension time for all DB2 programs is greater than 1% of
total elapsed execution time for the programs, then the application is
waiting too long for locks. One needs to get down to the individual
program level to determine the root cause.
These numbers can be obtained an accounting or statistics report and from the
lock suspension report in DB2PM.
5.10.6Monitoring Locking
DB2 provides a lot of features to monitor the locking as well as the IRLM connection.
MODIFY irlmproc,STATUS,irlmnm
Displays the status of a specific IRLM.
MODIFY irlmproc,STATUS,ALLD
Displays the status of all subsystems known to this IRLM in the data sharing
group.
MODIFY irlmproc,STATUS,ALLI
Displays the status of all IRLMs known to this IRLM in the data sharing group.
# MODIFY irlmproc,STATUS,MAINT
Displays the maintenance levels of IRLM load # module CSECTs for the specified
IRLM instance.
MODIFY irlmproc,STATUS,STOR
Displays the current and high water allocation for CSA and ECSA storage.
MODIFY irlmproc,STATUS,TRACE
Displays information about trace types of IRLM subcomponents.
If applicable, the output also includes information about physical I/O errors for those
objects. The use is as follows:
11:44:32 DSNT397I -
indicates which options were included when the DISPLAY DATABASE command
was issued.
dbname is an 8-byte character string indicating the database name. The pattern-
matching character, *, is allowed at the beginning, middle, and end of dbname.
DATABASE (*S*DB*) displays databases that begin with any letter, have the letter S
followed by any letters, then the letters DB followed by any letters.
ONLY restricts the display to databases names that fit the criteria.
The ADVISORY option on the DISPLAY DATABASE command can be used to limit the
display to table spaces or indexes that require some corrective action. The DISPLAY
DATABASE ADVISORY command without the RESTRICT option can be used to
determine when:
The EXPLAIN statement, or the EXPLAIN option of the BIND and REBIND
subcommands, can be used to determine which modes of table and table space
locks DB2 initially assigns for an SQL statement.
EXPLAIN stores its results in a table called PLAN_TABLE. To review the results,
query PLAN_TABLE. After running EXPLAIN, each row of PLAN_TABLE describes
the processing for a single table, either one named explicitly in the SQL
statement that is being explained or an intermediate table that DB2 has to
create. The column TSLOCKMODE of PLAN_TABLE shows an initial lock mode for
that table. The lock mode applies to the table or the table space, depending on
the value of LOCKSIZE and whether the table space is segmented or
nonsegmented.
In Figure 8, one can find what table or table space lock is used and whether page
or row locks are used also, for the particular combination of lock mode and
LOCKSIZE one are interested in.
For statements executed remotely: EXPLAIN gathers information only about data
access in the DBMS where the statement is run or the bind operation is carried out.
To analyze the locks obtained at a remote DB2 location, one must run EXPLAIN at
that location.
___________________________________ ____________________________________
| | Lock mode from EXPLAIN |
| |_______ ______ _______ ______ ______|
| Table space structure | IS | S | IX | U | X |
|___________________________________|_______|______|_______|______|______|
| For nonsegmented table spaces: | | | | | |
| Table space lock acquired is: | IS | S | IX | U | X |
| Page or row locks acquired? | Yes | No | Yes | No | No |
|___________________________________|_______|______|_______|______|______|
| Note: For partitioned table spaces defined with LOCKPART YES and for |
| which selective partition locking is used, the lock mode |
| applies only to those partitions that are locked. Lock modes |
| for LOB table spaces are not reported with EXPLAIN. |
|___________________________________ _______ ______ _______ ______ ______|
| For segmented table spaces with: | | | | | |
| LOCKSIZE ANY, ROW, or PAGE | | | | | |
| Table space lock acquired is: | IS | IS | IX | n/a | IX |
| Table lock acquired is: | IS | S | IX | n/a | X |
| Page or row locks acquired? | Yes | No | Yes | No | No |
|___________________________________|_______|______|_______|______|______|
| LOCKSIZE TABLE | | | | | |
| Table space lock acquired is: | n/a | IS | n/a | IX | IX |
| Table lock acquired is: | n/a | S | n/a | U | X |
| Page or row locks acquired? | No | No | No | No | No |
|___________________________________|_______|______|_______|______|______|
| LOCKSIZE TABLESPACE | | | | | |
| Table space lock acquired is: | n/a | S | n/a | U | X |
| Table lock acquired is: | n/a | n/a | n/a | n/a | n/a |
| Page or row locks acquired? | No | No | No | No | No |
|___________________________________|_______|______|_______|______|______|
Figure 8: Which locks DB2 chooses. N/A = Not applicable; Yes = Page or row locks are
acquired; No = No page or row locks are acquired.
Statistics Trace tells how many suspensions, deadlocks, timeouts, and lock
escalations occur in the trace record.
Accounting Trace gives the same information for a particular application. It also
shows the maximum number of concurrent page locks held and acquired during
the trace. Review applications with a large number to see if this value can be
lowered. This number is the basis for the proper setting of LOCKS PER USER and,
indirectly, LOCKS PER TABLE(SPACE).
Recommendations: One should check the results of the statistics and accounting
traces for the following possibilities:
Lock escalations are generally undesirable and are caused by processes that use
a large number of page, row, or LOB locks. In some cases, it is possible to
improve system performance by using table or table space locks.
Figure 9: Locking activity blocks from statistics trace and accounting trace
5.10.7Exercise
1. Which DB2 background process checks for deadlocks at regular intervals?
2. Commit frequency affects locking. True/False?
3. Which DSNZPARM contols the timeout duration?
4. What DB2 command shows the locks held on the database?
Answers:
1. Deadlock Detector
2. True
3. IRLMRWT
4. DISPLAY DATABASE
5.11 Concurrency
5.11.1Introduction to Concurrency
Definition: Concurrency is the ability of more than one application process to access
the same data at essentially the same time.
Lost updates: Without concurrency control, two processes, A and B, might both
read the same row from the database, and both calculate new values for one of
its columns, based on what they read. If A updates the row with its new value,
and then B updates the same row, A's update is lost.
To prevent those situations from occurring unless they are specifically allowed, DB2
might use locks to control concurrency.
What do locks do? A lock associates a DB2 resource with an application process in
a way that affects how other processes can access the same resource. The process
associated with the resource is said to "hold" or "own" the lock. DB2 uses locks to
ensure that no process accesses data that has been changed, but not yet committed,
by another process.
What do you do about locks? To preserve data integrity, the application process
acquires locks implicitly, that is, under DB2 control. It is not necessary for a process
to request a lock explicitly to conceal uncommitted data. Therefore, sometimes one
need not do anything about DB2 locks. Nevertheless processes acquire, or avoid
acquiring, locks based on certain general parameters. One can make better use of
the resources and improve concurrency by understanding the effects of those
parameters.
Here are a few items that affect concurrency, and an idea as to how to use them to
get results demanded by the application.
5.11.2ISOLATION Level
We have already discussed about the different levels of isolation in Section 6.3. Now
we shall see how they affect the concurrency aspect.
The various isolation levels offer less or more concurrency at the cost of more or less
protection from other application processes. The values one chooses should be based
primarily on the needs of the application. This section presents the isolation levels in
order from the one offering the least concurrency (RR) to that offering the most
(UR).
Figure 10 shows that all locks are held until the application commits. In the
following example, the rows held by locks L2 and L4 satisfy the predicate.
Figure 10: How an application using RR isolation acquires locks. All locks are held until the
application commits.
Applications that use repeatable read can leave rows or pages locked for longer
periods, especially in a distributed environment, and they can claim more logical
partitions than similar applications using cursor stability.
Applications that use repeatable read and access a nonpartitioning index cannot
run concurrently with utility operations that drain all claim classes of the
nonpartitioning index, even if they are accessing different logical partitions. For
example, an application bound with ISOLATION(RR) cannot update partition 1
while the LOAD utility loads data into partition 2. Concurrency is restricted
because the utility needs to drain all the repeatable-read applications from the
nonpartitioning index to protect the repeatability of the reads by the application.
Because so many locks can be taken, lock escalation might take place. Frequent
commits release the locks and can help avoid lock escalation.
With repeatable read, lock promotion occurs for table space scan to prevent the
insertion of rows that might qualify for the predicate. (If access is via index, DB2
locks the key range. If access is via table space scans, DB2 locks the table, partition,
or table space.)
An installation option determines the mode of lock chosen for a cursor defined with
the clause FOR UPDATE OF and bound with repeatable read.
Figure 11: How an application using RS isolation acquires locks when no lock avoidance
techniques are used. Locks L2 and L4 are held until the application commits. The other locks
aren't held.
Applications using read stability can leave rows or pages locked for long periods,
especially in a distributed environment. If read-stability is used, one should plan
for frequent commit points.
An installation option determines the mode of lock chosen for a cursor defined
with the clause FOR UPDATE OF and bound with read stability.
For table spaces created with LOCKSIZE ROW, PAGE, or ANY, a change can occur
even while executing a single SQL statement, if the statement reads the same
row more than once. In the following example, data read by the inner SELECT
can be changed by another transaction before it is read by the outer SELECT.
Therefore, the information returned by this query might be from a row that is no
longer the one with the maximum value for COL1.
SELECT * FROM T1
WHERE COL1 = (SELECT MAX(COL1) FROM T1);
In another case, if your process reads a row and returns later to update it, that
row might no longer exist or might not exist in the state that it did when your
application process originally read it. That is, another application might have
deleted or updated the row. If your application is doing non-cursor operations on
a row under the cursor, make sure the application can tolerate "not found"
conditions.
Similarly, assume another application updates a row after you read it. If your
process returns later to update it based on the value you originally read, you are,
in effect, erasing the update made by the other process. If you use isolation (CS)
with update, your process might need to lock out concurrent updates. One
method is to declare a cursor with the clause FOR UPDATE OF.
For packages and plans that contain updatable scrollable cursors, ISOLATION(CS)
lets DB2 use optimistic concurrency control. DB2 can use optimistic concurrency
control to shorten the amount of time that locks are held in the following situations:
Figure 12 and Figure 13 show processing of positioned update and delete operations
without optimistic concurrency control and with optimistic concurrency control.
Figure 12: Positioned updates and deletes without optimistic concurrency control
Figure 13: Positioned updates and deletes with optimistic concurrency control
I) When the application requests a fetch operation to position the cursor on a row,
DB2 locks that row, executes the FETCH, and releases the lock.
II) When the application requests a positioned update or delete operation on the
row, DB2 performs the following steps:
Example: An application tracks the movement of work from station to station along
an assembly line. As items move from one station to another, the application
subtracts from the count of items at the first station and adds to the count of items
at the second. Assume one wants to query the count of items at all the stations,
while the application is running concurrently.
What can happen if the query reads data that the application has changed
but has not committed?
If the application adds first and then subtracts, the query could add the amount
twice.
If those situations can occur and are unacceptable, it is not advisable to use UR
isolation.
Restrictions: One cannot use UR isolation for the types of statement listed below. If
one binds with ISOLATION(UR), and the statement does not specify WITH RR or
WITH RS, then DB2 uses CS isolation for:
- INSERT, UPDATE, and DELETE
- Any cursor defined with FOR UPDATE OF
When can one use uncommitted read (UR)? You can probably use UR isolation
in cases like the following ones:
damaging than reading the table 5 seconds earlier. Go ahead and read it with
ISOLATION(UR).
Example: The employee table of Spiffy Computer, our hypothetical user. For
security reasons, updates can be made to the table only by members of a single
department. And that department is also the only one that can query the entire
table. It is easy to restrict queries to times when no updates are being made and
then run with UR isolation.
Example: Spiffy gets sales leads from various sources. The data is often
inconsistent or wrong, and end users of the data are accustomed to dealing with
that. Inconsistent access to a table of data on sales leads does not add to the
problem.
A special mass delete lock acquired in S mode on the target table or table space. A
"mass delete" is a DELETE statement without a WHERE clause; that operation must
acquire the lock in X mode and thus cannot run concurrently.
An IX lock on any table space used in the work file database. That lock prevents
dropping the table space while the application is running.
No index is defined for the search criteria (WHERE clause). The index key must
match the columns used in the WHERE clause in order for the optimizer to use
the index to help locate the desired rows. If one chooses to optimize for high
concurrency, one should make sure the table design includes a primary key for
each table that will be updated. These primary keys should then be used
whenever these tables are referenced with an UPDATE SQL statement.
Direct access might be faster than via the index. The table must be large enough
so the optimizer thinks it is worthwhile to take the extra step of going through
the index, rather than just searching all the rows in the table. For example, the
optimizer would probably not use any index defined on a table with only four
rows of data.
A large number of row / page locks will be acquired. If many rows in the table are
going to be accessed by a transaction, the optimizer will probably acquire a table
or tablespace lock.
Any time one transaction holds a lock on a table or row, other transaction might be
denied access until the owner transaction has terminated. To optimize for maximum
concurrency, a small, row-level lock is usually better than a large table lock. Because
locks require storage space (to keep) and processing time (to manage), one can
minimize both these factors by using one large lock – rather than many small ones.
5.11.4Deadlock
Please refer to section 9.1 for details about deadlock.
Application designers need to watch out for deadlock scenarios whwn designing high-
concurrency applications that are to be run by multiple concurrent users. In
situations where the same set of rows will likely be read and then updated by
multiple copies of the same application program, the program should be designed to
roll back and retry any transactions that might be terminated as a result of a
deadlock situation. As a general rule, the shorter the transaction, the less likely the
transaction will be to get into a deadlock cycle. Srtting the proper interval for the
deadlock detector (in the database configuration file) is also necessary to ensure
good concurrent application performance. An interval that is too short will cause
unnecessary overhead, and an interval that is too long will enable a deadlock cycle to
delay a process for an unacceptable amount of time. One must balance the possible
delays in resolving deadlocks with the overhead of detecting the possible delays.
5.11.5Lock Compatibility
If a transaction A is running, holding a certain lock on resource X, then transaction B,
which also requires a lock on resource X, can run concurrently with transaction A
only if the lock requested by transaction B is compatible with the lock that
transaction A holds on resource X.
5.11.6Lock Conversion
Lock conversion often prevents transactions to run concurrently by promoting the
locks one of them is holding on a particular resource to a more restrictive type. This
can prevent the other transaction to do its own updates, thereby causing waits or
timeouts or deadlocks in some cases.
5.11.7Lock Escalation
Lock escalation takes place when the number of locks requested by a transaction on
an application exceeds the LOCKMAX parameter for the tablespace. This enhances
the performance of the transaction in question by reducing the overhead of excessive
number of page/row locks requested, but gives a blow to the concurrency.
Make way for the IRLM: One should make sure that the IRLM has a high MVS
dispatching priority or is assigned to the SYSSTC service class. It should come
next after VTAM and before DB2.
If more ECSA can be defined, then one should start the IRLM with PC=NO rather
than PC=YES. One can make this change without changing the application
process. This change can also reduce processing time.
Keep unlike things apart: One should give users different authorization IDs for
work with different databases; for example, one ID for work with a shared
database and another for work with a private database. This effectively adds to
the number of possible (but not concurrent) application processes while
minimizing the number of databases each application process can access.
Plan for batch inserts: If the application does sequential batch insertions,
excessive contention on the space map pages for the table space can occur. This
problem is especially apparent in data sharing, where contention on the space
map means the added overhead of page P-lock negotiation. For these types of
applications, one should consider using the MEMBER CLUSTER option of CREATE
TABLESPACE. This option causes DB2 to disregard the clustering index (or
implicit clustering index) when assigning space for the SQL INSERT statement.
Use LOCKSIZE ANY until you have reason not to: LOCKSIZE ANY is the
default for CREATE TABLESPACE. It allows DB2 to choose the lock size, and DB2
usually chooses LOCKSIZE PAGE and LOCKMAX SYSTEM for non-LOB table
spaces.
For LOB table spaces, it chooses LOCKSIZE LOB and LOCKMAX SYSTEM. One
should use LOCKSIZE TABLESPACE or LOCKSIZE TABLE only for read-only
tablespaces or tables, or when concurrent access to the object is not needed.
Before one chooses LOCKSIZE ROW, one should estimate whether there will be
an increase in overhead for locking and weigh that against the increase in
concurrency.
Examine small tables: For small tables with high concurrency requirements,
one should estimate the number of pages in the data and in the index. If the
index entries are short or they have many duplicates, then the entire index can
be one root page and a few leaf pages. In this case, one should spread out the
data to improve concurrency, or consider it a reason to use row locks.
Partition the data: Online queries typically make few data changes, but they
occur often. Batch jobs are just the opposite; they run for a long time and
change many rows, but occur infrequently. The two do not run well together. One
might be able to separate online applications from batch, or two batch jobs from
each other. To separate online and batch applications, one should provide
separate partitions. Partitioning can also effectively separate batch jobs from
each other.
Fewer rows of data per page: By using the MAXROWS clause of CREATE or
ALTER TABLESPACE, one can specify the maximum number of rows that can be
on a page. For example, if one uses MAXROWS 1, each row occupies a whole
page, and a page lock is confined to a single row. One should consider this option
if one has a reason to avoid using row locking, such as in a data sharing
environment where row locking overhead can be excessive.
Fewer rows per page can also be achieved by properly using the PCTFREE
parameter for a tablespace.
Taking commit points frequently in a long running unit of recovery (UR) has the
following benefits:
One should consider using the UR CHECK FREQ field or the UR LOG WRITE
CHECK field of installation panel DSNTIPN to help identify those applications that
are not committing frequently. UR CHECK FREQ, which identifies when too many
checkpoints have occurred without a UR issuing a commit, is helpful in
monitoring overall system activity. UR LOG WRITE CHECK enables one to detect
applications that might write too many log records between commit points,
potentially creating a lengthy recovery situation for critical tables.
Close cursors: If cursor is defined using the WITH HOLD option, the locks it
need could be held past a commit point. One should use the CLOSE CURSOR
statement as soon as possible in the program to cause those locks to be released
and the resources they hold to be freed at the first commit point that follows the
CLOSE CURSOR statement. Whether page or row level locks are held for WITH
HOLD cursors is controlled by the RELEASE LOCKS parameter on panel DSNTIP4.
Bind plans with ACQUIRE (USE): ACQUIRE (USE), which indicates that DB2
will acquire table and table space locks when the objects are first used and not
when the plan is allocated, is the best choice for concurrency.
table space locks. If one needs ACQUIRE (ALLOCATE), one might want to bind all
DBRMs directly to the plan.
5.11.9Exercise
1. During BIND, which ISOLATION option gives maximum concurrency?
2. Which ACQUIRE and RELEASE combination would give maximum concurrency?
Answers:
1.UR
2. USE and COMMIT
There is some locking activity that is not related to user data but takes place in
shared DB2 subsystem objects. User application programs can cause this locking
activity. It can also be caused by DB2 system plans processing. One is never aware
of most of this locking activity, although in some cases it can produce suspension
problems in your system. The DB2 system plans that generate locking activity are
these:
BCT, the plan used to perform service tasks and handle requests from DB2
resource managers. A lock issued by this plan is usually of short duration.
DSNBIND, the plan used for all binds. It is major contributor to the length of
time it takes to complete a bind.
DSNUTIL, the plan used by DB2 utility control program DSNUTILB. The
duration of locks held by this plan varies according to the specific DB2 utility
function being invoked.
Although the catalog and directory are designed to minimize contention among
application processes, update activity may lead to locking problems in concurrency
situations.
Five main activities can cause suspension problems in the DB2 catalog and
directory:
DB2 tasks that update DB2 catalog and directory tables. An example is
writing to SYSLGRNG every time a table space or partition is opened and
updated.
The BIND, REBIND, and FREE process, which reads some DB2 catalog
tables, such as SYSIBM.SYSTABLES, and inserts and/or updates others,
such as SYSIBM.SYSPACKAGE.
Data definition processes, such as CREATE, ALTER and DROP, which also
insert, update, or delete catalog and directory entries (for example,
DBD01).
Data control processes, such as GRANT and REVOKE, which affect the
concurrency of the catalog authorization tables (for example,
SYSIBM.SYSUSERAUTH).
Utility processing, which may also lock some directory tables (for
example, SYSUTILX).
To avoid most of these concurrency problems, one should process all the data
definition, data control and BIND activities in a dedicated window outside
production hours. One can also greatly relieve limitations on concurrency by
converting all catalog and directory indexes to Type 2, thus avoiding all index
locking.
When one binds a plan, DB2 creates an SKCT in SCT02. When one binds a package,
DB2 creates an SKPT in SPT01.
The following operations require exclusive control of the related SKCT and SKPT as
they are updating them:
When one runs a plan or package, DB2 takes a shared lock on it, so that changes
cannot be made to the object while it is being executed in an application program.
Thus, the execution of a plan or package contends with operations listed above.
Two main processes have to read and lock a DBD in shared mode:
Dynamic SQL statements
Active utilities.
Static SQL does not take any locks on the DBD if the DBD is cached in the
environment descriptor management (EDM) pool. Therefore DB2 does not have to go
to the DB2 directory table space to retrieve the DBD.
Each time a database or a dependent object definition is modified, the DBD object in
the directory must be updated. This update process requires an exclusive lock on
the DBD which is incompatible with dynamic SQL and utility execution. If the DBD
is in use for a plan or package, dynamic SQL and utility execution are suspended.
__________________________________________________________________________________
| DB2 Process |
|________ ________________ ___________ ________ ___________ ___________ ___________|
| | | | | | | Drop | | |
| Object of | Static| | | Create | Alter | Table | | |
| Locking | SQL |Dynamic SQL| BIND | Table | Table | Space | Grant | Revoke|
|___________|_______|___________|_______|_________|_______|_______|_______|________|
| Catalog | IS | IS | IX | IX | IX | IX | IX | IX |
| Table | (a) | (b) | | | | | | |
| spaces | | | | | | | | |
|___________|_______|___________|_______|_________|_______|_______|_______|________|
| SKCT or | S | S | X | - | X | X | - | X |
| SKPT | | | | | (c) | (d) | | |
|___________|_______|___________|_______|_________|_______|_______|_______|________|
| DBD | - | S | S | X | X | X | - | - |
| | (e) | | | | | | | |
|___________|_______|___________|_______|_________|_______|_______|_______|________|
| Notes: |
| |
| (a) IS locks on the catalog table spaces are held only for a short time to check|
| EXECUTE authority if the plan or package is not public or the authorization |
| list is not cached in the EDM pool. |
| |
| (b) Except when checking EXECUTE authority (see Note a), IS locks on the |
| catalog table spaces are held until the COMMIT point. |
| |
| (c) SKCT or SKPT is marked invalid if a referential constraint (such as a new |
| primary key or foreign key) is added or changed, or the AUDIT attribute is |
| changed in the table. |
| |
| (d) SKCT or SKPT is marked invalid as a result of a drop table space operation. |
| |
| (e) If the DBD is not in the EDM pool, S-locks are acquired on the DBD table |
| space, which effectively locks the DBD. | |
__________________________________________________________________________________|
4. What are the different values for ISOLATION, the BIND parameter? Arrange
them in the ascending order of restrictiveness as far as locking is concerned.
7. What is UTIMOUT?
5.14 Reference
http://publibz.boulder.ibm.com/cgi-
bin/bookmgr_OS390/BOOKS/DSNAG0F4/CCONTENTS
DB2 by Craig Mullins
UNIT - VI
6. Dynamic SQL
6.1 Unit Objectives
This section will describe in details about Dynamic SQL and it’s usage in application
program.
6.2 Introduction
Static SQL is hard coded, and only the values of host variables in predicates can
change. Dynamic SQL is characterized by its capability to change columns, tables,
and predicates during a program’s execution. This flexibility requires different
techniques for embedding dynamic SQL in application program.
For most DB2 users, static SQL--embedded in a host language program and bound
before the program runs--provides a straightforward, efficient path to DB2 data. You
can use static SQL when you know before run time what SQL statements your
application needs to execute.
Dynamic SQL prepares and executes the SQL statements within a program, while the
program is running. There are four types of dynamic SQL:
Embedded Dynamic SQL: The application puts the SQL source in host
variables and includes PREPARE and EXECUTE statements that tell DB2
to prepare and run the contents of those host variables at run time.
The programs that include embedded dynamic SQL must go through
pre-compile and bind.
A program that provides for dynamic SQL accepts as input, or generates, an SQL
statement in the form of a character string. You can simplify the programming if you
can plan the program not to use SELECT statements, or to use only those that return
a known number of values of known types. In the most general case, in which you
do not know in advance about the SQL statements that will execute, the program
typically takes these steps:
1. Translates the input data, including any parameter markers, into an SQL
statement
2. Prepares the SQL statement to execute and acquires a description of the
result table
3. Obtains, for SELECT statements, enough main storage to contain retrieved
data
4. Executes the statement or fetches the rows of data
5. Processes the information returned
6. Handles SQL return codes.
The time at which DB2 determines the access path depends on these factors:
Whether the statement is executed statically or dynamically
Whether the statement contains input host variables
For dynamic SQL statements, DB2 determines the access path at run time, when the
statement is prepared. This can make the performance worse than that of static SQL
statements. However, if you execute the same SQL statement often, you can use the
dynamic statement cache to decrease the number of times that those dynamic
statements must be prepared.
Also, WITH HOLD offers no relief for SQL statements that are not SELECT
statements.
DB2 can save prepared dynamic statements in a cache. The cache is a DB2-wide
cache in the EDM pool that all application processes can use to store and retrieve
prepared dynamic statements. After an SQL statement has been prepared and is
automatically stored in the cache, subsequent prepare requests for that same SQL
statement can avoid the costly preparation process by using the statement in the
cache. Cached statements can be shared among different threads, plans, or
packages.
SELECT
UPDATE
INSERT
DELETE
Distributed and local SQL statements are eligible. Prepared, dynamic statements
using DB2 private protocol access are eligible.
When the dynamic statement cache is active, and you run an application bound with
KEEPDYNAMIC(YES), DB2 retains a copy of both the prepared statement and the
statement string. The prepared statement is cached locally for the application
process. It is likely that the statement is globally cached in the EDM pool, to benefit
The local instance of the prepared SQL statement is kept in ssnmDBM1 storage until
one of the following occurs:
The application process ends.
A rollback operation occurs.
The application issues an explicit PREPARE statement with the same
statement name.
If the application does issue a PREPARE for the same SQL statement
name that has a kept dynamic statement associated with it, the kept
statement is discarded and DB2 prepares the new statement.
The statement is removed from memory because the statement has
not been used recently, and the number of kept dynamic SQL
statements reaches a limit set at installation time.
If an application requester does not issue a PREPARE after a COMMIT, the package at
the DB2 for OS/390 server must be bound with KEEPDYNAMIC(YES). If both
requester and server are DB2 for OS/390 subsystems, the DB2 requester assumes
that the KEEPDYNAMIC value for the package at the server is the same as the value
for the plan at the requester.
The KEEPDYNAMIC option has performance implications for DRDA clients that specify
WITH HOLD on their cursors:
If KEEPDYNAMIC (NO) is specified, a separate network message is
required when the DRDA client issues the SQL CLOSE for the cursor.
If KEEPDYNAMIC (YES) is specified, the DB2 for OS/390 server
automatically closes the cursor when SQLCODE +100 is detected,
which means that the client does not have to send a separate message
to close the held cursor. This reduces network traffic for DRDA
applications that use held cursors. It also reduces the duration of locks
that are associated with the held cursor.
The governor controls only the dynamic SQL manipulative statements SELECT,
UPDATE, DELETE, and INSERT. Each dynamic SQL statement used in a program is
subject to the same limits. The limit can be a reactive governing limit or a predictive
governing limit. If the statement exceeds a reactive governing limit, the statement
receives an error SQL code. If the statement exceeds a predictive governing limit, it
receives a warning or error SQL code.
If the failed statement involves an SQL cursor, the cursor's position remains
unchanged. The application can then close that cursor. All other operations with the
cursor do not run and the same SQL error code occurs.
If the failed SQL statement does not involve a cursor, then all changes that the
statement made are undone before the error code returns to the application. The
application can either issue another SQL statement or commit all work done so far.
EXEC SQL
EXECUTE IMMEDIATE :DSTRING;
DSTRING is the name of a host variable, and is not a DB2 reserved word. In
assembler, COBOL and C, you must declare it as a varying-length string variable. In
FORTRAN, it must be a fixed-length string variable. In PL/I, it can be a fixed- or
varying-length character string variable, or any PL/I expression that evaluates to a
character string.
For example, let the variable: DSTRING have the value "DELETE FROM
DSN8610.EMP WHERE EMPNO = ?". To prepare an SQL statement from that string
and assign it the name S1, write:
EXEC SQL PREPARE S1 FROM :DSTRING;
The prepared statement still contains a parameter marker, for which you must
supply a value when the statement executes. After the statement is prepared, the
table name is fixed, but the parameter marker allows you to execute the same
statement many times with different values of the employee number.
EXECUTE executes a prepared SQL statement, naming a list of one or more host
variables, or a host structure, that supplies values for all of the parameter markers.
After you prepare a statement, you can execute it many times within the same unit
of work. In most cases, COMMIT or ROLLBACK destroys statements prepared in a
unit of work. Then, you must prepare them again before you can execute them
again. However, if you declare a cursor for a dynamic statement and use the option
WITH HOLD, a commit operation does not destroy the prepared statement if the
cursor is still open. You can execute the statement in the next unit of work without
preparing it again.
Example:
The PREPARE statement prepares the SQL statement and calls it S1. The EXECUTE
statement executes S1 repeatedly, using different values for EMP.
An advantage of the fixed-list SELECT is that you can write it in any of the
programming languages that DB2 supports. Varying-list dynamic SELECT statements
require assembler, C, PL/I, and versions of COBOL other than OS/VS COBOL.
Dynamic SELECT statements cannot use INTO; hence, you must use a cursor to put
the results into host variables. In declaring the cursor, use the statement name (call
it STMT), and give the cursor itself a name (for example, C1):
EXEC SQL DECLARE C1 CURSOR FOR STMT;
4. Prepare the statement
The OPEN statement evaluates the SELECT statement named STMT. For
example:
If STMT contains parameter markers, then you must use the USING clause of
OPEN to provide values for all of the parameter markers in STMT. If there are
four parameter markers in STMT, you need:
The key feature of this statement is the use of a list of host variables to
receive the values returned by FETCH. The list has a known number of items
(two--:NAME and :PHONE) of known data types (both are character strings,
of lengths 15 and 4, respectively).
It is possible to use this list in the FETCH statement only because you planned
the program to use only fixed-list SELECTs. Every row that cursor C1 points
to must contain exactly two character values of appropriate length.
Suppose your program dynamically executes SQL statements, but this time without
any limits on their form. Your program reads the statements from a terminal, and
you know nothing about them in advance. They might not even be SELECT
statements.
As with non-SELECT statements, your program puts the statements into a varying-
length character variable; call it DSTRING. Your program goes on to prepare a
statement from the variable and then give the statement a name; call it STMT.
Now there is a new wrinkle. The program must find out whether the statement is a
SELECT. If it is, the program must also find out how many values are in each row,
and what their data types are. The information comes from an SQL descriptor area
(SQLDA).
exceed the predictive governing error threshold. DB2 returns the error
SQL code for an EXECUTE or OPEN statement.
6.3.8 Exercise
Questions:
1. List down different types of Dynamic SQL.
1. What is dynamic SQL cache?
2. Which are the eligible statements for caching?
3. How can we predict the cost of SQL statement?
4. What is SQLDA?
Answers:
1. Embedded Dynamic SQL, Interactive SQL, Deferred embedded SQL,
Dynamic SQL through ODBC functions
2. DB2 can save prepared dynamic statements in a cache. The cache is a
DB2-wide cache in the EDM pool that all application processes can use to
store and retrieve prepared dynamic statements. After an SQL statement
has been prepared and is automatically stored in the cache, subsequent
prepare requests for that same SQL statement can avoid the costly
preparation process by using the statement in the cache.
3. SELECT,UPDATE,INSERT AND DELETE
4. To predict the cost of an SQL statement, you execute EXPLAIN to put
information about the statement cost in DSN_STATEMNT_TABLE
5. The SQLDA is a structure used to communicate with your program,
and storage for it is usually allocated dynamically at run time.
6.5 Reference
UNIT - VII
7. Stored Procedures
7.1 Unit Objectives
7.2 Introduction
SEQUENCE OF
STEPS IN THE
EXECUTION OF A
USER STORED PROCEDURE
OUTPUT
USER
INPUT
CALLING RESULT
PROGRAM SET
DATABAS
E
STORED
PROCEDURE
7.2.3 Advantage
Reusability
Consistency
Data Integrity
Performance
Security
7.2.4 Disadvantages
It is more cumbersome to change a Stored Procedure as compared to a
normal program due to the higher levels of security involved.
Inclusion of business logic within the Stored Procedure makes it less
generic and hence should be avoided.
CICS transactions should not be called from a Stored Procedure.
7.2.6 Exercise
1. When network traffic is a concern, it is advised not to use SPs. True/False?
2. Maintaining SPs is easier compared to embedded SQL. True/False?
3. Security is better for SPs as compared to embedded SQL. True/False?
4. What are two types of SPs?
Answers: 1. False 2. False 3. True 4. a. SPs using Result Sets and b. SPs that
don’t use Result Sets
Here we would take a look at few terms that get used in connections with SPs.
The Load Module for the Store Procedure is always present in a different Load
Library. In most cases the name of this Load Library would be ‘TEST.SP.LOADLIB’,
unless the System Administrator has modified this. Before the Stored Procedure can
be executed it needs to be declared in the SYSIBM.SYSPROCEDURES. This is one of
the system tables that is maintained by DB2 and can be updated only by the DBA.
Some of the columns that are of interest are enumerated below:
PROCEDURE – This is column contains the name of the Stored Procedure.
LOADMOD – This is the name of the Load Module. This name may be different
from the Procedure name.
LINKAGE – This column specifies whether the input parameters for the Stored
Procedure can be nulls or not. In case the Stored Procedure is defined with
‘input characters can be null’, then there should be check at the beginning to
determine whether the input parameters are nulls.
LANGUAGE – This column specifies the host language used for coding the
Stored Procedure.
COLLID – This column contains the collection name for the stored procedure
package. If COLLID is blank, the client application collection name is used.
PGM_TYPE – This column specifies whether the Stored Procedure is a Main
program or a Sub program. If the Stored Procedure is declared as a Main
program then it should not have the GOBACK statement at the end.
RESULT_SETS – This column specifies the maximum number of Result Sets
that the Stored Procedure can return to the calling program.
PARMLIST – The input and output parameters being used by the Stored
Procedure are declared in this column along with their size and type.
Parameters can be of three types, namely, input, output and inout types.
COMMIT_ON_RETURN – This column specifies whether the unit of work done
by the Stored Procedure should be committed as soon as the Stored
Procedure ends successfully and control is returned back to the calling
program.
STAYRESIDENT – This column determines whether the Stored Procedure is
deleted from memory when execution is over. If this column is defined as ‘Y’
then it means that the Stored Procedure remains in memory even after
execution is over. If, however, this column is blank, then the Stored is
deleted from memory once it ends.
There are a few other columns in the SYSIBM.SYSPROCEDURE table, which contain
other attributes of the Stored Procedure. The Online Manuals contain detailed
descriptions of all the columns in the SYSIBM.SYSPROCEDURES table.
Now let us take a look at a Stored Procedure that uses the Result Set concept with
the host language as COBOL. Please refer to Appendix D.
Now we come to the structure of the calling program. A few salient points about the
calling program:
The EXEC SQL CALL statement used to call the Stored Procedure should use the
name of the Stored Procedure and not the Load Module name.
SQLCODE = +466 for the call to the Stored Procedure implies that the call has
been successful.
In this case we need not use Locators as they are used only when Result Sets are
used.
A Fetch statement is not required, to retrieve data pulled out by the Stored
Procedure as we use input output parameters for this. All data would be fetched
within the Stored Procedure and moved to the appropriate output variables and
made accessible to the calling program.
In case the input and output parameters have a number of sub-variables, then
the Redefines clause should be used so that the number of input and output
parameters used match the numbers defined in the SYSIBM.SYSPROCEDURES
table.
We should use a Copybook to pass parameters to the Stored Procedure and back
to the calling program for a non Result Set Stored Procedure.
Commit should be done in the calling program if the COMMIT_ON_RETURN = ‘N’
in the SYSIBM.SYSPROCEDURES table.
7.5.3 Exercise
1. What is the significance of LINKAGE column in SYSIBM.SYSPROCEDURES
table?
2. What is the significance of STAYRESIDENT column in
SYSIBM.SYSPROCEDURES table?
3. When a SP is using Result Set concept, what is clause a MUST in declaration
of cursor?
4. SQLCODE ____ implies that a call to SP is successful.
5. When a SP uses Result Set concept, it is mandatory to close all cursors.
True/False?
6. A FETCH statement is a MUST when not using Result Set concept. True/False?
Answers:
1. LINKAGE column specifies whether parameters passed to SP could be nulls.
2. A STAYRESIDENT column value decides whether to SP remains in memory
after execution.
3. WITH RETURN FOR
4. +466
5. False
6. False
You must associate each of these address spaces with a RACF user ID. Each of them
can also be assigned a RACF group name. The DB2 address spaces cannot be started
with batch jobs.
For stored procedures, stored procedures address space entries are required in the
RACF started procedures table. The associated RACF user ID and group name do not
have to match those used for the DB2 address spaces, but they must be authorized
to run the call attachment facility (for the DB2-established stored procedure address
space) or Recoverable Resource Manager Services attachment facility (for WLM-
established stored procedure address spaces).
If you follow these guidelines, each TCB that runs in the DB2-established stored
procedures address space requires approximately 100KB below the 16MB line. Each
TCB that runs in a WLM-established stored procedures address space uses
approximately 200KB.
DB2 needs extra storage for stored procedures in the WLM-established address
space because you can create both main and sub programs, and DB2 must create an
environment for each.
You must have Language Environment to run stored procedures. Your requirements
can differ significantly depending on your release of Language Environment.
load library grows from additions or replacements, the library may have to be
extended.
If you use PDSEs for the load libraries, the new extent information is dynamically
updated and you do not need to stop and start the address space. If PDSs are used,
load failures may occur because the new extent information is not available.
There are other tasks that must be completed before a stored procedure can run in a
WLM-established stored procedures address space. Here is a summary of those
tasks:
1. Make sure you have a numeric value specified in the TIMEOUT VALUE field of
installation panel DSNTIPX. If you have problems with setting up the
environment, this timeout value ensures that your stored procedures will not
hang for an unlimited amount of time.
2. If you want to migrate any stored procedures that use the DB2-established
stored procedure address space (ssnmSPAS), you must link edit them or code
them so that they use the Recoverable Resource Manager Services
attachment facility (RRSAF) instead of the call attachment facility. Use the JCL
startup procedure for WLM-established stored procedures address space that
was created when you installed or
migrated as a model. (The default name is ssnmWLM.)
Unless a particular environment or service class is not used for a long time,
WLM creates on demand at least one address space for each combination of
WLM environment name and service class that is encountered in the
workload. For example, if there are five environment names that each have
six possible service classes, and all
those combinations are in demand, it is possible to have 30 stored procedure
address spaces.
______________________________________________________________________________________________________________
| |
| Application-Environment Notes Options Help |
| ------------------------------------------------------------------------ |
| Create an Application Environment |
| Command ===> ___________________________________________________________ |
| |
| Application Environment Name . : WLMENV2 |
| Description . . . . . . . . . . Large Stored Proc Env. |
| Subsystem Type . . . . . . . . . DB2 |
| Procedure Name . . . . . . . . . WLMENV2 |
| Start Parameters . . . . . . . . DB2SSN=DB2A,NUMTCB=2,APPLENV=WLMENV2 |
| _______________________________________ |
| ___________________________________ |
| |
| Select one of the following options. |
| 1 1. Multiple server address spaces are allowed. |
| 2. Only 1 server address space per MVS system is allowed. |
| |
| |
|__________________________________________________________________________________|
Figure 1: WLM Panel to Create an Application Environment.
4. Update the WLM_ENV column of SYSIBM.SYSPROCEDURES to associate a
stored procedure with an application environment.
UPDATE SYSIBM.SYSPROCEDURES
SET WLM_ENV='WLM_ENV2'
WHERE PROCEDURE='BIGPROC';
5. Using the WLM install utility, install the WLM service definition that contains
information about this application environment into the couple data set.
6. Activate a WLM policy from the installed service definition.
7. Issue STOP PROCEDURE and START PROCEDURE for any stored procedures
that run in the ssnmSPAS address space. This allows those procedures to pick
up the application environment from the WLM_ENV column of
SYSIBM.SYSPROCEDURES.
8. Begin running stored procedures.
The accounting report on the server has several fields that specifically relate to
stored procedures processing, as shown in figure 2.
AVERAGE APPL (CLASS 1) DB2 (CLASS 2) IFI (CLASS 5) CLASS 3 SUSP. AVERAGE TIME AV.EVENT
------------ -------------- -------------- -------------- -------------- ------------ --------
ELAPSED TIME 0.123676 0.053400 N/P LOCK/LATCH 0.000000 0.00
CPU TIME 0.012648 0.009332 N/P SYNCHRON. I/O 0.040742 1.00
TCB 0.004097 0.001719 N/P OTHER READ I/O 0.000000 0.00
TCB-STPROC A 0.008551 0.007613 N/A OTHER WRTE I/O 0.000000 0.00
CPU-PARALL 0.000000 0.000000 N/A SER.TASK SWTCH 0.000000 0.00
SUSPEND TIME N/A 0.040742 N/A ARC.LOG(QUIES) 0.000000 0.00
TCB N/A 0.040742 N/A ARC.LOG READ 0.000000 0.00
CPU-PARALL N/A 0.000000 N/A DRAIN LOCK 0.000000 0.00
NOT ACCOUNT. N/A 0.003327 N/A CLAIM RELEASE 0.000000 0.00
DB2 ENT/EXIT N/A 8.00 N/A PAGE LATCH 0.000000 0.00
EN/EX-STPROC N/A 36.00 N/A STORED PROC. B 0.000000 0.00
DCAPT.DESCR. N/A N/A N/P NOTIFY MSGS. 0.000000 0.00
LOG EXTRACT. N/A N/A N/P GLOBAL CONT. 0.000000 0.00
NOT NULL 1 1 0 TOTAL CLASS 3 0.040742 1.00
.
.
.
.
.
.
Descriptions of Fields:
The number of calls to stored procedures is indicated in C.
The part of the total CPU time that was spent satisfying stored procedures
requests is indicated in A.
The amount of time spent waiting for a stored procedure to be scheduled is
indicated in B.
The number of times a stored procedure timed out waiting to be scheduled is
shown in D.
7.6.4 Exercise
1. A DB2 subsystem has _______ address space for the distributed data facility.
2. It is recommended to use _______ for load libraries containing stored
procedures.
Answers:
1. ssnmDIST
2. Partitioned Data Set Extended (PDSEs)
3. environment name and service class
Store Procedure could be run in two types of environments, WLM (Work load
Manager)-established stored procedures address spaces and DB2-established stored
procedure address space.
Appendix C summarizes the differences between stored procedures that run in WLM-
established stored procedures address spaces and those that run in DB2-established
stored procedure address space.
7.8 SP Builder
The database administrator (DBA) or developer who builds the stored procedure
must have the database privileges the stored procedure requires, but the users of
the client applications that call the stored procedure do not need such privileges.
DB2 Stored Procedure Builder is a graphical application that supports the rapid
development of DB2 stored procedures. Using Stored Procedure Builder, you can
perform the following tasks:
Create stored procedures
Build stored procedures on local and remote DB2 servers
Modify and rebuild existing stored procedures
Run stored procedures for testing and debugging the execution of installed
stored procedures
Tip: Using Stored Procedure Builder, you can also run stored procedures that you
created in another editor and that use a language other than Java or the SQL
procedure language. You might want to test the execution of existing installed stored
procedures.
Stored Procedure Builder is implemented with Java and all database connections are
managed by using a Java Database Connectivity (JDBC) API. Using a JDBC driver,
you can connect to any DB2 database by using a local alias.
7.8.2 How has DB2 SP Builder changed the process of creating SPs?
DB2 Stored Procedure Builder provides an easy-to-use development environment for
creating, installing, and testing stored procedures. Using Stored Procedure Builder
allows you to focus on creating your stored procedure logic rather than the details of
registering, building, and installing stored procedures on a DB2 server. Additionally,
with Stored Procedure Builder, you can develop stored procedures on one operating
system and build them on other server operating systems.
You can identify Stored Procedure Builder project files by their SPP file extension.
The Project window shows all of the stored procedures on the DB2 database to which
you are connected.
Depending on their state and language, stored procedures have different icons:
Java stored procedure
SQL stored procedure
Stored procedure created in a language other than Java or SQL
Java stored procedure that has not been built to the database or that has
changed since it was last built to the database
SQL stored procedure that has not been built to the database or that has
changed since it was last built to the database
With Stored Procedure Builder, you create stored procedures in Java and the SQL
procedure language. Creating stored procedures in Java and the SQL procedure
language produces stored procedures that are highly portable among operating
systems.
Using a stored procedure wizard and SQL Assistant facilitate the development of
stored procedures. You launch a stored procedure wizard from the Project window by
selecting the
Stored Procedures folder; then, use the Selected menu to create a new stored
procedure. You can use a stored procedure wizard to create your basic SQL
structure; then, you can use the code editor to add highly sophisticated stored
procedure logic.
You can also create stored procedures without using a stored procedure wizard. You
can create stored procedures by using a template that creates the stored procedure
structure but does not include any SQL statements. After generating the basic stored
procedure structure, you can use the code editor to further modify the generated
code to add logic and SQL statements.
When creating a stored procedure, you can choose to return a single result set,
multiple result sets, or output parameters only. You might choose not to return a
result set or output parameters when your stored procedure creates or updates
database tables.
You can use a stored procedure wizard to define input and output parameters for a
stored procedure so that it receives values for host variables from the client
application. Additionally, you can create multiple SQL statements in a stored
procedure; the stored procedure receives a case expression and selects one of a
number of queries.
Using the code editor, you can add parameters, result sets, and additional stored
procedure logic. By modifying a Java stored procedure, you can add methods to the
code to include sophisticated stored procedure logic. For Java stored procedures, you
can add logic to the method that is called when the stored procedure starts. In Java
stored procedures and SQL stored procedures, you can add calls to other stored
procedures and run other SQL statements.
See the following topics for detailed information about how you can use the code
editor in Stored Procedure Builder:
Modifying existing Java stored procedure source code
Modifying existing SQL stored procedure source code
Editing generated code
When you run a stored procedure, depending on how you set it up, it can return
result sets and output parameters based on test input parameter values that you
enter. When you run a stored procedure that has input parameters, you are
prompted for any required parameters.
7.8.3 Exercise
1. Stored Procedure could be run in ___ types of environments.
2. Can we use SP Builder to run SPs?
Answers:
1. Two
2. Yes
You should use “stay resident” option with reentrant program. For any program that
is not reentrant, you need to absolutely negate the “stay resident” option.
On DB2 for OS/390, SPs are fenced. On other platforms they can be fenced or non-
fenced.
The routine, which checks for ASUTIME overage, runs ones a clock minute. This way,
it does not provide a very strict control on how much CPU time a SP can use. We can
use priorities and service goals of WLM to have total control.
You can also specify a limit for number of times SPs can abnormally terminate. On
installation panel DSNTIPX, a field called MAX ABEND COUNT is used for this. This
helps us in preventing overloading of the system with ABEND dumps.
Using EXCI gives the CICS program the ability to both run as online transaction in
CICS and as a program called via SP y a client application. So when it comes to
existing system integration, SPs come really handy.
7.9.6 Exercise
1. For any program that is not reentrant, you need to absolutely negate the
_____ column in SYSIBM.SYSPROCEDURES table..
2. On DB2 for OS/390, SPs are fenced. True/False?
3. _____ column in SYSIBM.SYSROUTINES is set to allow DB2 to cancel SPs that
are in a loop.
4. For better performance, guideline is to use WLM in ____ mode if you use SPs.
Answers:
1. STAYRESIDENT
2. True
3. ASUTIME
4. Goal
5. OS/390
Some additional SPs that come with DB2 are not documented. They were included
starting with version 5. Its possible that some are no longer included. Here we would
just introduce you to these SPs.
7.10.1DSNWZP
It returns all values of the normal and hidden DSNZPARMs and the version 6
DSNHDECP values.
7.10.2DSNWSPM
Retrieves many performance statistics like SQL CPU.
7.10.3DSNACCMG
Formats SQLCA as DSNTIAR did.
7.10.4DSNACCAV
Gives partition information for table spaces and index spaces to show which needs
REORG, RUNSTATS or image copy utilities executed.
7.10.5DSNUTILS
Executes DB2 utilities from any process that can issue an SQL call statement.
7.11.1Do’s
Defining the Stored Procedure properly in the SYSIBM.SYSPROCEDURES
should always be done at the beginning by the DBA.
Check whether the user compiling the Stored Procedure requires to have
some special authorities to execute this operation or not.
Use the clause ‘WITH HOLD FOR’ while declaring the cursor within the Stored
Procedure if it uses the Result Set concept.
Do not initialize the Input parameters within the Stored Procedure.
If the Stored Procedure has been defined as Main Program in the
SYSIBM.SYSPROCEDURES table do not use the GOBACK statement in the
Stored Procedure. This is mentioned in the Manual. However from personal
experience I found that it does not make a significant difference.
The number of input and output parameters being used by the Stored
Procedure should tally with the values defined in the
SYSIBM.SYSPROCEDURES table. In case sub-variables are being used, they
must be clubbed together using the REDEFINES clause.
Always validate the input parameters before using them in SQL statements in
the Stored Procedure and also check whether any of the input parameters are
null.
The Result Set concept should be used in the Stored Procedure if the number
of rows that can be returned are large or if one is not sure of the maximum
number of rows that might be returned.
Always pass appropriate error messages back to the calling program in case
of exceptional conditions.
Using a copybook to pass parameters make things a lot easier.
Once the Stored Procedure executes successfully, make sure that the Load
Module gets updated into the ‘TEST.SP.LOADLIB’ library every time it is
compiled.
Always check for SQLCODE = +466 for the call to the Stored Procedure to
determine whether the call has been successful or not.
Any changes to the columns in the SYSIBM.SYSPROCEDURES table for the
Stored Procedure should ask for appropriate changes in both the Stored
Procedure as well as the calling program.
Use COMMIT ON RETURN option for SPs to reduce network traffic,
contentions, etc. However, note that this option would not be useful and
would be ignored if specified, in nested SPs.
Set DESCSTAT parm of DSNZPARM on host DB2 to YES if you want column
names to be returned from a SP. For dynamic SELECT statements, column
names would be returned by default.
7.11.2DON’T’s
Do not call any other program from the Stored Procedure if the version of
DB2 is 5. This is possible in case of version 6.
Do not put any display statements in the Stored Procedure. All error
messages should be displayed in the calling program as per the status code
passed by the Stored Procedure.
Do not issue any CICS calls from within the Stored Procedure.
Do not issue any ‘COMMIT’ statements within the Stored Procedure.
Do not create a Stored Procedure that does not contain any SQL statements.
Do not close the cursor within the Stored Procedure if it uses the Result Set
concept, as this will make the Result Set unavailable to the calling program.
It’s better if we do not include business logic within the Stored Procedure.
Be careful in use of nested SPs. Nested SPs are ones where SP can invoke
User Defined Functions (UDFs) and subsequently can call other SPs (local or
remote), any of which can invoke triggers. If not planned and implemented
properly, there could be looping issues, unnecessary table updates resulting
in unnecessary trigger invocation, etc.
7.13 Reference
Redbook on SP Builder
http://publibz.boulder.ibm.com/cgi-
bin/bookmgr_OS390/BOOKS/DSNAG0F4/CCONTENTS
DB2 High Performance Design and Tuning by Richard Yevich and Susan
Lawson.
Glossary
Active Log - The portion of the DB2 log to which log records are written as they are
generated. The active log always contains the most recent log records, whereas the
archive log holds those records that are older and no longer will fit on the active log.
Caching Dynamic SQL statements - DB2 can save prepared dynamic statements
in a cache. The cache is a DB2-wide cache in the EDM pool.
Checkpoint - A point at which DB2 records internal status information on the DB2
log that would be used in the recovery process if DB2 should abend.
Check Pending - A state of a table space or partition that prevents its use by some
utilities and some SQL statements, because it can contain rows that violate
referential constraints, table check constraints, or both.
CICS EXCI - An interface that allows and Os/390 application program executing in
OS/390 address space to link to a CICS program running in CICS address space.
Claims – To register to DB2 that an object is being accessed. This registration is also
called a claim. A claim is used to ensure that an object cannot be drained until a
commit is reached. Contrast with drain
Commit - The operation that ends a unit of work by releasing locks so that the
database changes made by that unit of work can be perceived by other processes.
Concurrency – The shared use of resources by more than one application process
at the same time
Control Interval (CI) - A fixed-length area or direct access storage in which VSAM
stores records and creates distributed free space. Also, in a key-sequenced data set
or file, the set of records pointed to by an entry in the sequence-set index record.
The control interval is the unit of information that VSAM transmits to or from direct
access storage. A control interval always includes an integral number of physical
records.
Drain Lock - A lock on a claim class, which prevents a claim from occurring.
Dynamic SQL through ODBC functions - When the application contains ODBC
function calls that pass dynamic SQL statements as arguments.
EDM pool - A pool of main storage used for database descriptors and application
plans.
Embedded Dynamic SQL - The application puts the SQL source in host variables
and includes PREPARE and EXECUTE statements that tell DB2 to prepare and run the
contents of those host variables at run time.
Fixed-list SELECT statements - User must know the number of columns and the
data types of those columns.
Forward Log Recovery - The third phase of restart processing during which DB2
processes the log in a forward direction to apply all REDO log records.
IRLM – Internal Resource Lock Manager. An MVS subsystem used by DB2 to control
communication and database locking
Latch – A DB2 internal mechanism for controlling concurrent events or the use of
system resources
Lock Conversion – The process of changing the size or mode of a DB2 lock to a
higher level
Lock Escalation - The change in the size of a lock from a row or page lock to a
table space lock because the number of page locks concurrently held on a given
resource exceeds a preset limit
Lock Mode – A representation for the type of access concurrently running programs
can have to a resource held by a DB2 lock.
Lock Promotion – The process of changing the size or mode of a DB2 lock to a
higher level
Locking - The process by which the integrity of data is ensured. Locking prevents
concurrent users from accessing inconsistent data
Locksize - The amount of data controlled by a DB2 lock on table data; the value can
be a row, a page, a table, or a table space
Logical Unit - An access point through which an application program accesses the
SNA network in order to communicate with another application program.
Log Initialization - The first phase of restart processing during which DB2 attempts to
locate the current end of the log.
Log Record Sequence Number (LRSN) - A number DB2 generates and associates
with each log record. DB2 also uses the LRSN for page versioning. The LRSNs
generated by a given DB2 data sharing group form a strictly increasing sequence for
each DB2 log and a strictly increasing sequence for each page across the DB2 group
Non-Partitioned Index (NPI) - When used with partitioned table spaces, a non-
partitioning index is any index on a partitioned table space that is not the partitioning
index.
Resource Limit Facility (or Governor) - It limits the amount of CPU time an SQL
statement can take, which prevents SQL statements from making excessive
requests.
Result set - One row of data returned to the called program by the Stored
Procedure.
Static SQL - is hard coded, and only the values of host variables in predicates can
change.
Storage Group - A DB2 storage group is a set of volumes on direct access storage
devices (DASD).
Sysplex - A set of MVS systems that communicate and cooperate with each other
through certain multisystem hardware components and software services to process
customer workloads.
Table Space - A table space is one or more data sets in which one or more tables
are stored.
Task Control Block (TCB) - A control block used to communicate information about
tasks within an address space that are connected to DB2. An address space can
support many task connections (as many as one per task), but only one address
space connection.
lock release
18 CACHEDYN DSN6SPRM DSNTIP4 NO , YES Save dynamic
prepared SQL
19 CACHEPAC DSN6SPRM DSNTIPP 0-2M ; Dafault is Storage allocations
32K for caching package
authorizations
20 CACHERAC DSN6SPRM DSNTIPP 0-2M ; Dafault is Storage allocations
32K for caching routine
authorizations
21 CATALOG DSN6ARVP DSNTIPA NO. YES Catalog data
22 CATALOG DSN6SPRM DSNTIPA2 DSNCAT or ICF user Catalog alias ,
catalog names of 1- cannot be updated
8 char
23 CDSSRDEF DSN6SPRN DSNTIP4 1, ANY Dafault value for
current degree of
special register
24 CHGDC DSN6SPRM DSNTIPO 1,2,3 DPROP support
25 CMTSTAT DSN6FAC DSNTIPR Active , Inactive DDF threads
26 COMPACT DSN6ARVP DSNTIPA No , YES Compact data
27 CONDBAT DSN6SYSP DSNTIPE 0-25000,64 Max remote
connected
28 CONTSTOR DSN6SPRM DSNTIPE No, YES Contract threads
working storage area
29 COORDNTR DSN6GRP DSNTIPK NO, YES Coordinate parallel
processing
30 CTHREAD DSN6SYSP DSNTIPE Acceptable values Max users
are 1 – 2000;
default is 30
31 DBPROTCL DSN6SYSP DSNTIP5 DRDA, Private Dafault protocol
32 DDF DSN6FAC DSNTIPR NO, AUTO , DB2 start up option
COMMAND
33 DEALLCT DSN6LOGP DSNTIPA 0-1439(min) , 0- Dealloc period
59(sec) ; or
NOLIMIT ; default is
0
34 DECDIV3 DSN6SPRM DSNTIPF NO, YES Min devide scale
35 DEFIXTP DSN^SPRM DSNTIPE 1,2 Dafault index type
36 DEFLTID DSN6SPRM DSNTIPP IBMUSER or auth id Unknown AUTHID
if RACF is not
available
37 DESCSTAT DSN6SPRM DSNTIPF NO, YES Build a describe
SQLDA when
building static SQL
38 DSHARE DSN6GRP DSNTIPA1 NO, YES or blank for Data sharing
upgrade
39 DSMAX DSN6SPRM DSNTIPC 1-32767 Max available open
datasets
40 DLDFREQ DSN6SYSP None 0-32767 ; dafault is Check points
5 between level ID
updates
41 DLITOUT DSN6SPRM DSNTIPI 1-254 ; default is 6 Number of resource
timeouts values
DL/1 batch
connection wiats for
lock release
42 DSSTIME DSN6SYSP DSNTIPN 1-1440; dafault is 5 Time interval in
minutes for
restarting dataset
stats for online
performance
monitors
43 EDMDSPAC DSN6SPRM DSNTIPC 1-2097152 ; dafault Size in kilobytes of
is 5 the dataspace for
the environment
description manager
pool
44 EDMPOOL DSN6SPRM DSNTIPC 1k-2097152K ; Environmental
description manager
45 EDPROP DSN6SPRM DSNTIPO 1,2,3 DPROP support
46 EXTRAREQ DSN6SYSP DSNTIPS 0-100, Default is Upper limit of extra
100 DRDA query blocks
form remote server
47 EXTRASRV DSN6SYSP DSNTIPS 0-100, Default is Upper limit of DRDA
100 query blocks to a
DRDA client
48 EXTSEC DSN6SYSP DSNTIPR NO , YES Control security
potions
49 GRPNAME DSN6GRP DSNTIPK 1-8 char , DSNCAT DB2 group name
50 HOPAUTH DSN6SPRM DSNTIP5 BOTH , RUNNER Package owner from
non DB2 server
51 IDBACK DSN6SYSP DSNTIPE Acceptable values Max batch connect
are 1 – 2000 dafault
is 20
52 IDFORE DSN6SYSP DSNTIPE Acceptable are 1-
2000 dafault is 40
53 IDTHTOIN DSN6FAC DSNTIPR 0 – 9999 Idle thread time out
54 IDXBPOOL DSN6SYSP DSNTIP1 Any $k BP name ; Default BP for user
dafault is BP0 indexes
55 INBUFF DSN6LOGP DSNTIPL 28K to 60 K Input buffer size
56 IRLMAUT DSN6SPRM DSNTIPI YES , NO Auto start for IRLM
57 IRLMPRC DSN6SPRM DSNTIPI IRLMPROC or the Proc name `
name of the IRLM
proc that MVS
invokes if RLMaoto
start = YES
58 IRLMRWT DSN6SPRM DSNTIPI 1-3600, dafault is 60 Resource time out
59 IRLMSID DSN6SPRM DSNTIPI IRLM or name of the Subsystem name
IRLM subsystem
60 IRLMSWT DSN6SPRM DSNTIPI Acceptable values Time to autostart
are 1 –3600 dafault
is 300
61 LBACKOUT DSN6SYSP DSNTIPN AUTO, YES , NO Backward log
processing
postponed
dataset or a partition
was last updated
82 POOLINAC DSN6FAC DSNTIP5 0-9999, dafault is Time in seconds a
120 database access
thread (DBAT)
remains idle in pool
before terminated
83 PRIQTY DSN6ARVP DSNTIPA Blank , clist Primary allocation
calculates using
blksize and log size
1-9999999 units
84 PROTECT DSN6ARVP DSNTIPP No , YES Archive log RACF
85 PTASKROL DSN6SYSP ------ YES, NO Roll up query
parallel task
accounting trace
records into
originating tasks
accounting records
86 QUIESCE DSN6ARVP DSNTIPA 0-999 dafault is 5 Max quiesce time
87 RECALL DSN6SPRM DSNTIPO YES ,NO Recall database
88 RECALLD DSN6SPRM DSNTIPO 0-32767 Recall delay
89 RELCURHL DSN6SPRM DSNTIP4 Yes , NO At commit release
data pages or row
lock for cursor with
hold
90 RESTART/DEFE DSN6SPRM DSNTIPS Restart /defer Restrt or defer
R processing objects
91 RESYNC DSN6FAC DSNTIPR 1,2-99 Resync interval
92 RETLWAIT DSN6SPRM DSNTIPI 0-254 dafault is0 Data sharing only ,
how long trans waits
for an incompatible
reatained lock
93 RETVLCFK DSN6SPRM DSNTIP4 No , YES Varchar retrieved
from index
94 RGFCOLID DSN6SPRM DSNTIPZ 1-8 chars dafault is Owner of
DSNRGCOL registration tables
95 RGFDBNAM DSN6SPRM DSNTIPZ 1-8 chars dafault is Name of the dbase
DSNRGFDB that contains
registration tables
96 RGFDEDPL DSN6SPRM DSNTIPZ No , YES DB2 subsystem
controlled by a
closed application
thru registration
97 RGFDEFTL DSN6SPRM DSNTIPZ ACCEPT, REJECT , Action for
APPL unregistered DDL
98 RGFESCP DSN6SPRM DSNTIPZ Any non alpha ART/ORT escape
numeric char char
99 RGFFULLQ DSN6SPRM DSNTIPZ Yes, NO Registered object
require fully qualified
names
100 RGFINSTL DSN6SPRM DSNTIPZ No , YES Install data
definition control
support
101 RGFNMORT DSN6SPRM DSNTIPZ 1-17 char Name of the object
DSN_REGISTER_OBJ registration table
T
102 RGFNMPRT DSN6SPRM DSNTIPZ 1-17 Char Name of the
DSN_REGISTER_APP application
L registration table
103 RLF DSN6SYSP DSNTIPO NO , YES RLf Auto start
104 RLFAUTH DSN6SYSP DSNTIPP SYSIBM or the auth Resource AUTHID
Id used if RLF is
automatically
started
105 RLFERR DSN6SYSP DSNTIPO NOLIMIT , NORUN , RLST access error
1-50000
106 RLFERRD DSN6FAC DSNTIPR NOLIMIT , NORUN , RLST access error
1-50000
107 RLFTBL DSN6SYSP DSNTIPO 01 or any 2 alpha RLST name suffix
numeric chars
108 ROUTCDE DSN6SYSP DSNTIPI 1 or 1-14 route WTO route codes
codes with values
from 1 to 16
109 RRULOCK DSN6SPRM DSNTIPI No , YES Use page level U
(Update ) locks
when using RR
isolation
110 SECQTY DSN6ARVP DSNTIPA Blank – clist Secondary space
calculates using allocation
blksize and logsize
1-9999999 units
111 SEQCACH DSN6SPRM DSNTIPE BYPASS , SEQ Use 3990 – 3 seq
cache
112 SEQPRES DSN6SPRM DSNTIPE No , YES For utility scanning
non partition indexes
followed by update
to keep data in 3990
cache longer when
reading data
113 SITETYP DSN6SPRM DSNTIPO LOCALSITE or Location of current
RECOVERYSITE system
114 SMFACCT DSN6SYSP DSNTIPN 1 or NO , YES SMF accounting
( Class 1) list of
classes ( 1-5 , 7 ,8 )
, or *
115 SMFSTAT DSN6SYSP DSNTIPN YES , NO SMF Stats
116 SRTPOOL DSN6SPRM DSNTIPC 240K-64000K Sort pool size
dafault is 1MB
117 STATIME DSN6SYSP DSNTIPN 1-1440min dafault Stats time
is 30
118 STORMXAB DSN6SYSP DSNTIPX 0-255 dafault is 0 Maximum abend
count
119 STORPROC DSN6SYSP DSNTIPX 1-8 chars dafault is MVS procedure
ssnSPAS name
ISOLATION (CS)
VALIDATE (BIND)
ACTION (REPLACE)
SQLERROR (NOPACKAGE)
FLAG (I)
ACQUIRE (USE)
RELEASE (COMMIT)
DEGREE (ANY)
CURRENTDATA (NO)
EXPLAIN (YES)
S U X IS IX SIX
S Y Y N Y N N
U Y N N Y N N
X N N N N N N
IS Y Y N Y Y Y
IX N N N Y Y N
SIX N N N Y N N
S U X
S Y Y N
U Y N N
X N N N
| | relying on LE/370 to |
| | handle that. |
|_______________________|________________________|
| You can access | You can access |
| non-relational data, | non-relational data. |
| but that data is not | If the non-relational |
| included in your SQL | data is managed by |
| unit of work. It is a | OS/390 RRS, the |
| separate unit of | updates to that data |
| work. | are part of your SQL |
| | unit of work. |
|_______________________|________________________|
| Stored procedures | Stored procedures can |
| access protected MVS | access protected MVS |
| resources with the | resources with the SQL |
| authority of the | user's RACF authority. |
| stored procedures | |
| address space. | |
|_______________________|________________________|
IDENTIFICATION DIVISION.
PROGRAM-ID. BKSPPOS1.
AUTHOR. INFOSYS.
DATE-WRITTEN. 08-14-2001.
DATE-COMPILED.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PROGRAM-WS-START PIC X(50) VALUE
'*** BKSPPOS1 WORKING STORAGE STARTS HERE ***'.
01 WS-WORK-FIELDS.
05 WS-PRSHG-ACCT-OFC-CD PIC X(03) VALUE SPACES.
05 WS-PRSHG-ACCT-NUM PIC X(06) VALUE SPACES.
01 WS-MESSAGE PIC X(80).
88 WS-MSG-1 VALUE
'CURSOR OPEN FAILED IN BKSPPOS1 !'.
88 WS-MSG-2 VALUE
'INVALID INPUT PARAMETERS !'.
88 WS-MSG-3 VALUE
'NO MATCHING RECORDS FOUND !'.
88 WS-MSG-4 VALUE
'CURSOR OPEN SUCCESSFUL!'.
88 WS-MSG-5 VALUE
‘VALIDATION OF INPUT VALUES FAILED!’
******************************************************************
* COPYBOOK AREA
*
******************************************************************
/
COPY SQLCODES.
******************************************************************
* DCLGEN AREA
*
******************************************************************
/
EXEC SQL INCLUDE SQLCA END-EXEC.
/
* DCLGEN FOR TB_AC_ACCT
EXEC SQL INCLUDE TBACACCT END-EXEC.
/
******************************************************************
* CURSOR DECLARATION FOR INSTR-QTY CURSOR
*
******************************************************************
EXEC SQL DECLARE INSTR_QTY_CSR CURSOR WITH RETURN FOR
SELECT
TB_AC_SUBACCT_PSTN.SUBACCT_CD,
TB_AC_SUBACCT_PSTN.SETTLE_DATE_QTY,
TB_AC_SUBACCT_PSTN.TRADE_DATE_QTY
FROM
TB_AC_SUBACCT_PSTN, TB_AC_ACCT
WHERE
TB_AC_ACCT.PRSHG_ACCT_OFC_CD =
:DCLTB-AC-ACCT.PRSHG-ACCT-OFC-CD AND
TB_AC_ACCT.PRSHG_ACCT_NUM =
:DCLTB-AC-ACCT.PRSHG-ACCT-NUM AND
TB_AC_ACCT.ACCT_ID =
TB_AC_SUBACCT_PSTN.ACCT_ID AND
TB_AC_SUBACCT_PSTN.TRADE_DATE_QTY <> 0 AND
END-EXEC.
/
LINKAGE SECTION.
COPY BKCPPOS1.
******************************************************************
* PROCEDURE DIVISION STARTS HERE
*
******************************************************************
/
PROCEDURE DIVISION USING BKSPPOS1-INPUT-AREA
BKSPPOS1-OUTPUT-AREA.
0001-MAIN.
PERFORM 1000-INITIALIZE
THRU 1000-INITIALIZE-EXIT
PERFORM 1500-CHECK-INPUT
THRU 1500-CHECK-INPUT-EXIT
PERFORM 2000-OPEN-CURSOR
THRU 2000-OPEN-CURSOR-EXIT
MOVE SQLCODE TO BKSPPOS1-SQLCODE
PERFORM 3000-EXIT-ROUTINE
THRU 3000-EXIT-ROUTINE-EXIT
.
0001-MAIN-EXIT.
EXIT
.
******************************************************************
* INTIALIZES VARIABLES USED IN THE PROGRAM
*
******************************************************************
1000-INITIALIZE.
INITIALIZE BKSPPOS1-OUTPUT-AREA
SET BKSPPOS1-STATUS-OK TO TRUE
.
1000-INITIALIZE-EXIT.
EXIT
.
/
******************************************************************
* VALIDATES THE INPUT PARAMETERS
*
******************************************************************
1500-CHECK-INPUT.
MOVE BKSPPOS1-PRSHG-ACCT-OFC-CD TO
PRSHG-ACCT-OFC-CD OF DCLTB-AC-ACCT
MOVE BKSPPOS1-PRSHG-ACCT-NUM TO
PRSHG-ACCT-NUM OF DCLTB-AC-ACCT
EXEC SQL
SELECT
ACCT_ID
INTO
:DCLTB-AC-ACCT.ACCT-ID
FROM
TB_AC_ACCT
WHERE
PRSHG_ACCT_OFC_CD = :DCLTB-AC-ACCT.PRSHG-ACCT-OFC-CD
AND
PRSHG_ACCT_NUM = :DCLTB-AC-ACCT.PRSHG-ACCT-NUM
END-EXEC
EVALUATE SQLCODE
WHEN 0
CONTINUE
WHEN -811
CONTINUE
WHEN +100
SET WS-MSG-2 TO TRUE
PERFORM 3000-EXIT-ROUTINE
THRU 3000-EXIT-ROUTINE-EXIT
WHEN OTHER
SET WS-MSG-5 TO TRUE
PERFORM 3000-EXIT-ROUTINE
THRU 3000-EXIT-ROUTINE-EXIT
END-EVALUATE
.
1500-CHECK-INPUT-EXIT.
EXIT
.
/
******************************************************************
* OPEN THE INSTR_QTY_CSR CURSOR
*
******************************************************************
2000-OPEN-CURSOR.
EXEC SQL
OPEN INSTR_QTY_CSR
END-EXEC
EVALUATE SQLCODE
WHEN +0
SET BKSPPOS1-STATUS-OK TO TRUE
SET WS-MSG-4 TO TRUE
WHEN +100
SET BKSPPOS1-NOT-FOUND TO TRUE
SET WS-MSG-3 TO TRUE
WHEN OTHER
SET BKSPPOS1-ERROR TO TRUE
SET WS-MSG-1 TO TRUE
PERFORM 3000-EXIT-ROUTINE
THRU 3000-EXIT-ROUTINE-EXIT
END-EVALUATE
.
2000-OPEN-CURSOR-EXIT.
EXIT
.
******************************************************************
* THIS PARA PERFORMS THE EXIT ROUTINE
*
******************************************************************
3000-EXIT-ROUTINE.
MOVE WS-MESSAGE TO BKSPPOS1-ERROR-MSG
.
3000-EXIT-ROUTINE-EXIT.
GOBACK
.