v7p151-217
DESCRIPTION
sapTRANSCRIPT
Data MaintenanceTopics
Export/Import
Export/Import of Structured Type
Load
Constraints/Integrity Checking
Data Maintenance Commands
151
Data MaintenanceSET INTEGRITY Command(Also known as SET CONSTRAINTS)
Use to turn on or off integrity checking for one or more tables. Integrity checking options.
Foreign key. Check.
Summary and Datalink Reconcile Pending - not covered here. All
SET INTEGRITY command options. INCREMENTAL
Force incremental constraint checking on the appended portion of data or summary table refresh processing.Even if option not specified, incremental processing is default. Error message returned if full processing needed.
IMMEDIATE CHECKED Integrity checking turned on and carry out deferred integrity checking.
IMMEDIATE UNCHECKED Integrity checking turned on and deferred integrity checking is not performed.Can also check one type of integrity and leave in check pending state.
152
Data MaintenanceConstraint Maintenance
Maintain CONSTRAINT incrementally SET INTEGRITY .. IMMEDIATE CHECKED
SET INTEGRITY ..IMMEDIATE CHECKED
LOAD INSERT
FOREIGN KEY
CHECK CONSTRAINT
TABLE
NORMAL
FOREIGN KEY
CHECK CONSTRAINT
TABLE
CHECK PENDING
If possible..Only appended portion is checked
Whole table is checked
If not possible..(Default behavior)
(new foreign key or constraint added while in check pending)
SET INTEGRITY .... IMMEDIATE CHECKED
153
Data MaintenanceConfirm CHECK PENDING status
CONST_CHECKED columns of SYSCAT.TABLES"Y" and "U" mean table validated, but it can be in CHECK PENDING
Value Description
Y Checked by SYSTEM
N Not checked ( In CHECK PENDING)
U Checked by USER (as a result of SET INTEGRITY ...IMMEDIATE UNCHECKED)
W Previously checked by USER and some data needs to be verified by SYSTEM ( In CHECK PENDING)
db2 "select tabname,status,CONST_CHECKED from SYSCAT.TABLES
TABNAME STATUS CONST_CHECKED TABLE1 N YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
FOREIGN KEY
CHECK CONSTRAINT
SUMMARY TABLE
154
CONST_CHECKED columns of SYSCAT.TABLES is used to confirm whether the table is validated or not.
VALIDATED state of a table:A table must be validated if it is not in check pending. When in check pending, a table can be either validated or not validated.When we check the constraints for a child table, all parent tables must have been validated. Similarly, when we refresh a summary table, all its underlying table must have been validated. After a table has been validated, we can take it out of check pending without doing any further constraint checking; if the table is a summary table, it can be taken out of check pending without doing any further refresh
Data MaintenanceCheck Pending Notes
155
Data MaintenanceTopics
Export/Import
Export/Import of Structured Type
Load
Constraints/Integrity Checking
Data Maintenance Commands
156
Data Maintenance Process
Rebind
ApplicationExecution
Rebind
ReorgchkRunstats
Reorg needed?
YESNO
Reorg
Runstats
157
Data MaintenanceRUNSTATS Utility
Updates statistics about the physical characteristics of a table and the associated indexes.RUNSTATS ON TABLE <table-name>
You can specify table and/or indexesIf requested distribution statistics can be collected based on database configuration parametersShare Level (SHRLEVEL) can be set
Change - other users can read & write to tableReference - other users have read-only access
For row types, table-name must be the name of the hierarchy's root table.
>>-RUNSTATS ON TABLE--table-name--------------------------------> >-----+-+--------------------------------------------------------------------+-+> | '-WITH DISTRIBUTION--+--------------------------------------------+--' | | '-AND--+----------+--+-INDEXES ALL--------+--' | | '-DETAILED-' '-INDEX--index-name--' | '-+--------------------------------------------------+-------------------' '--+-AND-+---+----------+--+-INDEXES ALL--------+--' '-FOR-' '-DETAILED-' '-INDEX--index-name--' >-----+--------------------------+----------------------------->< | .-CHANGE----. | '-SHRLEVEL--+-REFERENCE-+--'
158
Data MaintenanceREORGCHK Utility
REORGCHK ON TABLE db2.candidateTable statistics:F1: 100*OVERFLOW/CARD < 5F2: 100*TSIZE/((FPAGES-1) * 4020) > 70F3: 100*NPAGES/FPAGES > 80CREATOR NAME CARD OV NP FP TSIZE F1 F2 F3 REORGDB2 CANDIDATE 3 0 1 1 27 0 - 100 - - -
Index statistics:F4: CLUSTERRATIO or normalized CLUSTERFACTOR > 80F5: 100*(KEYS*(ISIZE+10)+(CARD-KEYS)*4)/(NLEAF*4096) > 50F6: 90*(4000/(ISIZE+10)**(NLEVELS-2))*4096/ (KEYS*(ISIZE+10)+(CARD-KEYS)*4) <100CREATOR NAME CARD LEAF LVLS ISIZE KEYS F4 F5 F6 REORGTable: DB2.CANDIDATESYSIBM SQL960226095048000 3 1 1 9 3 100 - - - - -
REORGCHK calculates statistics obtained from six different formulas to determine if performance has deteriorated or can be improved by reorganizing a table. Can update statistics on all or subset of tables.
159
Data MaintenanceREORG Utility
Reorganizes a table by reconstructing the rows to eliminate fragmented data, and by compacting information. Can reorganize table based on index.
REORG TABLE db2.candidateMust use qualified table name or aliasIf an index is specified you must use fully qualified index nameTemporary space allocated in tablespace where table resides (default). Can temporary tablespace if the table is very largeIf REORG fails DO NOT DELETE the temporary files
>>-REORG TABLE--table-name----+--------------------+------------> '-INDEX--index-name--' >-----+-----------------------+-------------------------------->< '-USE--tablespace-name--'
160
Data MaintenanceREBIND Utility and db2rbind
Allows the user to recreate a specific package stored in the
database without the need for a bind file. Must use qualified package name or it will assume the current authorization ID.Does not automatically commit unless auto-commit is enabled
Provides a quick way to recreate a package
db2rbind command will rebind all packages in database.
>>-REBIND-+---------+--package-name---------------------------->< '-PACKAGE-'
>>-db2rbind--database--/l logfile----+------+-------------------> '-all--'>-----+-------------------------+------------------------------>< '-/u userid--/p password--'
161
Database Recovery Topics
LoggingBACKUP and RESTORE utilitiesDatabase Recovery including Roll ForwardRecovery history file
162
Database RecoveryRecovery Types
Crash/Restart RecoveryUses the RESTART DATABASE command or the automatic restart enable configuration parameter (autorestart) to protect a database from being left in an inconsistent, or unusable, state.
Version/Image RecoveryUses the BACKUP command in conjunction with the RESTORE command to put the database in a state that was previously saved. Used for non-recoverable databases or databases for which there are no archived logs.
Rollforward RecoveryUses the BACKUP command in conjunction with the RESTORE and ROLLFORWARD commands to recover a database or table space to a specified point in time.
163
Database RecoveryLog File Usage
Logs keep record of all changes made to database objects and data... maximum 32 gigabytes in V7.1All changes written to log buffers in memory before being flushed to disk. Logs can be written to raw devices. Rollback ... Uses log files to terminate a unit of work and back out any changes
Crash RecoveryConsists of 2 phases
Reapply all transactions (regardless of commit)
Rollback changes NOT committed
DB config parameter AUTORESTART (default ON)
Roll Forward Recovery Command can be applied to DB or Table space - Minimum Point In Time (PIT) for table spaces
Recoverable vs. Non-Recoverable DatabasesOnline vs. Offline usage and minimum recovery timedb2ckbkp utility
164
Database RecoveryTransaction Log File Use
Example of three processes accessing and changing data. Process 2, Transaction E performs a rollback. DB2 will begin using a second log file (y) when the first (x) becomes full.
TIME
Transaction F
Transaction C Process 3
Transaction B Transaction E Process2
Transaction A Transaction D Process 1
A B C A B C A B ACTIVE
D C E F D E E F D D
Log file x
Log file y
databasedisk files
Com
mit
Com
mit
Com
mit
Com
mit
Com
mit
Rol
lbac
k
165
Database RecoveryWhat makes up logging
Log Control File (SQLOGCTL.LFH)Log BuffersPhysical log filesLog files Database configuration fileWAIT! What about Not Logged Initially??
166
Database RecoveryCircular Logging
PRIMARY
SECONDARY
1
"n" 2
3
1 "n"
Default logging method DB2 UDB. Primary log files used to record all changes; reused when changes are committed. Secondary log files allocated when limit of primary log files reached. Crash and version recovery possible; roll-forward recovery not possible.Will get an error when reach limit of secondary logs or run out of hard drive space.
167
Database RecoveryArchival Logging/Log Retention
ONLINE ARCHIVE -Contains informationfor committed andexternalized transactions.Stored in the ACTIVElog subdirectory.
OFFLINE ARCHIVE -Archive moved fromACTIVE log subdirectory.(May also be on other media)
12
13
14
15
16
Manual orUser-exit
ACTIVE - Containsinformation fornon-committed or non-externalizedtransactions
Enabled with LOGRETAIN parameter. Log files not deleted - kept online or offline. USEREXIT routine needed to move archived log files to secondary storage (e.g. tape). - samples provided. Roll forward recovery and on-line backup possible.
168
Database RecoveryHow are retained logs handled
With log retention, all logs will be kept in the log path unless userexits are enabled or they are moved manually.
Userexits are used to archive the log files to another path/drive.
Logs will be archived once they are full.
They will be marked as "reusable" once they are no longer required for restart / recovery.
After an online backup is complete, DB2 will now close the current active log. This operational enhancements makes it easier to ensure that the online backup has the necessary archived logs necessary for recovery.
169
Database RecoveryUserexits
The userexit will be called by the DB2 system controller for every log file:
Will be called as soon as the log file is full
When the log file is no longer required for restart / recovery DB2 will mark the log file as "reusable"
Any time after this point the log file can be renamed to one of the new (higher numbered) log files.
During roll forward, userexit may be called to get the log file if it is not in the current log path.
Only done for full database restore, not table space
Sample userexits included with DB2 - can be modified for any installation.
170
Database MaintenanceBackup Utility
SYSADMSYSCTRLSYSMAINT
DB2DB
REMOTE
LOCAL -or-
*REFERENCE?
(backbufsz, command option)
-or-
3rd party such as TSM, Veritas, etc.
Creates a backup copy of a database or a table space.Off-line and on-line backups supported. Commands can be issued from Command Prompt or Control Center
BACKUP DATABASE DB2CERT TO /dev/rmt0 WITH 2 BUFFERS BUFFER 512 PARALLELISM 2
171
Database RecoveryBackup Files
File name for images on disk or diskette contains:database aliastype of backup (0=FULL, 3=TS, 4=LOAD Copy file)instance namedatabase node (always 0 for non EEE)timestamp of backupsequence number
Exact naming convention varies slightly by platform.Tape images are not named, but contain the same information in the backup header for verification purposes.Backup History provides key information in easy to use format.
172
Database RecoveryBackup File Name
DBALIAS.0\DB2INST.0\19960314\131259.001
Alias Instance Year Day Minute Sequence
Type Node Month Hour Second
DBALIAS.0.DB2INST.0.19960314131259.001
Alias Instance Year Day Minute Sequence
Type Node Month Hour Second
Intel
UNIX
173
Database RecoveryRestoring a Backup Image
BACKUP
EXISTS DELETE TABLE, INDEX, LONG FIELD FILES
RETAIN AUTHENTICATION
RETAIN DATABASE DIRECTORIES
REPLACE TABLE SPACE ENTRIES
RETAIN HISTORY
CHECK DATABASE SEED
NEW
CREATE NEW DATABASE
RESTORE AUTHENTICATION
RESTORE DATABASE CONFIGURATION FILE
SET DEFAULT LOG PATH
RESTORE COMMENTS
RESTORE DATABASE DB2CERT FROM C:\DBBACKUP WITHOUT ROLLING FORWARD WITHOUT PROMPTING
Rebuilds a database or tablespace that has been backed up using BACKUP command. Can issue either from command line or from Control Center.
174
Database RecoveryRedirected Restore
EXAMPLERESTORE DATABASE DB2CERT FROM C:\DBBACKUP INTO NEWDB REDIRECT WITHOUT ROLLING FORWARD
SQL1277N Restore has detected that one or more table space containers are inaccessible, or has set their state to 'storage must be defined'.DB20000I The RESTORE DATABASE command completed successfully.
SET TABLESPACE CONTAINERS FOR 0 USING (FILE "d:\newdb\cat.dat" 5000)SET TABLESPACE CONTAINERS FOR 1 USING (PATH "d:\newdb2")
RESTORE DATABASE DB2CERT CONTINUE
Can redefine or redirect tablespace containers during restore. Record of tablespace containers is kept during backup. If containers not available during restore, new containers can be specified. Database restore command issued twice. Use REDIRECT parameter on RESTORE command and SET TABLESPACE CONTAINERS command.
175
Database RecoveryRollforward Database
During rollforward processing, DB2 will: Look for the required log file in the current log path.
If found, reapply transactions from the log file.
If log file is not found in the current path, the userexit is called to retrieve the log file from the archive path.
The userexit will only be called to retrieve the log file if you are rolling forward through a full database restore. If rolling forward through a table space restore, you must specify the overflow logpath parameter or manually move the files back to the active log path.
Once the log is in the current log path, the transactions will be reapplied.There are sample userexits included with DB2 UDB which can be modified for the particular installation.
176
Database RecoveryRestore Considerations
Need SYSADM, SYSCTRL, or SYSMAINT authority to restore to existing database; SYSADM or SYSCTRL to restore to a new database.
Restore only works with images taken with the Backup command on the same operating system.
Restore does work with external storage managers like the Tivoli Storage Management Solutions (ADSM).
Restore takes exclusive connection to database.
Database can be local or remote.
177
Database RecoveryOnline backup considerations
Log Flush during ONLINE backupAfter an online backup is complete, DB2 "forces" the currently active log file to be closed and as a result it will be archived off (remember this is an online backup).This ensures that your online backup has a complete set of archived logs available for recovery,This can reduce log management requirements during online backups.
178
Database RecoveryTable Space Backup/Recovery
EXAMPLEBACKUP DATABASE DB2CERT TABLESPACE (SYSCATSPACE,FILETS) TO C:\DBBACKUP
RESTORE DATABASE DB2CERT TABLESPACE (FILETS) ONLINE FROM C:\DBBACKUP
Table Space recovery requires a recoverable database (retention logging or a userexit be enabled) as the table space must be rolled forward to a minimum Point In Time (PIT).
Minimum PIT ensures the table space agrees with what is in the system catalogs.
Rest of database and table spaces accessible during restore of particular table space.
179
Database Recovery Table Space Recovery
Units of Work1
23
4
Crash
RESTORETable Space(s)
Log-Files
n active logs
n archived logs
Logging
ROLLFORWARDchanges in logs
Point of Consistency
time
Active/ucommitted UoW's are rolled back
BACKUPTable space
Image
Backup Table space(s)
Can now rollforward to a minimum PIT
Log retain and/or a userexit must be enabled. Restore database then use ROLLFORWARD command to bring table space to desired PIT.
180
Database RecoveryTable space - OFFLINE (1)
CTNR
CTNR
TBS1
CONNECT /ACTIVATE
BACKUP_PENDING(Before)
BACKUP_PENDING + OFFLINE(After)
CTNR
CTNR
TBS1
CONNECT /ACTIVATE
OFFLINE(After)
NORMAL(Before)
Example 1: Example 2:
What is OFFLINE table space state?If container not accessible, table space placed in OFFLINE state.Benefits
If you can correct the problem, table space can be made available.Allows you to connect to database even if circular logging is used.
181
V5CIRCULARLOGGING
TBSCONNECT
NO
V6/7CIRCULARLOGGING
TBSCONNECT
OKOFFLINE
Database RecoveryTable Space OFFLINE (2)
Allow connection to be made when table space is damaged even if CIRCULAR LOGGING is used
If only temporary table space damaged, you can create new one after connecting to database. Then the bad one can be dropped.
182
Database RecoveryBackup & Recovery Considerations
Full Database Backup off-line
Full Database Backup off-line
Full Database Backup on-line
Table Space
Backup off-line
Table Space
Backup on-line
Logging Type Archival Circular Archival Archival Archival
Access allowed during Backup
N/A N/A Full None Full
Database state after
restore
Rollforward Pending Consistent Rollforward
PendingTS inRFPending
TS in RF Pending
Rollforward Required
Any Point in Time
after backup
N/A
Any Point in Time
past backup
Min PIT Min PIT
183
Database RecoveryRecovery History File
Created with each database and is automatically updated whenever there is a:
Backup of a database or table space Restore of a database or table space Roll forward of a database or table space Alter of a table space Quiesce of a table space Load of a table Drop a table Reorganization of a table Update of table statistics.
Can use the summarized backup information to recover all or part of the database to a given point in time.Size of the file is controlled by the rec_his_retentn configuration parameter.
Specifies a retention period (in days) for the entries in the file.
Can execute commands against file. OPEN, CLOSE, GET NEXT, UPDATE, and PRUNE
184
Database RecoveryDropped Table Recovery
Permits recovery of accidentally dropped tables.Requires setting DROPPED TABLE RECOVERY option on table space "prior" to table being dropped.Will need to restore database or table space to recover dropped table. DDL for dropped table is stored in Recovery History File.
Extract using the LIST HISTORY DROPPED TABLES command.
Involves generating a 'loadable' image of the table and then loading delimited ASCII data back into table. Image is generated by:
Stopping during roll forward at point in time table was dropped. Exporting table data to file(s). Continuing roll forward to end of logs. Recreate the table. Import the data.
NOTE: Triggers, summary tables, unique constraints, referential constraints, and check constraints not recovered - must be manually reapplied.
185
The sections we are going to be covering for the Database Administration component today include:
DB2 Server Management - DONEData Placement - DONEDatabase Access - DONEDatabase Maintenance and Recovery - DONEMonitoring DB2 Activity and Problem Determination - NEXT
ALMOST DONE!
Database Administration
186
Use the EXPLAIN facilityUse the DB2 monitors:
SNAPSHOT monitor
EVENT monitor
Use the Graphical Performance ToolsEvent Analyzer/Monitor
Performance Monitor
Understand Performance issues and diagnostics
Database Monitoring and TuningTopics
187
Database Monitoring and TuningSuggested Process
Monitoring and tuning a DB should be done in steps:Define the objectives
What is wrong or what do you want to accomplish
Determine information to be analyzedDetermine the monitor(s) to be usedObtain monitor data Analyze the information Determine the changes requiredImplement changes (one at a time)
188
Cost based optimizer. Will use current statistics to determine how to retrieve data (i.e. access plan).Very important to keep statistics up to date.
Use RUNSTATS command will accomplish this. REORGCHK command can also invoke RUNSTATS.Do RUNSTATS (or REORGCHK .. tables system) on system catalog tables.
Optimizer has a "throttle" to control how much optimization is done during access plan generation.
Parameter is DFT_QUERYOPT. Range is 0 - 9.In general, 5 is good for OLTP applications and/or static SQL. In general, 3 or less is good for OLAP, data warehouse, and/or dynamic SQL.
Optimizer has ability to rewrite SQL statement to improve performance.
Result set is the same as original SQL, just produced faster.Use Explain tool to see rewritten SQL statement.
Database Monitoring and TuningDB2 UDB Optimizer Characteristics
189
Database Monitoring and TuningQuery Compilation
Parse Query
Check Semantics
Rewrite Query
Optimize Access Plan
Generate Executable Code
QueryGraphModel
SQL COMPILER
Execute Plan
Explain TablesExecutable
Plan
db2expln
AccessPlan
Remote SQL Generation
Pushdown Analysis
db2exfmtTool
VisualExplain
Seven step process to compile SQL statement.
190
Database Monitoring and TuningMonitoring Facilities
DB2 provides different facilities for monitoring the your SQL, databases, and activity.
The main tools available are the:Explain Facility
Visual explain (graphical LOB data stored in EXPLAIN tables)Text explain (db2expln, dynexpln, db2exfmt)
Snapshot MonitorEvent MonitorPerformance Monitor
191
Database Monitoring and TuningWhat is "Explain"?
Facility to capture detailed information about the access plan chosen by the SQL compiler to resolve an SQL statement.
Both static and dynamic SQL are supported.All elements of SQL processing are captured - table access, index access, joins, unions, scans, etc.
Timing information called "Timerons" is captured for each processing step.
Timerons are a unit of measurement used to give a rough relative estimate of the resources, or cost, required by the database server to execute two plans for the same query. The resources calculated in the estimate include weighted CPU and I/O costs.
Access plan information captured in seven DB2 tables.Tables created automatically or by executing EXPLAIN.DDL script in the Command Line Processor.
Information can be analyzed through text or GUI based tools. GUI: Visual Explain & Text: db2expln, dynexpln, or db2exfmt
192
Database Monitoring and TuningExplain Tables
Several tables used to provide access plan information:EXPLAIN_ARGUMENT - unique characteristics for each individual operatorEXPLAIN_INSTANCE - main control table for explainEXPLAIN_OBJECT - objects required by access plan(tables, indexes etc.)EXPLAIN_OPERATOR - operators needed by access plan(table/index scans)EXPLAIN_PREDICATE - matches predicates to operatorsEXPLAIN_STATEMENT - text of the statement(original & rewritten)EXPLAIN_STREAM - data flows within the query
Created automatically by Control Center or by executing EXPLAIN.DDL script in the Command Line in DB2
193
Database Monitoring and TuningGathering Explain Data
There are 4 general methods of populating the Explain tables:
EXPLAIN StatementThe information gathered is dependent on invocation
CURRENT EXPLAIN MODE Special RegisterGather information on dynamic SQL
CURRENT EXPLAIN SNAPSHOT Special RegisterGather explain snapshot data for dynamic SQL
BIND optionsGather information during the bind process
194
Database Monitoring and TuningExplain Statement
EXPLAIN ALL WITH SNAPSHOT FOR "SELECT *
FROM STAFF"
SNAPSHOT
SNAPSHOT
SNAPSHOT
SNAPSHOT
WITH SNAPSHOTexplain tables fully populated
SNAPSHOT
FOR SNAPSHOTonly snapshot populated
Default no snapshot
Good if you need information on one SQL statement. Will end up populating all or subset of Explain tables.
195
Database Monitoring and TuningExplain Special Register
Can set interactively or can embedded in dynamic SQL program.
There are 2 special Registers:
EXPLAIN MODE (only explain data populated)EXPLAIN SNAPSHOT (full explain plus snapshot)
NO - Information is not gathered
YES - tables populated during execution of all stmts until register set to NO.EXPLAIN - tables populated without execution
Options For EXPLAIN MODE only:RECOMMEND INDEXES and EVALUATE INDEXESUsed by Index Advisor
SET CURRENT EXPLAIN MODE [ NO | YES | EXPLAIN ]SET CURRENT EXPLAIN SNAPSHOT [ NO | YES |
EXPLAIN ]
196
DB2 Monitoring and TuningExplain BIND Options
There are 2 BIND options:EXPLAIN (only explain info)EXPLSNAP (full explain plus snapshot)
NO - Information is not gatheredYES - static SQL information gatheredALL - static & dynamic SQL information gathered
BIND package EXPLAIN [ NO | YES | ALL ]BIND package EXPLSNAP [ NO | YES | ALL ]
197
DB2 Monitoring and TuningExamining Explain Data - Text Tools
There are three text-based utilities for EXPLAIN information:
dynexpln - Dynamic SQL access plan information
db2expln - Static SQL access plan information
db2exfmt - Static and Dynamic SQL access plan information.
198
DB2 Monitoring and TuningExamining Explain Data - Graphically
GUI tool is called Visual Explain. Presents access plan in a tree like structure. Visual Explain can only display access plans "explained" (i.e. generated) with the "snapshot" option. There are two ways to invoke Visual Explain:
Control Center Explained statements history
All explained statements will be shown but only those that created with SNAPSHOT can be examined with VISUAL EXPLAIN.
EXPLAIN SQL... good for a single SQL statement
Command Center Choose "Statement" and select "EXPLAIN".
199
DB2 Monitoring and TuningSnapshot Monitors
Provides cumulative information in the form of resetable counters. Monitors set by switches at the instance or application level.
Use UPDATE DBM CONFIGURATION or UPDATE MONITOR SWITCHES commands in a session.Instance level switches affect all databases in the instance.
Can view Monitor information with GET SNAPSHOT command or through APIs. Provide information at a Point-in-time.Amount of data returned depends on level.
Database managerDatabaseApplication BufferpoolsTablespaceTableLockDynamic SQL
200
DB2 Monitoring and TuningSnapshot Monitors
Group Info provided Switch DBM Parm
DFT_MON_
Sortsnumber of heaps used, overflows, sorts, performance
SORT SORT
Locks number of locks held, number of deadlocks LOCK LOCK
Tables measure activity on table(rows read, rows written) TABLE TABLE
Buffer Pools
number reads and writes,time taken
BUFFERPOOL BUFPOOL
UOW start/end times andcompletion status UOW UOW
SQL start/stop time statement identification
STATEMENT STMT
201
DB2 Monitoring and TuningEvent Monitors
Provide Information About a State ChangeNo SwitchesAUTOSTART or MANUALSTART
Event Type Description When
DATABASE Database summary information Last application disconnects
CONNECTIONS Connection summary information Every application disconnects
TABLE Table summary information Table application disconnects
STATEMENTS SQL Statement information Each SQL statement
TRANSACTIONS Transaction summary information COMMIT or ROLLBACK time
DEADLOCKS Deadlock Information When a deadlock occurs( -911)
TABLESPACES Table space summary information Last application disconnects
202
DB2 Monitoring and TuningEvent Monitor Interface
Event Monitor Definitions Stored in CatalogsSYSCAT.EVENTMONITORSSYSCAT.EVENTS
Authorization - DDLSYSADM or DBADM
CREATE EVENT MONITORSET EVENT MONITOR event-monitor name STATE = 0|1DROP EVENT MONITOR event-monitor-name
Can Define Unlimited Number of Event MonitorsMaximum of 32 Active Event Monitors
Which Event Monitors Are Active?Select monitor from SYSCAT.EVENTMONITORS table. Use the SQL Function EVENT_MON_STATE (event-monitor-name)
203
DB2 Monitoring and TuningExamine Monitoring Output
How do I examine event monitor output?Write an application to read file to pipe outputUse db2evmon from command promptdb2eva from command prompt or invoked from Control Centerdb2emcrt - a GUI tool which views reports
Data Element TypesCounter - # of times an activity occursGauge - Current ValueHighest - High Water MarksInformation - Reference InformationTimestamp - Time of Event
204
DB2 Monitoring and TuningDB2 Performance Monitor
Event Analyzer
Snapshot Monitor
Performance Monitor
Graphical tool that provides information about the state of DB2 Universal Database and the data that it controls.Access from DB2 UDB Control Center.Monitor objects like instances, databases, tables, table spaces, and connectiGood for overall view of database performance.
205
DB2 Monitoring and TuningDB2 Performance Monitor
Performance variable details
Color coded performance thresholds
206
MAXAGENTS (maximum number of agents)Maximum number of database manager agents available at any given time to accept application requests. This value limits the memory usage of the instance, because each additional agent requires additional memory.
NUM_POOLAGENTS (agent pool size)A guideline for how large you want the agent pool to grow. If more agents are created than is indicated by the value of this parameter, they will be destroyed when they finish executing their current request.
NUM_INITAGENTSParameter determines the initial number of idle agents that are created in the agent pool at DB2START time.
DB2 Monitoring and TuningParameters to consider
207
BUFFPAGE (buffer pool size)Controls the default size of a buffer pool if CREATE or ALTER BUFFERPOOL was run with NPAGES -1.
CATALOGCACHE_SZ (catalog cache size)Indicates the maximum amount of space that the catalog cache can use from the database heap. Its used to store table descriptor information that is used during compilation of an SQL statement.
LOGBUFSZ (log buffer size)Specifies the amount of the database heap to use as a buffer for log records before writing these records to disk.
LOCKLIST (maximum storage for lock list)Indicates the amount of storage that is allocated to the lock list. There is one lock list per database and it contains the locks held by all applications concurrently connected to the database.
MAXLOCKS (maximum locks per application)This defines a percentage of the lock list held by an application that must be filled before the database manager performs escalation.
DB2 Monitoring and TuningParameters to consider
208
PCKCACHESZ (package cache size)Allocated out of the database global memory and used for caching static and dynamic SQL statements on a database. One package cache for each database node.
CHNGPGS_THRESH (changed pages threshold)Specifies the level (percentage) of changed pages at which the asynchronous page cleaners will be started, if not currently active.
NUM_IOCLEANERS (number of asynchronous page cleaners)
Specifies the number of asynchronous page cleaners for a database. These page cleaners write changed pages from the buffer pool to disk before the space in the buffer pool is required by a database agent.
NUM_IOSERVERS (number of I/O servers)Specifies the number of I/O servers for a database. I/O servers are used on behalf of the database agents to perform prefetch I/O and asynchronous I/O by utilities such as backup and restore.
DB2 Monitoring and TuningParameters to consider
209
SORTHEAP (sort heap size)Defines the maximum number of private memory pages to be used for private sorts, or the maximum number of shared memory pages to be used for shared sorts.
MAXAPPLS (maximum number of active applications)Specifies the maximum number of concurrent applications that can be connected (both local and remote) to the database.
MINCOMMIT (group commit count)This allows you to delay the writing of log records to disk until a minimum number of commits have been performed.
LOGFILSIZ (logfilesize)Defines the size of each primary and secondary log file.
LOGPRIMARY (number of primary log files)Specifies the number of primary log files to be preallocated.
LOGSECOND (number of secondary log files)Specifies the number of secondary log files that are created and used for recovery log files (only as needed).
DB2 Monitoring and TuningParameters to consider
210
DB2 Monitoring and TuningWhat to watch?
Buffer Pool Hit RatioGreater % means less time on Disk I/O
Catalog Cache Hit RatioCATALOGCACHE_SZ (Higher % = less Disk I/O)
Lock EscalationDeadlocksAverage Lock Wait TimeSQL Statements per Second
Low value may indicate complex queries or lock problems
Sort OverflowedSORTHEAP may be too small
Indicates possible concurrency problems
211
DB2 Monitoring and TuningDB2 Sorting
DB2 will try to order data via an index. If an index can not be used a sort will occur.A Sort consists of two steps:
Sort PhaseOverflowed - sort does not fit into sort heap and uses temporary tables. Non-overflowed - sort fits into sort heap. Non-overflowed always perform better.
Return resultsPiped - data returned directly without requiring a temporary table to store a final, sorted list of data. Non-piped - sorted information requires a temporary table to be returned. Piped always performs better.
All combinations of the categories are possible.
212
DB2 Monitoring and TuningQuery Parallelism
Inter-partition parallelism - Parallel Queryselect, insert, update, delete
Intra-partition parallelism- Parallel TransactionSelect only. Not supported for insert, update, delete. Enabled by INTRA_PARALLEL parameterData parallelism divides the data based on number of processors used
MPP Parallel Support
Parallel Query
CPUCPU
CPUCPUSQL
Parallel TransactionCPUSQL
CPUSQLCPUSQL
CPUSQLUniprocessor
SymmetricMultiprocessor
(SMP)
Cluster Massively Parallel Processor (MPP)
213
DB2 Monitoring and TuningWhere to Configure Parallelism
Instance LevelINTRA_PARALLEL
Yes/NoEnables/Disables parallelism for the instance
MAX_QUERYDEGREE1-32767, (ANY)Maximum degree of parallelism for the instance
Database LevelDFT_DEGREE
1-32767 (ANY)The default degree of parallelism for the databaseMax for any SQL on the database
CLI Level1-32767 (ANY) [Default is 1]
if DB2DEGREE not set in db2cli.ini then NO parallelism
Sets degree of parallelism for CLI/ODBC applicationsSet on the server
Statement Level CURRENT DEGREE
1-32767 (ANY)Sets Degree of parallelism for dynamic statements
DEGREE1-32767 (ANY)Sets Degree of parallelism for statements in a package at bind time
RUNTIME DEGREE1-32767 (ANY)Changes/sets degree of parallelism for a running applicationtakes effect after currently executing statementCan only REDUCE degree of parallelism
Lowest Setting Wins.
214
DB2 Monitoring and TuningDB2 Problem Diagnosis
DB2 provides diagnosis information at the point failure (db2diag.log)There are 5 levels of information possible :-
0 - NO diagnostic data captured1 - SEVERE errors only2 - SEVERE & NON-SEVERE errors3 - SEVERE, NON-SEVERE errors & WARNINGS (DEFAULT)4 - SEVERE, NON-SEVERE errors, WARNINGS & INFORMATIONAL messages
db2diag.log is the first place to look if any problems occur.
215
DB2 Monitoring and TuningDB2 Tracing
DB2 Trace Facility db2trc
CLI / ODBC / JDBC TraceAdmin Tools / ICLUI TraceDB2 Connect Trace
ddcstrc
DRDA Trace db2drdat
SNA Trace
216
DB2 Database AdministrationCertification Review
Having completed this, you should be able to:Take the DB2 UDB V7.1 certification exams for Fundamentals and Database Administration!! Are you ready to pass - you are the only one who knows that ...
Now is the best time to ask questions ...
Any questions?
Finally - GOOD LUCK to all of you!
217