Post on 07-Apr-2015
DB2 Data Objects
Storage Group
Databases
Table spaces
Indexes
TABLES
SYNONYM
VIEW
Buffer pools
DB2 CATALOG
STORAGE GROUP
A storage group (stogroup) is a set of DASD volumes from which DB2 can assign space for tables and indexes.
All volumes of a storage group must be the same device type.
A storage group is used to:
Have DB2, rather than the user, allocate the VSAM data sets for table spaces and indexes.
Simplify the management of DB2 data sets.
STOGROUP 1
VOL1
VOL3 VOL2
STOGROUP 2
VOL4
VOL5
STOGROUP 3
VOL3
TABLESPACE
A table space is one or more data sets in which one or more tables are stored.
A table space may consist of from 1 to 64 VSAM data sets.
The data sets may contain up to 64 gigabytes of data altogether.
Table space is the unit of recovery in DB2.
There are three types of table spaces:
Simple
Partitioned
Segmented
DATABASE
TABLESPACE
T
T
T
T T
TABLESPACE
T
T
T
T T
vsam1
vsam2
vsam
Simple TABLESPACE
Simple
Has one VSAM data set for every two gigabytes.
Contains rows from one or more tables on a page.
Can hold one or more than one table in table space
Scanning rows in one table requires Scanning the entire table space.
Updating row in one table causes the entire table space to be locked
VSAM 2 VSAM1
Partition TABLESPACE
Partitioned
Table space is divided into partition and each partition is stored in one VSAM/ESDS.
Holds only one table and each partition stores a part of the table. One table split across multiple areas of a table space.
Table physically separated into key range partitions
Large tables can be split across multiple DASD Volumes
A-G
H-P
Q-Z
Segmented TABLESPACE
Segmented Can hold more than one
table
Locking at Table level.
If table scan is necessary , only segments assigned to the table will be scanned.
Segment contains same number of pages which is multiple of 4 .
Segment is made up of 4 to 64 consecutive pages.
Contains rows from only one table in a segment.
More efficient than a simple table space.
DB2-DM-3
Pages
• A Page is either 4K or 32K
A Page is the unit of I/O
A Page can contain a maximum of 127 data records.
A data record does not span pages
HEADER
FOOTER
PAGE
SPACE
Data Records
USING A PAGE OF DATA
Table spaces are divided into equal-sized units called pages.
A page can be either 4K or 32K in size, and is always composed of 4K VSAM Control Intervals (CI).
Rows of data are stored on a page.
Up to 255 rows of data are allowed on a single page
A page is used as follows:
A program must use a row of data.
If the page containing the row is already in the buffer pool, no I/O is done.
If the page is not in the buffer pool, an I/O is done to transfer the page from DASD to the buffer pool. The page is the I/O unit for DB2.
Once the page containing the desired row is in the buffer pool, data is transferred from the row to the program, column by column.
Page 01
Page 02
Page nn
Program
I/O Area
Buffer Pool
0006 0029
Smith Jones
490112 550911
Empno Name Birthdate
INDEXES
Indexes
An index is an ordered set of pointers to the data in a DB2 table, stored separately from the table.
Each index is based on the values of data in one or more columns of a table.
You can use an index to:
Optimize data access.
Guarantee uniqueness.
Empno Lastname Jobcode DeptnoPage-Row
120 O'Connell 58 A00060 Stern 55 D11090 Henderson 55 D11
123
1
130 Quintana 55 C01030 Kwan 60 C01190 Walker 53 E11
123
2
290 Parker 42 E1113
Index on Empno
030 2-2060 1-2090 1-3120 1-1130 2-1190 2-3290 3-1
Index Data
DB2 TABLE
All data in a DB2 data base is stored in tables.
A table is a collection of rows, all having the same columns.
Rows are similar to record occurrences in a file.
Columns are similar to fields within a record.
Rows
Table
C o l u m n s
Field 1 Field 2Field 1 Field 2
Field 1 Field 2 Field 3 Field 4
Record
Sequential File
VIEWS
A view is a logical (or “virtual”) table that is derived from one or more tables.
It does not physically exist.
A view can:
Be made up of selected columns from a table.
Be made up of selected rows from a table.
Include data from more than one table.
• Data Security • Data Independence
View
Base TableA B C D E
1
2
3
4
5
A B D
1
2
5
SYNONYMS
Another name for a table or view
Can be used only by its creator
Can not be qualified
Only for local table or view
Synonyms
A synonym is a different name by which a table or view is known.
Synonyms can be used to:
Eliminate the need to specify the table AUTHID.
Synonyms are useful in avoiding fully qualifying table names that are frequently used, such as:
Assigned TABLE name: ACCT_TABLE TABLE created by: PLTNM01 Your USERID: STUDENT1
Without a synonym, STUDENT1 can reference the table only as: PLTNM01.ACCT_TABLE
After the creation of a synonym (by STUDENT1):
CREATE SYNONYM ACCOUNT_TABLE FORPLTNM01.ACCT_TABLE
STUDENT1 can reference the table as:
SELECT * FROM ACCOUNT_TABLE
A synonym can only be used by its creator and can only refer to a local table or view.
ALIAS
An alternate name for a table or view
Can be used by anyone . Can be qualified
Can describe local or remote tables
Are not dropped when the described table is dropped.
An alias is similar in usage to a synonym but without most of a synonym's restrictions.
Aliases are useful in assigning customer meaningful names to tables:
Assigned table name: T00101
TABLE created by: ENPIP41
After creation of alias by DBA:
CREATE ALIAS ENPIP41.ACCT_TABLE FOR
ENPIP41.T00101
Anyone can reference the table as
SELECT * FROM ENPIP41.ACCT_TABLE
Aliases are useful for accessing remote tables:
A three part name is used for remote tables:
location.creator.table
CREATE ALIAS ENPIP41.ACCT_TABLE FOR
NEWYORK.ENPIP41.ACCT_TABLE
ALIAS VS VIEW
When To Use An Alias vs. A View
FUNCTION DB2 OBJECT TO USE
Assigning customer meaningful names (local or remote)
Alias
Accessing remote tables Alias
Restricting access to certain columns and/or rows for security
View
Creating a logical view from more than one table (join)
View
Create Data Base Create Table Space Create Table Create Index Insert/Load Row
DB2
Catalog
D B 2
VSAM
VSAM Catalog
VSAM Linear
Data Set
VSAM Linear
Data SetData Base
Table Space
Index Space
Index
Table
Row
Updating DB2 Catalog
Threads
DB2Call
Attach pgm
CICS PGM
DB2Utility
TSO O/L
PGM
QMF Or
DB2I
TSOBatchpgm
IMS Batchpgm
IMS/DCPGM
Are memory structures used by DB 2 to communicate
with an application program.
Serves as links between DB 2 and application
programs.
Application programs send all requests to DB 2
through threads.
DB 2 communicates the status of each SQL statement
to the application using threads through SQLCA.
MAJOR COMPONENTS OF DB2
The four major components of DB2 are
System Services Component
Locking Services Component
Database Services Component
Distributed Data Facility Component
System Services Component, which supports System operation, Operator communication, Logging and similar functions.
Locking Services Component, which provides the necessary controls for managing concurrent access to data.
Database Services Component, which supports of the definition, retrieval and update of user and system data.
Distributed Data Facility Component, which provides DB2 database support.
DB2 Components
AlliedAgent
CICSIMSTSO
System service
LoggingRecovery
Acces to TP
VSAM
Media Manager
IRLMInternal
resource Lock
Manager
Locking
DDF
DistributedData
FacilityAccess
To distributed
data
Data
Database Service
OptimizerData manager
Buffer Manager
SYSTEM SERVICES
This system services component handles all system wide tasks.
Controlling Connections to other MVS Subsystems (CICS, IMS & TSO)
Handling system startup and shut down and operator Communication.
Managing the System log
Gathering system wide statistics performance, auditing and accounting information.
These are provided by an MVS subsystem called the IMS Resource Lock Manager (IRLM). This IRLM is used to control concurrent access to Db2 data, regardless whether IMS is present in the system or not.
LOCKING SERVICES
DATABASE SERVICES
SQL Syntax Checking
DATA DICTIONARY
PRECOMPILER
BIND
Buffer Manager
DATA MANAGER
Insertion/Reterival/ Index Maintenance
DBADM RESPONSIBILITIES
Build and maintain objects within the database.
Grants to other users the privilege to access or change objects within the database.
Perform the binds (prepare application programs to work with DB2)
DBADM is responsible for the running of most DB2 utilities
SYSADM RESPONSIBILITIES
Install new releases Grant of privileges Creating system level objects Monitoring System performance
Notes: SYSADM may install or assist in the install of DB2 and fixes.
SYSADM grants privileges (DBADM, CREATETAB, CONNECT Etc).
SYSADM creates the system level objects like Databases, Table spaces etc.
SYSADM monitors DB2’s performance using tools like DB2 PM.
PROGRAMMER RESPONSIBILITIES
Create the test environments for new applications.
• Prototypes (write and test the SQL before it is used in production).
• Check that SQL statements access the data most efficiently.
• Physically embed SQL in host language programs.
• Prepare (precompile and bind) programs for execution.
END-USER RESPONSIBILITIES
Anyone who executes an SQL statement is an end-user.
SQL can be in the applications the end-users run. SQL within the applications may read, add, change or remove data Produce reports after giving necessary input data. Write their own SQL to change data or produce reports.