SlideShare a Scribd company logo
1 of 74
Day2
 Tables
 Views
 Indexes
 Packages
 Procedures
 Triggers
 Pages
 Tablespaces
 Bufferpools
2
 Tables are logical structure maintained by Database manager. In a table
each vertical block called as column (Tuple) and each horizontal block
called as row (Entity). The collection of data stored in the form of columns
and rows is known as a table. In tables, each column has different data
type. 
3
 System Catalog Tables
 User Tables
 Temporary Tables
4
Each DB2 database has a set of tables called the system catalog tables.
DB2 creates these tables when a database is created.
• DB2 creates the system catalog base tables under the SYSIBM schema like
SYSIBM.SYSTABLES,SYSIBM.SYSVIEWS,SYSIBM.SYSPACKAGES.
• These tables are not erasable.
• DB2 optimizer uses these to track the changes happening to the db2
objects.
5
All the tables created by DBAs will come under this category. All the tables
will be placed in usersapace1 table space by default
 db2 " create table customers (id integer primary key not null, name
varchar(50), age integer)”
 db2 " insert into customers values (11,‘abc',27)”
• db2 "select * from customers”
• db2 " select tabname, tabschema, tbspace from syscat.tables“
• db2 " select tabname, tabschema, tbspace from syscat.tables"| grep -i
customers
• db2 describe table customers
6
Column name schema Data type name Length Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID SYSIBM INTEGER 4 0 No
NAME SYSIBM VARCHAR 50 0 Yes
AGE SYSIBM INTEGER 4 0 Yes
db2 " alter table customers alter column ID set data type bigint"
Column name schema Data type name Length Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID SYSIBM BIGINT 8 0 No
NAME SYSIBM VARCHAR 50 0 Yes
AGE SYSIBM INTEGER 4 0 Yes
7
 db2 "alter table customers rename column NAME to NICKNAME”
Column name schema Data type name Length Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID SYSIBM BIGINT 8 0 No
NICKNAME SYSIBM VARCHAR 50 0 Yes
AGE SYSIBM INTEGER 4 0 Yes
db2 "drop table customers“
8
  For temporary work of different database
operations, DB2 uses temporary tables. The
temporary tables do not appear in system catalog.
9
View is an alternative way of representing the data stored in the tables. It is
not an actual table and it does not have any permanent storage. View
provides a way of looking at the data in one or more tables.
• db2 “create view view_sales1(id, itemname, qty, price) as select id,
itemname, qty, price from shopper.sales1”
• SYSIBM.SYSVIEWS ,SYSCAT.VIEWS
• db2 drop view <view_name>
• SYSCAT.TABLES, SYSCAT.VIEWS,SYSCAT.TABLESPACES are the
examples of view subjected to system catalog tables
SYSIBM.SYSTABLES,SYSIBM.SYSVIEWS and
SYSIBM.SYSTABLESPACES respectively.
10
 Indexes are an ordered set of keys each pointing to a row in a table. They improve
application performance when looking for specific rows.
 Indexes are database objects that are built based on one or more columns of a table.
They are used for two main reasons:
 • To improve query performance. Indexes can be used to access the data faster
using direct access to rows based on the index key values.
 • To guarantee uniqueness when they are defined as unique indexes.
 SYSIBM.SYSINDEXES , SYSCAT.INDEXES
 db2 describe indexes for table customers show detail
11
To create an index, use the CREATE INDEX statement. This statement requires at a
minimum:
• The name of the index
• The name of the associated table
• The columns that make up the index (also known as index keys)
In addition, you can specify the following:
• Whether the index is unique (enforce uniqueness for the key values) or non-
unique(allow duplicates)
• Which order DB2 should use to build and maintain the key values: ascending (ASC,
the default) or descending (DESC) order
• Whether to create INCLUDE columns that are not part of the index key but are
columns often retrieved by your queries
12
 db2 “CREATE UNIQUE INDEX company_ix ON
company (company_ID ASC, name DESC)
INCLUDE (no_employees)”
13
A package is a database object consisting of executable SQL, including the access
path the DB2 optimizer will take to perform the SQL operation.
14
15
Procedures are programs whose executable binaries reside at the database server.
They serve as subroutines to calling applications, and they normally wrap multiple
SQL statements with flow logic. They are used to reduce the traffic so improving the
performance.
 Besides improving response time for applications running on a different server than
the database server, stored procedures also provide a central location to store
database application logic. This allows for a single place to maintain your code.
16
17
There are 2 types of procedures in DB2 .
1. Fenced Procedure
2. Unfenced Procedure
A fenced stored procedure runs in a different address space than the DB2
engine. This guarantees that a failure from the procedure will not corrupt the
DB2 engine itself. In Linux and UNIX, a fenced user needs to be created to
work with fenced stored procedures.
 In terms of performance, unfenced stored procedures run faster than fenced
ones; however, there is a risk that unfenced procedures may corrupt DB2
information,
18
A trigger is a database object associated to a table or a view that contains some
application logic, which is executed automatically upon an INSERT, UPDATE, or
DELETE operation on the table or view.
Triggers can be classified as BEFORE, AFTER, or INSTEAD OF triggers.
Example of Before Trigger
 CREATE TRIGGER default_time NO CASCADE BEFORE INSERT ON schedule
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
WHEN (n.start_time IS NULL) SET n.start_time = '12:00'
19
 CREATE TRIGGER audit_qty
 AFTER UPDATE OF quantity ON inventory
 REFERENCING OLD AS o NEW AS n
 FOR EACH ROW
 MODE DB2SQL
 INSERT INTO sold
 VALUES (n.product_ID, n.daysold, o.quantity - n.quantity)
20
 This example demonstrates how a read-only view can still be updated by
using INSTEAD OF triggers. In the example, the trigger updates the region
column of table table2 when the view view2 (a read-only view) is updated.
 CREATE TRIGGER update_view2 INSTEAD OF UPDATE
 ON view2 REFERENCING OLD AS o NEW AS n
 FOR EACH ROW MODE DB2SQL
 BEGIN ATOMIC UPDATE table2
 SET region = n.region
 WHERE region = o.region;
 END
21
DB2 stores table and index data on a page, which is the smallest unit of storage in a DB2
database.
 DB2 creates and manages the pages in the table space automatically, but you can control
the page size for your table spaces. If you do not explicitly specify the page size when you
create
 the table space, DB2 will use the default size of 4K. DB2 supports four different page sizes:
4K,8K, 16K, and 32K.
 The maximum number of rows on a page is 255 rows. This is significant, if you have small
row sizes.
 A table space may contain up to 64 GB of data, if the page size is 4K.
 Chunk of pages are called as Extent
22
A table space is a storage structure, it contains tables, indexes, large
objects, and long data. It can be used to organize data in a database into
logical storage group which is related with where data stored on a system.
23
 The table spaces are beneficial in database in various ways given as
follows:
 Recoverability: Tablespaces make backup and restore operations more
convenient. Using a single command, you can make backup or restore all
the database objects in tablespaces.
 Automatic storage Management: Database manager creates and extends
containers depending on the needs.
 Memory utilization: A single bufferpool can manage multiple tablespaces.
You can assign temporary tablespaces to their own bufferpool to increase
the performance of activities such as sorts or joins.
24
When you create a new database, the database
manager creates some default tablespaces for
database. These tablespace is used as a storage
for user and temporary data. Each database must
contain at least three tablespaces as given here:
 Catalog tablespace
 User tablespace
 Temporary tablespace
25
26
Logical layer between Hardware and Database
Comprised of one or more containers
A container is a file or a directory
REGULAR
CREATE TABLESPACE name
LARGE
SYSTEM
TEMPORARY
USER
MANAGED BY SYSTEM system-containers
DATABASE database-containers
27
SMS Containers
USING (‘container string’)
DMS Containers
USING (FILE ‘container string’ number of pages)
(DEVICE ‘container string’ number of pages)
28
CREATE TABLESPACE TS1 MANAGED BY SYSTEM
USING (‘/home/inst01/database/ts1’)
CREATE TABLESPACE DMS01D MANAGED BY DATABASE
USING (FILE ‘C:DMSDATABASEDMS01D’ 1000)
29
The database buffer pool area is a piece of real memory that is used by DB2
to temporarily store (cache) the regular data and index pages when they are
read from disk to be scanned or modified.
 The buffer pool area improves the performance of the database, since the
pages can be accessed
 much more quickly from memory than from disk.
30
 When you create a database, DB2 creates a default buffer pool named
IBMDEFAULTBP.
 CREATE BUFFERPOOL tempbp SIZE 10000
 ALTER TABLESPACE tempspace1 BUFFERPOOL tempbp
 CREATE BUFFERPOOL bp16k SIZE 100000 PAGESIZE 16K
 ALTER BUFFERPOOL bp16k SIZE 200000
31
You will not be able to drop any buffer pools that are
associated with a table space. Before you can drop the
buffer pool you will need to associate the table space
with a different buffer pool using the ALTER
TABLESPACE statement.
DROP BUFFERPOOL bp16k
32
 db2 get snapshot for bufferpools on database-name
Bufferpool name = IBMDEFAULTBP
Database name = MUSICKEG
Database path = C:DB2NODE0000SQL00002
Input database alias = MUSICKEG
Snapshot timestamp = 05/04/2005 13:11:37.329018
Buffer pool data logical reads = 336
Buffer pool data physical reads = 129
33
 IMPORT
 EXPORT
 LOAD
 db2move
35
36
File
Import
Export
37
IMPORT FROM filename OF IXF
DEL
ASC
LOBS FROM lob-path MODIFIED BY options
MESSAGES
INSERT INTO table-name
INSERT_UPDATE
REPLACE
REPLACE_CREATE
38
EXPORT TO file OF IXF MESSAGES message-file
DEL
WSF
select statement
39
1) Load Loads data, collects index keys
2) Build creates the indexes
3) Delete Delete unique key violations place into
exception tables.
4) Index Copy – copy indexes from temp table space
40
LOAD FROM filename OF IXF
ASC
DEL
LOBS FROM lob-path MODIFIED BY options
MESSAGES message-file
INSERT INTO table-name
REPLACE
RESTART
TERMINATE
41
Create nickname sales for
another database SAMPLE table SALES
Create nickname employee for
another database SAMPLE table EMPLOYEE
DECLARE C1 CURSOR FOR SELECT SALES.SALES_PERSON,
LASTNAME, FIRSTNME FROM SALES, EMPLOYEE
WHERE SALES_PERSON = EMPLOYEE.LASTNAME
LOAD FROM C1 OF CURSOR INSERT INTO LOCAL_SALES
db2move
Database
42
db2move.lst
table.ixf
DB2MOVE
43
db2move database-name import
export
load
tc table-creators
tn table-name
sn schema-names
ts table space-names
44
CREATE TABLESPACE TS1 MANAGED BY SYSTEM
USING (‘C:SMSMUSICKEGTS1’)
CREATE TABLESPACE DMS01D MANAGED BY DATABASE
USING (FILE ‘C:DMSMUSICKEGDMS01D’ 161)
EXTENTSIZE 8 PREFETECHSIZE 8
CREATE TABLESPACE DMS01I MANAGED BY DATABASE
USING (FILE ‘C:DMSMUSICKEGDMS01I’ 48)
EXTENTSIZE 4 PREFETCHSIZE 4
45
Defining logs
Recovery of database
Recovery of a table space
Offline versus Online
47
Database
S0000000.log
S0000001.log
S00000002.log
S0000003.log(SecondaryLog)
S0000004.log(SecondaryLog)
48
Database
S0000000.log
S0000001.log
S00000002.log
S0000003.log
S0000004.log
49
 If LOGRETAIN = Recovery you may backup table space
or database
 If LOGRETAIN = NO you may only backup database
BACKUP DB database-name ONLINE to C:backup
INCLUDE LOGS
50
 If LOGRETAIN = NO, you may only recover the
database
 If LOGRETAIN = RECOVERY, you may recover a table
space or a database from a full database backup
51
 Offline
 Online
RESTORE DB database-name FROM file TAKEN AT
time
ROLLFORWARD DATABASE database-name
TO isotime AND STOP
END OF LOGS
52
Database_standby
Database1
Laptopcomputer
53
 Database Configuration parameters
 Database Structure
 SQL Statements
55
56
57
Database
BufferPool
Select*fromStaff
58
 Sorts are done in sortheap
 If no space for sort data is moved to TEMPSPACEn
 GET SNAPSHOT FOR ALL ON database
59
 Dynamic SQL statements
PackageCache
Select*fromStaffwhereID=10
Select*fromStaffwhereID=10
UpdateStaffSetSalary=Salary+100whereID=10
Select*fromEMPLOYEE
60
 Locks are held to prevent loss of data
 Lock Row / Table / Table Space
 LOCKLIST
 MAXLOCKS
 ALTER TABLE table-name LOCKSIZE TABLE
61
62
 Determine which statement is causing the majority of
problems
 Determine what might be causing the problem
 Testing the solution
63
64
65
66
 Buffer pools
 Numerous Database Configuration parameters
 SQL Statement Tuning
67
 Security is used at the operating system level
 Table access is through the database
69
 SYSADM_GROUP
 SYSCTRL_GROUP
 SYSMAINT_GROUP
 SYSMON_GROUP
70
 GRANT access to an object/program
 REVOKE access to an object/program
 GRANT SELECT ON TABLE ARTISTS TO
USER1
71
 The Relational Database can be simple or complex
 The database structure is simple, Table spaces, Tables,
etc.
 Recovery is straight forward
 Database maintenance can be automated
 Tuning the database is a life long endeavor
72
 July 12, 13 DB2 UDB Administration Proof of
Technology
 IBM – McClean Tec
 8401 Greensboro Drive
 McClean, VA 22102
 Suite 120 First Floor
 WebSphere Information Integrator July 14, 2005
 Contact: Keith E. Gardenhire
 keithgar@us.ibm.com
73
74

More Related Content

What's hot

Solving the DB2 LUW Administration Dilemma
Solving the DB2 LUW Administration DilemmaSolving the DB2 LUW Administration Dilemma
Solving the DB2 LUW Administration DilemmaRandy Goering
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performancesolarisyougood
 
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruIBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruRavikumar Nandigam
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDBSrinimf-Slides
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizerterraborealis
 
IBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM
 
The Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12cThe Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12cDavid Yahalom
 
db2dart and inspect
db2dart and inspectdb2dart and inspect
db2dart and inspectdbawork
 
High Availability Options for DB2 Data Centre
High Availability Options for DB2 Data CentreHigh Availability Options for DB2 Data Centre
High Availability Options for DB2 Data Centreterraborealis
 
DB2 for z/OS Real Storage Monitoring, Control and Planning
DB2 for z/OS Real Storage Monitoring, Control and PlanningDB2 for z/OS Real Storage Monitoring, Control and Planning
DB2 for z/OS Real Storage Monitoring, Control and PlanningJohn Campbell
 
Best Practices For Optimizing DB2 Performance Final
Best Practices For Optimizing DB2 Performance FinalBest Practices For Optimizing DB2 Performance Final
Best Practices For Optimizing DB2 Performance FinalDatavail
 
DB2 LUW Access Plan Stability
DB2 LUW Access Plan StabilityDB2 LUW Access Plan Stability
DB2 LUW Access Plan Stabilitydmcmichael
 
Inno db datafiles backup and retore
Inno db datafiles backup and retoreInno db datafiles backup and retore
Inno db datafiles backup and retoreVasudeva Rao
 
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OSPractical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OSCuneyt Goksu
 
Dbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyDbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyFranck Pachot
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restoreVasudeva Rao
 

What's hot (20)

Solving the DB2 LUW Administration Dilemma
Solving the DB2 LUW Administration DilemmaSolving the DB2 LUW Administration Dilemma
Solving the DB2 LUW Administration Dilemma
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performance
 
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guruIBM DB2 LUW UDB DBA Online Training by Etraining.guru
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
IBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration Basics
 
The Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12cThe Top 12 Features new to Oracle 12c
The Top 12 Features new to Oracle 12c
 
db2dart and inspect
db2dart and inspectdb2dart and inspect
db2dart and inspect
 
Ibm db2
Ibm db2Ibm db2
Ibm db2
 
High Availability Options for DB2 Data Centre
High Availability Options for DB2 Data CentreHigh Availability Options for DB2 Data Centre
High Availability Options for DB2 Data Centre
 
DB2 for z/OS Real Storage Monitoring, Control and Planning
DB2 for z/OS Real Storage Monitoring, Control and PlanningDB2 for z/OS Real Storage Monitoring, Control and Planning
DB2 for z/OS Real Storage Monitoring, Control and Planning
 
Best Practices For Optimizing DB2 Performance Final
Best Practices For Optimizing DB2 Performance FinalBest Practices For Optimizing DB2 Performance Final
Best Practices For Optimizing DB2 Performance Final
 
DB2 utilities
DB2 utilitiesDB2 utilities
DB2 utilities
 
Les 18 space
Les 18 spaceLes 18 space
Les 18 space
 
DB2 LUW Access Plan Stability
DB2 LUW Access Plan StabilityDB2 LUW Access Plan Stability
DB2 LUW Access Plan Stability
 
Inno db datafiles backup and retore
Inno db datafiles backup and retoreInno db datafiles backup and retore
Inno db datafiles backup and retore
 
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OSPractical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
 
Dbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyDbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easy
 
Les 10 fl1
Les 10 fl1Les 10 fl1
Les 10 fl1
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restore
 

Similar to DB2 Database Objects Overview

Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018Dave Stokes
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataIntroduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataGruter
 
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San FranciscoMySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San FranciscoDave Stokes
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features" Anar Godjaev
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slidesenosislearningcom
 
Db2 Important questions to read
Db2 Important questions to readDb2 Important questions to read
Db2 Important questions to readPrasanth Dusi
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1sunildupakuntla
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerIDERA Software
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptxMohamedNowfeek1
 
Introducing ms sql_server
Introducing ms sql_serverIntroducing ms sql_server
Introducing ms sql_serverleetinhf
 

Similar to DB2 Database Objects Overview (20)

DB2 TABLESPACES
DB2 TABLESPACESDB2 TABLESPACES
DB2 TABLESPACES
 
SKILLWISE-DB2 DBA
SKILLWISE-DB2 DBASKILLWISE-DB2 DBA
SKILLWISE-DB2 DBA
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataIntroduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big Data
 
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San FranciscoMySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features"
 
Presentation day2 oracle12c
Presentation day2 oracle12cPresentation day2 oracle12c
Presentation day2 oracle12c
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
Db2 Important questions to read
Db2 Important questions to readDb2 Important questions to read
Db2 Important questions to read
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
No SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability MeetupNo SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability Meetup
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
Introducing ms sql_server
Introducing ms sql_serverIntroducing ms sql_server
Introducing ms sql_server
 
Dbcc.doc
Dbcc.docDbcc.doc
Dbcc.doc
 

DB2 Database Objects Overview

  • 2.  Tables  Views  Indexes  Packages  Procedures  Triggers  Pages  Tablespaces  Bufferpools 2
  • 3.  Tables are logical structure maintained by Database manager. In a table each vertical block called as column (Tuple) and each horizontal block called as row (Entity). The collection of data stored in the form of columns and rows is known as a table. In tables, each column has different data type.  3
  • 4.  System Catalog Tables  User Tables  Temporary Tables 4
  • 5. Each DB2 database has a set of tables called the system catalog tables. DB2 creates these tables when a database is created. • DB2 creates the system catalog base tables under the SYSIBM schema like SYSIBM.SYSTABLES,SYSIBM.SYSVIEWS,SYSIBM.SYSPACKAGES. • These tables are not erasable. • DB2 optimizer uses these to track the changes happening to the db2 objects. 5
  • 6. All the tables created by DBAs will come under this category. All the tables will be placed in usersapace1 table space by default  db2 " create table customers (id integer primary key not null, name varchar(50), age integer)”  db2 " insert into customers values (11,‘abc',27)” • db2 "select * from customers” • db2 " select tabname, tabschema, tbspace from syscat.tables“ • db2 " select tabname, tabschema, tbspace from syscat.tables"| grep -i customers • db2 describe table customers 6
  • 7. Column name schema Data type name Length Scale Nulls ------------------------------- --------- ------------------- ---------- ----- ------ ID SYSIBM INTEGER 4 0 No NAME SYSIBM VARCHAR 50 0 Yes AGE SYSIBM INTEGER 4 0 Yes db2 " alter table customers alter column ID set data type bigint" Column name schema Data type name Length Scale Nulls ------------------------------- --------- ------------------- ---------- ----- ------ ID SYSIBM BIGINT 8 0 No NAME SYSIBM VARCHAR 50 0 Yes AGE SYSIBM INTEGER 4 0 Yes 7
  • 8.  db2 "alter table customers rename column NAME to NICKNAME” Column name schema Data type name Length Scale Nulls ------------------------------- --------- ------------------- ---------- ----- ------ ID SYSIBM BIGINT 8 0 No NICKNAME SYSIBM VARCHAR 50 0 Yes AGE SYSIBM INTEGER 4 0 Yes db2 "drop table customers“ 8
  • 9.   For temporary work of different database operations, DB2 uses temporary tables. The temporary tables do not appear in system catalog. 9
  • 10. View is an alternative way of representing the data stored in the tables. It is not an actual table and it does not have any permanent storage. View provides a way of looking at the data in one or more tables. • db2 “create view view_sales1(id, itemname, qty, price) as select id, itemname, qty, price from shopper.sales1” • SYSIBM.SYSVIEWS ,SYSCAT.VIEWS • db2 drop view <view_name> • SYSCAT.TABLES, SYSCAT.VIEWS,SYSCAT.TABLESPACES are the examples of view subjected to system catalog tables SYSIBM.SYSTABLES,SYSIBM.SYSVIEWS and SYSIBM.SYSTABLESPACES respectively. 10
  • 11.  Indexes are an ordered set of keys each pointing to a row in a table. They improve application performance when looking for specific rows.  Indexes are database objects that are built based on one or more columns of a table. They are used for two main reasons:  • To improve query performance. Indexes can be used to access the data faster using direct access to rows based on the index key values.  • To guarantee uniqueness when they are defined as unique indexes.  SYSIBM.SYSINDEXES , SYSCAT.INDEXES  db2 describe indexes for table customers show detail 11
  • 12. To create an index, use the CREATE INDEX statement. This statement requires at a minimum: • The name of the index • The name of the associated table • The columns that make up the index (also known as index keys) In addition, you can specify the following: • Whether the index is unique (enforce uniqueness for the key values) or non- unique(allow duplicates) • Which order DB2 should use to build and maintain the key values: ascending (ASC, the default) or descending (DESC) order • Whether to create INCLUDE columns that are not part of the index key but are columns often retrieved by your queries 12
  • 13.  db2 “CREATE UNIQUE INDEX company_ix ON company (company_ID ASC, name DESC) INCLUDE (no_employees)” 13
  • 14. A package is a database object consisting of executable SQL, including the access path the DB2 optimizer will take to perform the SQL operation. 14
  • 15. 15
  • 16. Procedures are programs whose executable binaries reside at the database server. They serve as subroutines to calling applications, and they normally wrap multiple SQL statements with flow logic. They are used to reduce the traffic so improving the performance.  Besides improving response time for applications running on a different server than the database server, stored procedures also provide a central location to store database application logic. This allows for a single place to maintain your code. 16
  • 17. 17
  • 18. There are 2 types of procedures in DB2 . 1. Fenced Procedure 2. Unfenced Procedure A fenced stored procedure runs in a different address space than the DB2 engine. This guarantees that a failure from the procedure will not corrupt the DB2 engine itself. In Linux and UNIX, a fenced user needs to be created to work with fenced stored procedures.  In terms of performance, unfenced stored procedures run faster than fenced ones; however, there is a risk that unfenced procedures may corrupt DB2 information, 18
  • 19. A trigger is a database object associated to a table or a view that contains some application logic, which is executed automatically upon an INSERT, UPDATE, or DELETE operation on the table or view. Triggers can be classified as BEFORE, AFTER, or INSTEAD OF triggers. Example of Before Trigger  CREATE TRIGGER default_time NO CASCADE BEFORE INSERT ON schedule REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL WHEN (n.start_time IS NULL) SET n.start_time = '12:00' 19
  • 20.  CREATE TRIGGER audit_qty  AFTER UPDATE OF quantity ON inventory  REFERENCING OLD AS o NEW AS n  FOR EACH ROW  MODE DB2SQL  INSERT INTO sold  VALUES (n.product_ID, n.daysold, o.quantity - n.quantity) 20
  • 21.  This example demonstrates how a read-only view can still be updated by using INSTEAD OF triggers. In the example, the trigger updates the region column of table table2 when the view view2 (a read-only view) is updated.  CREATE TRIGGER update_view2 INSTEAD OF UPDATE  ON view2 REFERENCING OLD AS o NEW AS n  FOR EACH ROW MODE DB2SQL  BEGIN ATOMIC UPDATE table2  SET region = n.region  WHERE region = o.region;  END 21
  • 22. DB2 stores table and index data on a page, which is the smallest unit of storage in a DB2 database.  DB2 creates and manages the pages in the table space automatically, but you can control the page size for your table spaces. If you do not explicitly specify the page size when you create  the table space, DB2 will use the default size of 4K. DB2 supports four different page sizes: 4K,8K, 16K, and 32K.  The maximum number of rows on a page is 255 rows. This is significant, if you have small row sizes.  A table space may contain up to 64 GB of data, if the page size is 4K.  Chunk of pages are called as Extent 22
  • 23. A table space is a storage structure, it contains tables, indexes, large objects, and long data. It can be used to organize data in a database into logical storage group which is related with where data stored on a system. 23
  • 24.  The table spaces are beneficial in database in various ways given as follows:  Recoverability: Tablespaces make backup and restore operations more convenient. Using a single command, you can make backup or restore all the database objects in tablespaces.  Automatic storage Management: Database manager creates and extends containers depending on the needs.  Memory utilization: A single bufferpool can manage multiple tablespaces. You can assign temporary tablespaces to their own bufferpool to increase the performance of activities such as sorts or joins. 24
  • 25. When you create a new database, the database manager creates some default tablespaces for database. These tablespace is used as a storage for user and temporary data. Each database must contain at least three tablespaces as given here:  Catalog tablespace  User tablespace  Temporary tablespace 25
  • 26. 26 Logical layer between Hardware and Database Comprised of one or more containers A container is a file or a directory REGULAR CREATE TABLESPACE name LARGE SYSTEM TEMPORARY USER MANAGED BY SYSTEM system-containers DATABASE database-containers
  • 27. 27 SMS Containers USING (‘container string’) DMS Containers USING (FILE ‘container string’ number of pages) (DEVICE ‘container string’ number of pages)
  • 28. 28 CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘/home/inst01/database/ts1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:DMSDATABASEDMS01D’ 1000)
  • 29. 29
  • 30. The database buffer pool area is a piece of real memory that is used by DB2 to temporarily store (cache) the regular data and index pages when they are read from disk to be scanned or modified.  The buffer pool area improves the performance of the database, since the pages can be accessed  much more quickly from memory than from disk. 30
  • 31.  When you create a database, DB2 creates a default buffer pool named IBMDEFAULTBP.  CREATE BUFFERPOOL tempbp SIZE 10000  ALTER TABLESPACE tempspace1 BUFFERPOOL tempbp  CREATE BUFFERPOOL bp16k SIZE 100000 PAGESIZE 16K  ALTER BUFFERPOOL bp16k SIZE 200000 31
  • 32. You will not be able to drop any buffer pools that are associated with a table space. Before you can drop the buffer pool you will need to associate the table space with a different buffer pool using the ALTER TABLESPACE statement. DROP BUFFERPOOL bp16k 32
  • 33.  db2 get snapshot for bufferpools on database-name Bufferpool name = IBMDEFAULTBP Database name = MUSICKEG Database path = C:DB2NODE0000SQL00002 Input database alias = MUSICKEG Snapshot timestamp = 05/04/2005 13:11:37.329018 Buffer pool data logical reads = 336 Buffer pool data physical reads = 129 33
  • 34.
  • 35.  IMPORT  EXPORT  LOAD  db2move 35
  • 37. 37 IMPORT FROM filename OF IXF DEL ASC LOBS FROM lob-path MODIFIED BY options MESSAGES INSERT INTO table-name INSERT_UPDATE REPLACE REPLACE_CREATE
  • 38. 38 EXPORT TO file OF IXF MESSAGES message-file DEL WSF select statement
  • 39. 39 1) Load Loads data, collects index keys 2) Build creates the indexes 3) Delete Delete unique key violations place into exception tables. 4) Index Copy – copy indexes from temp table space
  • 40. 40 LOAD FROM filename OF IXF ASC DEL LOBS FROM lob-path MODIFIED BY options MESSAGES message-file INSERT INTO table-name REPLACE RESTART TERMINATE
  • 41. 41 Create nickname sales for another database SAMPLE table SALES Create nickname employee for another database SAMPLE table EMPLOYEE DECLARE C1 CURSOR FOR SELECT SALES.SALES_PERSON, LASTNAME, FIRSTNME FROM SALES, EMPLOYEE WHERE SALES_PERSON = EMPLOYEE.LASTNAME LOAD FROM C1 OF CURSOR INSERT INTO LOCAL_SALES
  • 43. 43 db2move database-name import export load tc table-creators tn table-name sn schema-names ts table space-names
  • 44. 44 CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘C:SMSMUSICKEGTS1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:DMSMUSICKEGDMS01D’ 161) EXTENTSIZE 8 PREFETECHSIZE 8 CREATE TABLESPACE DMS01I MANAGED BY DATABASE USING (FILE ‘C:DMSMUSICKEGDMS01I’ 48) EXTENTSIZE 4 PREFETCHSIZE 4
  • 45. 45
  • 46.
  • 47. Defining logs Recovery of database Recovery of a table space Offline versus Online 47
  • 50.  If LOGRETAIN = Recovery you may backup table space or database  If LOGRETAIN = NO you may only backup database BACKUP DB database-name ONLINE to C:backup INCLUDE LOGS 50
  • 51.  If LOGRETAIN = NO, you may only recover the database  If LOGRETAIN = RECOVERY, you may recover a table space or a database from a full database backup 51
  • 52.  Offline  Online RESTORE DB database-name FROM file TAKEN AT time ROLLFORWARD DATABASE database-name TO isotime AND STOP END OF LOGS 52
  • 54.
  • 55.  Database Configuration parameters  Database Structure  SQL Statements 55
  • 56. 56
  • 57. 57
  • 59.  Sorts are done in sortheap  If no space for sort data is moved to TEMPSPACEn  GET SNAPSHOT FOR ALL ON database 59
  • 60.  Dynamic SQL statements PackageCache Select*fromStaffwhereID=10 Select*fromStaffwhereID=10 UpdateStaffSetSalary=Salary+100whereID=10 Select*fromEMPLOYEE 60
  • 61.  Locks are held to prevent loss of data  Lock Row / Table / Table Space  LOCKLIST  MAXLOCKS  ALTER TABLE table-name LOCKSIZE TABLE 61
  • 62. 62
  • 63.  Determine which statement is causing the majority of problems  Determine what might be causing the problem  Testing the solution 63
  • 64. 64
  • 65. 65
  • 66. 66
  • 67.  Buffer pools  Numerous Database Configuration parameters  SQL Statement Tuning 67
  • 68.
  • 69.  Security is used at the operating system level  Table access is through the database 69
  • 70.  SYSADM_GROUP  SYSCTRL_GROUP  SYSMAINT_GROUP  SYSMON_GROUP 70
  • 71.  GRANT access to an object/program  REVOKE access to an object/program  GRANT SELECT ON TABLE ARTISTS TO USER1 71
  • 72.  The Relational Database can be simple or complex  The database structure is simple, Table spaces, Tables, etc.  Recovery is straight forward  Database maintenance can be automated  Tuning the database is a life long endeavor 72
  • 73.  July 12, 13 DB2 UDB Administration Proof of Technology  IBM – McClean Tec  8401 Greensboro Drive  McClean, VA 22102  Suite 120 First Floor  WebSphere Information Integrator July 14, 2005  Contact: Keith E. Gardenhire  keithgar@us.ibm.com 73
  • 74. 74

Editor's Notes

  1. This presentation will discuss DB2 UDB Fundamentals.
  2. There are two types of table space management systems: Database and System. System managed table space is easier to maintain. Database managed space is slightly faster than System managed space when adding data to a table. The reason is that DMS table space will format data pages in advance. SMS managed space has significant performance improvements in DB2 UDB V8.1. SMS table space will acquire an extent at time on DB2 V8.1, where on previous release DB2 UDB obtained 1 page at a time. If you use SMS table space, the entire table must exist in the one table space. If you use DMS table space, the table may have the data portion in one table space, the index in a second table space and the large object portion in a third table space. Table space definition will set the page size. The default page size is 4K. Page sizes can be 4K, 8K, 16K and 32K. The maximum number of rows on a page is 255 rows. This is significant, if you have small row sizes. A table space may contain up to 64 GB of data, if the page size is 4K.
  3. Table spaces may be managed by System requires a directory. The directory will be created. Table spaces managed by Database requires a file or raw device.
  4. The table space named TS1 is an SMS table space. If the directory does not exist, it will be created. The table space named DMS01D is a DMS table space. Data will be placed in a file.
  5. A logical read occurs when DB2 attempts to find a page in the buffer pool. A physical read occurs, when the page requested is not in the buffer pool.
  6. Populating data into tables. IMPORT inserts data into tables. LOAD utility used for loading large amounts of data is faster than the IMPORT utility. Export utility moves data from a table to a flat file. db2move is a utility that may move many tables at the same time.
  7. The Import utility will take the data from a flat file and place it into table. Inserts will be used to place the data into the table. The inserts will be logged. Triggers, if they exist, will be executed. DB2 UDB V8.2 will allow Online IMPORT. This means that users may access the table, while the IMPORT utility is running.
  8. The IMPORT utility will insert data into a table. The format of the input file is IXF (PC/Integrated Exchange format) used by DB2 only. DEL indicates a delimited ASCII format. The columns will be delimited by a comma. Character columns will be delimited by a double quote mark. ASC indicates an ASCII file with a column beginning and ending position of the data. If you use the ASC file type the METHOD L must be used to state the beginning and ending position. Example: IMPORT FROM ARTISTS.DAT OF ASC LOBS FROM C:\LOBS\ MODIFIED BY LOBSINFILE METHOD L ( 40 43, 1 39, 50 69, 70 83, 84 98) MESSAGES IMPORT_ARTISTS.MSG INSERT INTO ARTISTS
  9. Export data from a table(s) and place data into file. With the Export utility you can take data from more than one table. Any valid SELECT statement may be used. The SELECT statement may even be JOIN.
  10. The 4 phases from load.
  11. The Load command is used for placing large amounts of data into the table. When using the load command, exception tables should be created. The exception tables are identical to the original table. The exception table may have two additional columns: TS (Timestamp) and MSG (CLOB 32K). If you do not have an exception table and a row violates referential integrity, the LOAD will fail. Note: If you are running the DPF (Data Partitioning Feature), the exception table must be in the same partitions as the original table.
  12. The LOAD utility supports using a cursor. This is a way to load data from tables that do not exist in the database. The nickname is a federated database concept. The nickname will refer to table in a separate database. The federated database concept allows access to non-IBM database stores.
  13. db2move is the Database Movement Tool. db2move is a tool that allows the DBA to copy a large number of tables using one command. Tables will be exported in the PC/IXF format. The tables can be imported and exported into another DB2 database. The db2move tool will create a db2move.lst file that will contain the table name resolution file. Each table will have an tab.ixf file associated with the table data.
  14. db2move can export only the tables with a specific schema name, table name, or who created the table. The db2move can also import the tables. If the table does not exist, the db2move utility is able to create the table if the import is done.
  15. Table space TS1 is managed by the system so a directory “\sms\musickeg\ts1” will be created. Table space DMS01D is managed by the database so a file of 161 4K pages will be used. The table space DMS01I will be managed by the database and a file of 48 pages will be created.
  16. Creating a table space using the Control Center. Open the Control Center. Expand the tree for the database you want to create the table space. In this case let us use the database MUSICKEG. Select the “+” to left of the database.
  17. When the database is started, either by the first connect or using the “ACTIVATE DATABASE” command, the primary log files are allocated. The number of primary logs is defined by the database configuration parameter LOGPRIMARY. When LOGRETAIN = NO (Database Configuration parameter) and the primary log files are full, the secondary log files will be allocated. LOGPRIMARY indicates the number of log files that will be allocated when the database starts. LOGSECOND indicates the maximum number of secondary log files that can be allocated. If you set LOGSECOND to a -1, an infinite number of secondary log files can be allocated.
  18. When LOGRETAIN = RECOVERY, log files are maintained. When the primary log files are used, additional log files will be created.
  19. Backup in DB2 UDB V8.2 will allow the logs to backed up at the same time as the database. You may only include the logs only in an online backup. BACKUP DB database-name ONLINE to c:\backup INCLUDE LOGS This command will include the log files with the backup. If LOGRETAIN=NO, you may only do offline backups.
  20. Offline backup no one can access the database during a backup. Online backup will allow users to be accessing the database at the time the backup is executing. If LOGRETAIN=RECOVERY, a table space(s) may be recovered from a full database backup. When the restore is finished, the database is left in a roll forward pending state. If the database configuration parameter LOGRETAIN = RECOVERY, the DBA (database administrator) may recover the database to a point in time. The RECOVER DATABASE command combines both RESTORE DATABASE and ROLLFORWARD DATABASE commands.
  21. HADR allows for a standby database. The standby database is used, if the primary database is unavailable. The clients will be automatically rerouted to the standby database. To invoke the HADR feature update the database configuration. If the standby database does not hear from the primary database is 120 seconds (default), the standby database takes over. HADR is not available with the DPF (Data Partitioning Feature)
  22. Let us cover a few simple performance and tuning options of using DB2.
  23. The Configuration Advisor allows the DBA to answer several questions. DB2 UDB will then set the configuration parameters.
  24. As with any performance configuration parameters your performance improvement may vary. Each person has there own personal preferences.
  25. There is one default buffer pool. The buffer pool is named IBMDEFAULTBP and is 250 4K pages on a Windows operating system and 1000 4K pages on a UNIX operating system. When page is requested, DB2 will search the buffer pool first. If the page is not in the buffer pool, DB2 will issue a physical I/O request. Therefore it is imperative to keep pages, that are needed in the buffer pool. Suggestion: In an OLTP (Online Transaction Processing ) environment you would want high impact tables in a buffer pool by itself. For DSS (Decision Support Systems) one large buffer pool should suffice. The command “GET SNAPSHOT FOR TABLES ON database” will produce what tables are accessed the most. If you change page sizes from the default 4K page, make sure that a buffer pool is made with the same size.
  26. It is probably better to keep sort data in memory. Sort overflows indicate data to be sorted did not fit in memory. The command “GET SNAPSHOT FOR ALL ON database” will show how many sort overflows have occurred. The database configuration parameter SORTHEAP should be adjusted to eliminate a number of the sort heaps. If the SORTHEAP is not big enough, DB2 will overflow the sort into TEMPSPACE. Note: If you change a page size from the default size of 4K, you must also create TEMPORARY table space of that size.
  27. A dynamic SQL statement is executed. The database manager will verify if the statement is in package cache (package cache lookup). If the SQL statement is not in package cache, the statement is compiled and placed in package cache (package cache insert). If there are no sections available in package cache, a package cache overflow will occur. When package cache overflows, it expands dynamically. You may flush package cache with the command: FLUSH PACKAGE CACHE DYNAMIC Package cache is allocated at database start up time. Look for the database parameter PCKCACHESZ (it is a calculated value of MAXAPPLS * 8).
  28. By default a row is locked. The LOCKLIST is number of 4K pages, that will hold all the lock request blocks. MAXLOCKS determines the percentage of locklist that 1 user may hold. If this percentage is exceeded, the lock request blocks will updated into one table lock. Lock escalation normally indicates a problem. Changing the default row level locking for a table to table level, especially if the table is read only is a good idea.
  29. A LOCKWAIT occurs when a user is waiting on an object in the database. This slide shows two users, DBAPOT and ADMIN, waiting for a resource held by user KGARDEN. From the Control Center select the instance named “DB2” with the RMB (Right Mouse Button). From the pop-up menu select the Applications (menu item). Highlight the user holding the lock and select the command button Show Lock Chains.
  30. The Activity monitor (new to DB2 UDB V8.2) is able to assist in finding the high impact SQL statements. Visual Explain and the character explain tools are able to show the access path of a single SQL Statement. The Design Advisor is able to suggest indexes and MQT (Materialized Query Table), that may help in deciding what may improve performance of the SQL statement.
  31. To get to this point Open the Control Center -&amp;gt; Select the database with the RMB (Right Mouse Button) -&amp;gt; Activity Monitor Determine the SQL Statement that is causing the problem. In this example select the Report: Dynamic SQL statements in the cache with the longest average execution time. From here you can select the SQL Statement and execute Visual Explain.
  32. In this case an index was used for the table TITLES. Notice the diamond above the table DBAPOT.TITLES. This diamond indicates an index is being used. A table scan was run against the tables WAREHOUSE and ARTISTS. DB2 UDB has a cost based optimizer so it is important to have statistics up to date. If you double click on the tables (rectangle), the table statistics will be displayed.
  33. Notice the STATS_TIME row.
  34. There are many things that may affect performance. These are just a couple of tuning tips.
  35. All these groups should be defined to the operating system. If the group is defined in the operating systems security, any userid in that group has the authority. The SYSMON_GROUP is new for DB2 UDB V8.1. Users in this group will be able issue GET DATABASE MANAGER MONITOR SWITCHES, GET MONITOR SWITCHES, GET SNAPSHOT, LIST ACTIVE DATABASES, LIST APPLICATIONS, RESET MONITOR SWITCHES and UPDATE MONITOR SWITCHES.
  36. DB2 UDB Administration for the Oracle DBA For the Distributed Database on Linux, Windows, UNIX. Hands on Labs on Windows workstation. Date: July 12, 13, 2005 (Tuesday and Wednesday) Start Time: 09:00 A.M. End Time: 05:00 P.M. Location: IBM Technology Center 8401 Greensboro Drive McClean, VA 22102 Suite 120 (First Floor) Customers who would like to attend contact: Keith E. Gardenhire e-mail: [email_address] Phone: (301)803-1717 I am doing a 2 day class DB2 UDB V8.2 for the Oracle DBA. The class will cover Database Structure Discuss the differences between DB2 UDB and Oracle RDBMS data structures. Show what table spaces are created, when a DB2 UDB database is created. Discuss the database configuration parameters and the difference that Oracle uses for INIT.ORA file. Labs: Create the SAMPLE and a custom DB2 UDB database Lecture 1: Command Line Processor Lab: Using the DB2 Command Line Processor to examine instance and database configuration. List the tables that exist for a database Show the column characteristics for a table Use the Graphical User Interface (GUI) to display database manager configuration parameters and database configuration parameters. Lecture 2: Database Exploration Understand the database structure: Table Spaces, tables, indexes and system catalog tables. Discuss Referential Integrity constraints. Lab: Create the table spaces and tables using the DB2 Command Line Processor. Learn how to use script files to create database objects. Use the Task Center (GUI) to schedule a job to create the table spaces. If this job is successful, execute a second script to create tables. This exercise will demonstrate how to create and schedule jobs. Use the Journal to see the results of a previously executed task. Alter the tables and add the referential integrity. Lecture 3: Populate the Database Discussions on the Import and Load utilities. Discuss the differences between the two utilities. Lab: Populate the tables created in the previous exercise using the LOAD utility. Use the SET INTEGRITY command to correct the referential integrity constraint violations. Lecture 4: Security Discuss the basic security for DB2 UDB environment. Understand DB2 UDB uses group authority for SYSADM, SYSMAINT and SYSCTRL authority. A new group in DB2 UDB V8.2 SYSMON has been added. Discuss the reasons that this group is used. The students will discuss the GRANT and REVOKE authority commands. The implicit security will be discussed. Lecture 5: Explain Understand how to use the Visual and character explain tools to help in discovery of SQL statement performance problems. Lab: Take an SQL statement and determine what might be incorrect with the database structure (index, Materialized Query Tables, etc..), that is causing a performance problem. Lecture 6: Automatic maintenance DB2 UDB V8.2 allows for certain database maintenance be executed automatically. Learn how to have the RUNSTATS (update the table statistics), REORG (reorganization of a table), and database backups to run automatically. Lab: Using the Control Center (GUI) to set up a maintenance window and to have the REORG, RUNSTATS and database backup be executed during this maintenance window. Lecture 7: Recovery Discussions on the two types of logging: Circular and Archival modes Discussions on the two types of database backup: Offline and Online Recovery modes: Full database recovery, Partial database recovery (table space) and recovery to a point in time Database Configuration parameters that are used in recover will be discussed. Lab: Backup a database. Recover the database to a point in time. Lecture 8: Design Advisor The Design Advisor is a tool, that will assist the DBA (Database Administrator) in designing the proper database structure. Discuss how to capture SQL statements and run the SQL statements through the Design Advisor. Lab: Take 3 complex SQL statements and run through the Design Advisor. Take the results of the Design Advisor and place in the recommendations into the Task Center to run at a later time. Execute the Design Advisor using the DB2 Command Line Processor. Lecture 9: Health Center The Health Center is a new GUI tool for DB2 UDB V8. The Health Center captures alerts and is designed to send the alert to a user. Alerts can be set up by the DBA (Database Administrator) to be customize for a particular situation. Lab: Modify the alter configuration parameters to capture warnings when a table space gets to be 60 percent full. Modify the alter configuration parameters to capture errorss when a table space gets to be 70 percent full. Update the database manager configuration file to start the Health monitor. Lecture 10: Using the Activity Monitor The Activity Monitor, which is new for DB2 UDB V8.2, monitors the dynamic SQL Statements. The lecture will discuss dynamic versus static SQL statements. We will discuss how to capture SQL statements and generate reports. Lab: Execute 3 script files that will run 3 SQL statements. Use the Activity monitor to determine the slowest SQL statement. Use the Activity monitor to Explain the SQL statement. Run Statistics on the tables used by the SQL statement (SQL statement is a join) and Explain the SQL statement again and notice the differences in the total cost to run the SQL Statement. Create two new indexes and update the statistics on both tables. Run the Explain on the SQL statement and determine if the performance was improved. Lecture 11: Stored Procedures. Discuss the differences between Oracle PL/SQL and DB2 UDB SQL/Procedure Langauge. Show how to use the DB2 Development Center to create a simple stored procedure. Learn several SQL/Procedure Language statements. Discuss the structure of a Stored Procedure. Learn how to run Stored Procedure Debugger. Lab: Create a stored procedure, that will show how to build Basic Stored Procedure Structure Manage the SQLCODE and SQLSTATE variables Code the basic EXIT HANDLERS when a row is NOT FOUND. Define a CURSOR that will manage a result set. Code a nested FOR LOOP.
  37. Lecture 3: Populate the Database Discussions on the Import and Load utilities. Discuss the differences between the two utilities. Lab: Populate the tables created in the previous exercise using the LOAD utility. Use the SET INTEGRITY command to correct the referential integrity constraint violations. Lecture 4: Security Discuss the basic security for DB2 UDB environment. Understand DB2 UDB uses group authority for SYSADM, SYSMAINT and SYSCTRL authority. A new group in DB2 UDB V8.2 SYSMON has been added. Discuss the reasons that this group is used. The students will discuss the GRANT and REVOKE authority commands. The implicit security will be discussed. Lecture 5: Explain Understand how to use the Visual and character explain tools to help in discovery of SQL statement performance problems. Lab: Take an SQL statement and determine what might be incorrect with the database structure (index, Materialized Query Tables, etc..), that is causing a performance problem. Lecture 6: Automatic maintenance DB2 UDB V8.2 allows for certain database maintenance be executed automatically. Learn how to have the RUNSTATS (update the table statistics), REORG (reorganization of a table), and database backups to run automatically. Lab: Using the Control Center (GUI) to set up a maintenance window and to have the REORG, RUNSTATS and database backup be executed during this maintenance window. Lecture 7: Recovery Discussions on the two types of logging: Circular and Archival modes Discussions on the two types of database backup: Offline and Online Recovery modes: Full database recovery, Partial database recovery (table space) and recovery to a point in time Database Configuration parameters that are used in recover will be discussed. Lab: Backup a database. Recover the database to a point in time. Lecture 8: Design Advisor The Design Advisor is a tool, that will assist the DBA (Database Administrator) in designing the proper database structure. Discuss how to capture SQL statements and run the SQL statements through the Design Advisor. Lab: Take 3 complex SQL statements and run through the Design Advisor. Take the results of the Design Advisor and place in the recommendations into the Task Center to run at a later time. Execute the Design Advisor using the DB2 Command Line Processor. Lecture 9: Health Center The Health Center is a new GUI tool for DB2 UDB V8. The Health Center captures alerts and is designed to send the alert to a user. Alerts can be set up by the DBA (Database Administrator) to be customize for a particular situation. Lab: Modify the alter configuration parameters to capture warnings when a table space gets to be 60 percent full. Modify the alter configuration parameters to capture errorss when a table space gets to be 70 percent full. Update the database manager configuration file to start the Health monitor. Lecture 10: Using the Activity Monitor The Activity Monitor, which is new for DB2 UDB V8.2, monitors the dynamic SQL Statements. The lecture will discuss dynamic versus static SQL statements. We will discuss how to capture SQL statements and generate reports. Lab: Execute 3 script files that will run 3 SQL statements. Use the Activity monitor to determine the slowest SQL statement. Use the Activity monitor to Explain the SQL statement. Run Statistics on the tables used by the SQL statement (SQL statement is a join) and Explain the SQL statement again and notice the differences in the total cost to run the SQL Statement. Create two new indexes and update the statistics on both tables. Run the Explain on the SQL statement and determine if the performance was improved. Lecture 11: Stored Procedures. Discuss the differences between Oracle PL/SQL and DB2 UDB SQL/Procedure Langauge. Show how to use the DB2 Development Center to create a simple stored procedure. Learn several SQL/Procedure Language statements. Discuss the structure of a Stored Procedure. Learn how to run Stored Procedure Debugger. Lab: Create a stored procedure, that will show how to build Basic Stored Procedure Structure Manage the SQLCODE and SQLSTATE variables Code the basic EXIT HANDLERS when a row is NOT FOUND. Define a CURSOR that will manage a result set. Code a nested FOR LOOP.