Sei sulla pagina 1di 19

Introduction to DB2 DB2 is IBMs Relational Database Management System for MVS operating system.

. DB2 can access other sub systems like IMS, CICS transaction managers, or by TSO for batch jobs. DB2 uses a centralized operational Data Dictionary. The data definition, data control and data manipulation, authorizations are performed by the Structured Query Language (SQL). DB2 provides full data security, data integrity and data recovery functions. DB2 is designed to be fast, efficient and easy to use. One of the main objectives of DB2 is to reduce application design and development efforts. DB2 runs on 5 different Address Spaces. Address Spaces DB2 subsystem comprises of 5 address spaces namely DSNMSTR DSNDBM1 IRLMPROC DSNDIST DSNSPAS

DSNMSTR (System Services): controls to other to other MVS sub-systems like IMS, CICS, TSO. supports system startup, operation, communication and shutdown. collects system statistics for performance, auditing and accounting. performs commit, rollback, checkpoint, maintaining recovery log. DSNDBM1 (Database Services) : supports definition, updation and retrieval of DB2 Data. IRLMPROC (Locking Services): To control concurrent access to data and to maintain data integrity, provided by DB2 address space IRLM. DSNDIST (Database Services) : takes care of remote access database located at different places and subsystems. DSNSPAS it provides an isolated environment in which to execute stored procedures.

Storage Groups Create stogroup HEXSG volumes (SMS001,SMS002) vcat DSN610; Database Create database HEXDB stogroup HEXSG buffer pool BP01; Table Space CREATE TABLESPACE HEXTS IN HEXDB USING STOGROUP HEXSG PRIQTY 10 SECQTY 10 NUMPARTS/SEGSIZE LOCK SIZE row/page/table PCTFREE n BUFFERPOOL BP01; Tables Create table employee (eno integer, ename varchar(10)) in database.tablespace; Index CREATE INDEX IDX ON EMPLOYEE (EMPNO ASC); View CREATE VIEW VDEPT AS SELECT DEPTNO,DEPTNAME,MGRNO FROM userid.DEPT; Database Design SPUFI SQL Referential Integrity DB2, DSN Commands Bind DCLGEN

Bind Program Used: IKJEFT01 INPUT DBRM LIB produced in precompiler step OUTPUT PLAN Function: Reads the SQL statements from DBRMs and produces a mechanism to access data from tables. Parameters given while binding: 1. Owner, Qualifier 2. Action (REPLACE/ADD) 3. Isolation (CS/RR) 4. Acquire (USE/DEALLOCATE) 5. Release (COMMIT/DEALLOCATE) 6. Validate (BIND/RUN) 7. Explain 8. Flag. Owner: Name of the owner who created the PLAN Qualifier: Name where the table reside Action: Add or Replace the existing plan Isolation: This determines the mode of page locking implemented by the programs as it runs. CS Cursor Stability: Releases the page locks as soon as another page is accessed or an COMMIT is issued. Improves concurrency. RR Repeatable Read (DEFAULT): Releases the page locks only when a COMMIT is issued. Acquire & Release Options: These options of BIND or REBIND are used to specify when DB2 is to lock the tables or tablespaces and when to release. Acquire (Allocate)/Release (Deallocate)

This option avoids deadlocks by locking the resources at the beginning. This option is opted when efficiency is more important than concurrency. Acquire (Use)/Release (Deallocate) The object is locked only when it is needed while running and unlocked only when the plan terminates. Acquire (Use)/Release (Commit) A table or tablespace is locked only when needed. The lock is released when a COMMIT or ROLLBACK statement is issued or the application process terminates. This can increase the frequency of the deadlocks. Validate: Method of checking for the existence and validity for DB2 access tables and authorization Bind: Validates at Bind time; Run Validates at run time. Flag: Returns informational, warning, error and completion messages. Bind Bind reads SQL statements from DBRM s and produces a method to access data as directed by the SQL statements being bound. It stores this access method as Plan Two types of Binds BIND PLAN, BIND PACKAGE
D 2A de sS a e B d r s pcs
MS V

DN S R S MT D2 B
s at t rs

DN B 1 S DM D2 B
s at t rs o r c n et o n cs

I L PO RMR C D2 B

S se S r i e y t m e vc s

Dt B s S r i e aa a e e vc s

L c i gS r i e o kn e vc s

BD SS

L G O

CT A

DR I

D 2A d e ss a eF n tio s B d r s pc uc n
S s e S r ic y t m ev e A d e ss a e dr s pc ======= ======= C e t a dm in an r ae n a t i c n et n o n c io s L g in t og go a t v / r h elo s c i e a c iv g B D P o e sn S S r csi g A c u t g Sa s c o nin / t t / p r o m n et a e ef r a c r c s Sa t p s u d w / t ru /h t o n C ek o t g h c p in in ey r D t b s S r ic aa a e e v e A d e ss a e dr s pc ======= ======= Dt s ae aa p c m n g mn aae et R la io a e t nl m n g mn aae et B f e m n g mn uf r a a e e t L c in vaI L ok g i RM I L RM A d e ss a e dr s pc ======= ======= L c in S r ic s o k g ev e D t C n is e c aa o s t n y D t I t gi y a a ne r t

/e o rcv

Updating the BSDS BSDS can be manually updated by CHANGE LOG INVENTORY (DSNJU003) utility. DELETE - Deletes Active or Archive log data set BSDS Contents BSDS automatically updated by DB2. - SYSTEM TIMESTAMP updated at: - STOP DB2 - Active log dataset switch - Log output buffer wrap - Single BSDS mode (error condition)

Lo B ffers g u O tp t b ffer = 4 u u u 0K 4 0 K b te (O T U F 4 0 0 0 y s U B F = 0 )

In u b ffer = 2 K p t u 8

6 K b tes (IN U F 2 ) 0 y B F = 8

E ch b ffer p g is 4 in size a u a e K O tp t b ffe u u u u rs sed fo w r ritin to th a g e ctive lo g In u b ffe u d for re in fro th a p t u rs se ad g m e ctive or arch ive lo s g

DSN commands DSN is the DB2 command processor and executes as a TSO command processor. BIND DCLGEN DSN END FREE REBIND RUN SPUFI Builds an application package or plan Produces declarations for tables or views Starts a DSN session Ends the DSN session Deletes an application package or plan Updates an application package or plan Executes an application program Executes the SQL Processor Using File Input

DB2 commands DISPLAY BUFFERPOOL Displays information about the buffer pools -DISPLAY DATABASE Displays status information about DB2 databases --START DATABASE Makes the specified database available for use

-START DB2 Initializes the DB2 subsystem (can be issued only from an MVS console) DB2 Utilities Types of Utilities - Online & Standalone Utilities MODIFY- Output MODIFY deletes image copy rows from SYSIBM.SYSCOPY and SYSIBM.SYSLGRNX. MODIFY-Example For the table space HEXDBS.HEXTS1 delete all SYSCOPY records older than 90 days MODIFY RECOVERY TABLESPACE HEXDBS.HEXTS1 DELETE AGE(90) REORG-Example REORG TABLESPACE HEXDBS.HEXTS1 UNLOAD EXTERNAL UNLDDN(SYSREC) PUNCH DDN(SYSPUNCH) LOAD-Example LOAD DATA RESUME YES INTO userid.Tablename ( DSPINDEX POSITION (2) LINENO POSITION (6) DSPLINE POSITION (80)

CHAR(2), CHAR(2), CHAR(79) )

]QUIESCE-Example QUIESCE TABLESPACE HEXDBS.HEXTS TABLESPACE HEXDBS.HEXTS1

RUNSTATS-Example RUNSTATS TABLESPACE HEXDBS.HEXTS1 EXAMPLE CHECK DATA TABLESPACE HEXDB.HEXTS FOR EXCEPTION IN MASTER USE EXMASTER IN DETAIL USE EXDETAIL DELETE YES Before Running COPY To run COPY Tablespace should not - Check Pending Status - Recovery Pending Status MERGECOPY-Example MERGECOPY TABLESPACE DSN8D51P.DSN8S51C COPYDDN (COPY1,COPY2) NEWCOPY YES REPORT-Example For REPORTing Referentially Related Table Spaces in the table space set containing table space DSN8D51A.DSN8S51E. REPORT TABLESPACESET TABLESPACE DSN8D51A.DSN8S51E STOSPACE-Example For Updating the DB2 catalog SPACE columns for storage group DSN8G510. STOSPACE STOGROUP DSN8G510 RECOVER TABLESPACE Example Recovering table spaces HEXDBS.HEXTS1 and HEXDBS.HEXA to their Quiesce point. RECOVER TABLESPACE HEXDBS.HEXTS1 TORBA X'000007425468' be under

DB2 SECURITY Security Security component of the DB2 sub system controls the access to its data and its resources One of the ways that DB2 controls access to data is through the use of identifiers There are three types of identifiers: Primary Authorization Ids Secondary Authorization Ids SQL IDs Primary Authorization Ids Generally it is the primary authorization ID that identifies a specific process For example, in the process initiated through the TSO attachment facility, the primary authorization ID is identical to the TSO logon ID A trace record identifies the process by that ID

Secondary Authorization Ids Secondary authorization IDs, which are optional, can hold additional privileges available to the process A secondary authorization ID is often a Resource Access Control Facility (RACF) group ID

For example, a process can belong to a RACF group that holds the LOAD privilege on a particular database. Any member of the group can run the LOAD utility to load table spaces in the database SQL IDs An SQL authorization ID (SQL ID) holds the privileges exercised when issuing certain dynamic SQL statements If an authorization ID of a process has SYSADM authority, then the process can set its SQL ID to any authorization ID Security Within DB2, a process can be represented by a primary authorization ID and possibly one or more secondary Ids

A privilege allows a specific function/action, sometimes, on a specific object An explicit privilege has a name and is held as the result of an SQL GRANT or REVOKE statement

PRIVILEGES There are many explicit privileges We group them into privileges over: Tables Plans Packages Databases DB2 System PRIVILEGES TABLES ALTER: ALTER TABLE to change the table definitions

DELETE: DELETE to delete rows INDEX: CREATE INDEX to create index on the table INSERT: INSERT to insert rows REFERENCES: ALTER (or) CREATE TABLE to add (or) remove a referential constraint referring to the named table (or) a list of columns in the table SELECT: SELECT to retrieve data from the table UPDATE: UPDATE to update all columns (or) specific list of columns GRANT ALL on a table can grant all table privileges listed above PRIVILEGES PLAN BIND:BIND, REBIND, FREEPLAN to bind (or) free the plan EXECUTE: RUN to use the plan when running the application PRIVILEGES Database CREATETAB: The CREATE TABLE statement, to create tables in the database CREATETS: The CREATE TABLESPACE statement, to create table spaces in the database PRIVILEGES Database CREATETAB: The CREATE TABLE statement, to create tables in the database CREATETS: The CREATE TABLESPACE statement, to create table spaces in the database PRIVILEGES Database DISPLAYDB: The DISPLAY DATABASE command, to display the database status

DROP: The DROP and ALTER DATABASE statements, to drop or alter the database DISPLAYDB: The DISPLAY DATABASE command, to display the database status DROP: The DROP and ALTER DATABASE statements, to drop or alter the database REORG: The REORG utility, to reorganize objects in the database STARTDB The START DATABASE command, to start the database REPAIR: The REPAIR and DIAGNOSE utilities (except REPAIR DBD and DIAGNOSE WAIT) to generate diagnostic information about, and repair data in, objects in the database STATS: The RUNSTATS and CHECK utilities, to gather statistics and check indexes and referential constraints for objects in the database STOPDB: The STOP DATABASE command, to stop the database PRIVILEGES DB2 System ARCHIVE The ARCHIVE LOG command, to archive the current active log DISPLAY ARCHIVE command, to give information about input archive SET ARCHIVE command, to control allocation and deallocation of tape units for archive processing.

BINDADD: The BIND subcommand with the ADD option, to create new plans and packages CREATEALIAS: The CREATE ALIAS statement, to create an alias for a table or view name CREATEDBA: The CREATE DATABASE statement, to create a database and have DBADM authority over it CREATESG: The CREATE STOGROUP statement, to create a storage group STOPALL: The STOP DB2 command, to stop DB2 Some important Catalog Tables: SYSIBM.SYSTABLES SYSIBM.TABLESPACE SYSIBM.DATABASE SYSIBM.SYSCOLUMNS SYSIBM.SYSFIELDS SYSIBM.SYSFOREIGNKEYS SYSIBM.SYSCOPY SYSIBM.SYSUSERAUTH

SYSIBM.SYSTABLES
SYSTABLE contains row for every table, view and alias of DB2 systems Syntax: SELECT* FROM SYSIBM.SYSTABLES WHERE NAME=HEXATB AND CREATOR=HEXA01; SYSIBM.SYSTABLESPACE Syntax: SELECT * FROM SYSIBM.SYSTABLESPACE SELECT * FROM SYSIBM.SYSTABLESPACE

WHERE TSNAME=HEXATS

SYSIBM.SYSTABLESPACE NAME : Name of the table space CREATOR : Authorization ID of the owner of the table space DBNAME : Name of the database which contain the tablespace DBID : Internal identifier of the database which contain the table space OBID : Internal identifier of the table space descriptor PSID : Internal identifier of the table space page set descriptor BPOOL : Name of the buffer pool used for the table space PARTITIONS: Name of the partitions of the table space LOCKRULE : Lock size of the table space P Page, R Row, S Table space, T - Table PGSIZE : Size of pages in the table space in Kilo bytes. ERASERULE : Whether the data set has to be erased when dropped. STATUS : Availability of the table space A : Available P : Table space check pending status SYSIBM.SYSTABLESPACE each database, except for database DSNDB01. Each row gives information like Database Name, Creator, Name of the Default Storage Group, Default Buffer Pool, DBID, Type of Database GD (blank if database is not a work file & W for work file) and other information.

SYSIBM.SYSDATABASE Syntax: SELECT * FROM SYSIBM.SYSDATABASE SELECT * FROM SYSIBM.SYSDATABASE WHERE NAME=DBNAME SYSIBM.SYSDATABASE NAME : Name of the database CREATOR : Authorization Id of the owner of the database STGROUP : Name of the default store group for the database BPOOL : Name of the default buffer pool of the table space. DBID : Internal identifier of the database SYSIBM.SYSDATABASE TYPE : Type of database blank : Database is not a work file DB W : Database is a work file DB. The database is DSNDB07 TIMESTAMP : Timestamp of the database. SYSIBM.SYSCOLUMNS Syntax: SELECT * FROM SYSIBM.SYSCOLUMNS SELECT NAME, TBNAME, COLTYPE, LENGTH, NULLS, DEFAULT FROM SYSIBM.SYSCOLUMNS WHERE TBNAME='DEPT' AND TBCREATOR = 'DSN8510'; NAME : Name of the column TBNAME : Name of the table or view which

TBCREATOR: COLNO : COLTYPE : LENGTH : SCALE : NULLS : UPDATES : STATSTIME:

contain the column Authorization id of the owner of the table or view that created the column Numeric place of column in the view Data type information Length attributes of the column Scale of decimal data. Whether the column can contain null values Whether the column can be updated If RUNSTATS updated the statistics, the date and time when it was last invoked.

SYSIBM.SYSFIELDS This table contains one row for every column that has a field procedure. Each row gives information like owner of the table that contain the table, Name of the table that contain the column, Numeric place of this column in the table, Name of the column, Data type of the encoded values in the field, The length attribute of the field & other information. NAME : TBNAME : TBCREATOR: COLNO FLDTYPE LENGTH SCALE FLDPROC : : : : : Name of the column Name of the table or view which contain the column Authorization id of the owner of the table or view that created the column Numeric place of column in the view Data type information Length attributes of the column Scale of decimal data. For the row describing the field procedure, the name of the procedure. For the row describing the field procedure, the size, in bytes, of the work area required for the encoding and decoding

WORKAREA:

SYSIBM.SYSFOREIGNKEYS Syntax:

SELECT A.RELNAME, A.CREATOR, A.TBNAME, B.COLNAME, B.COLNO FROM SYSIBM.SYSRELS A, SYSIBM.SYSFOREIGNKEYS B WHERE A.REFTBCREATOR = 'DSN8610' AND A.REFTBNAME = 'PROJ' AND A.RELNAME = B.RELNAME ORDER BY A.RELNAME, B.COLNO; CREATOR : Authorization id of the owner of the table that contains the column TBNAME : Name of the table that contains the column RELNAME: Constraint name of the constraint for which the column is part of the foreign key. COLNAM :Name of the column COLNO : Numeric place of the column in its table COLSEQ : Numeric place of the column in the foreign key IBMREQD : Whether the row came from the basic machine readable material (MRM) type N No Y Yes SYSIBM.SYSCOPY Syntax: SELECT DBNAME, TSNAME, ICTYPE FROM SYSIBM.SYSCOPY DBNAME : TSNAME : DSNUM : Name of the database Name of the target table space or index space Data set number within the table space. For partitioned table space, the value corresponds to the partition number for a single partition copy. Type of operation A Alter

ICTYPE

ICDATE : START_RBA: FILESEQNO DEVTYPE : DSNAME : ICTIME : SHRLEVEL DSVOLSER

B Rebuild index D Check data F Full Image copy I Incremental copy Q Quiesce R Reorg Date of entry A 48-bit positive integer that contain the LRSN of a point in the DB2 recovery log. : Type file sequence number of the copy Device type of the copy is on. For I or F, DSNAME contains the data set name. The time at which the row was inserted. : SHRLEVEL parameter on COPY C Change R Reference : The volume serial number of the dataset

SYSIBM.SYSUSERAUTH Syntax: SELECT GRANTEE FROM SYSIBM.SYSUSERAUTH WHERE SYSADMAUTH <> ' ' GRANTOR : Authorization ID of the user who granted the privileges. GRANTEE : Application id of the user who holds the privileges NAME : Database name DATEGRANTED : Granted Date TIMEGRANTED: Granted Time CREATETABAUTH: Whether the grantee can create a table within the database. G Privilege held with the GRANT option Y privilege held without the GRANT NO option

CREATETSAUTH: Whether the grantee can create a table space within database DBADMAUTH : Whether the Grantee can create database and automatically receive DBADM authority over the new database. DISPLAYAUTH : Whether the Grantee can use the display command RECOVERAUTH : Whether the Grantee can use the recover command GRANTEDTS : When the Grant statement was issued

Potrebbero piacerti anche