Introduction to DB2 DB2 is IBM’s 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.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Introduction to DB2 DB2 is IBM’s 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 SpacesDB2 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.
BindProgram Used: IKJEFT01INPUT è DBRM LIB produced in precompiler stepOUTPUT è PLAN
Function: Reads the SQL statements from DBRMs and produces a mechanism to access data from tables.Parameters given while binding:1. Owner, Qualifier2. Action (REPLACE/ADD)3. Isolation (CS/RR)4. Acquire (USE/DEALLOCATE)5. Release (COMMIT/DEALLOCATE)6. Validate (BIND/RUN)7. Explain8. 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.
BindBind 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
DB2 Address SpacesMVS
DSNMSTR DSNDBM1 IRLMPROC
DB2 DB2 DB2
starts starts
or connects
System Services Data Base Services Locking Services
BSDS LOG CAT DIR
DB2 Address space FunctionsSystem Service Address space==============Create and maintain connections
Logging to active/ archive logs
BSDS Processing
Accounting/ Stats/ performance traces
Startup/ shutdown/ Checkpointing/ recovery
Database Service Address space==============Data space management
Relational management
Buffer management
Locking via IRLM
IRLMAddress space==============Locking Services
Data ConsistencyData Integrity
Updating the BSDSBSDS can be manually updated by CHANGE LOG INVENTORY (DSNJU003) utility.
DELETE…- Deletes Active or Archive log data set
BSDS ContentsBSDS automatically updated by DB2.
- SYSTEM TIMESTAMP updated at:- STOP DB2 - Active log dataset switch- Log output buffer wrap- Single BSDS mode (error condition)
Log Buffers
Output buffer = 40K – 4000K bytes (OUTBUFF=400)
Input buffer = 28K – 60K bytes (INBUFF=28)
……….
Each buffer page is 4K in sizeOutput buffers used for writing to the active logInput buffers used for reading from the active or archive logs
DSN commandsDSN is the DB2 command processor and executes as a TSO command processor.
BIND Builds an application package or planDCLGEN Produces declarations for tables or viewsDSN Starts a DSN session END Ends the DSN sessionFREE Deletes an application package or planREBIND Updates an application package or planRUN Executes an application programSPUFI 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 DATABASEMakes the specified database available for use
-START DB2Initializes the DB2 subsystem (can be issued only from an MVS console)
DB2 UtilitiesTypes of Utilities - Online & Standalone Utilities
MODIFY- Output MODIFY deletes image copy rows from SYSIBM.SYSCOPY and SYSIBM.SYSLGRNX.
MODIFY-ExampleFor the table space HEXDBS.HEXTS1 delete all SYSCOPY records older than 90 days
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'
DB2 SECURITYSecurity
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
SELECT * FROM SYSIBM.SYSTABLESPACESELECT * FROM SYSIBM.SYSTABLESPACE WHERE TSNAME=’HEXATS’
SYSIBM.SYSTABLESPACENAME : Name of the table spaceCREATOR : Authorization ID of the owner of the table space DBNAME : Name of the database which contain the tablespaceDBID : Internal identifier of the database which contain the table spaceOBID : Internal identifier of the table space descriptorPSID : Internal identifier of the table space page set descriptorBPOOL : Name of the buffer pool used for the table spacePARTITIONS: Name of the partitions of the table spaceLOCKRULE : 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 : AvailableP : Table space check pending status
SYSIBM.SYSTABLESPACEeach 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.SYSDATABASESELECT * FROM SYSIBM.SYSDATABASE WHERE NAME=’DBNAME’
SYSIBM.SYSDATABASENAME : Name of the databaseCREATOR : Authorization Id of the owner of the databaseSTGROUP : Name of the default store group for the databaseBPOOL : Name of the default buffer pool of the table space.DBID : Internal identifier of the database
SYSIBM.SYSDATABASETYPE : Type of databaseblank : Database is not a work file DBW : Database is a work file DB. The
database is DSNDB07TIMESTAMP : Timestamp of the database.
SYSIBM.SYSCOLUMNSSyntax:SELECT * FROM SYSIBM.SYSCOLUMNSSELECT NAME, TBNAME, COLTYPE, LENGTH, NULLS, DEFAULTFROM SYSIBM.SYSCOLUMNS WHERE TBNAME='DEPT'AND TBCREATOR = 'DSN8510';NAME : Name of the columnTBNAME : Name of the table or view which contain the columnTBCREATOR: Authorization id of the owner of the table or view
that created the columnCOLNO : Numeric place of column in the viewCOLTYPE : Data type information
LENGTH : Length attributes of the columnSCALE : Scale of decimal data.NULLS : Whether the column can contain null valuesUPDATES : Whether the column can be updatedSTATSTIME: If RUNSTATS updated the statistics, the date and time when it was last invoked.
SYSIBM.SYSFIELDSThis 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 : Name of the columnTBNAME : Name of the table or view which contain the columnTBCREATOR: Authorization id of the owner of the table or view that created the columnCOLNO : Numeric place of column in the viewFLDTYPE : Data type informationLENGTH : Length attributes of the columnSCALE : Scale of decimal data.FLDPROC : For the row describing the field procedure, the name of the procedure.WORKAREA: For the row describing the field procedure, the size, in bytes, of the work area required for the encoding and decoding
SYSIBM.SYSFOREIGNKEYSSyntax:
SELECT A.RELNAME, A.CREATOR, A.TBNAME, B.COLNAME, B.COLNOFROM SYSIBM.SYSRELS A, SYSIBM.SYSFOREIGNKEYS BWHERE 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 columnTBNAME : Name of the table that contains the columnRELNAME: Constraint name of the constraint for which the column is part of the foreign key.COLNAM :Name of the columnCOLNO : Numeric place of the column in its tableCOLSEQ : Numeric place of the column in the foreign keyIBMREQD : Whether the row came from the basic machine readable material (MRM) type
N NoY Yes
SYSIBM.SYSCOPYSyntax:SELECT DBNAME, TSNAME, ICTYPE FROM SYSIBM.SYSCOPY
DBNAME : Name of the databaseTSNAME : Name of the target table space or index spaceDSNUM : Data set number within the table space. For partitioned table space, the value corresponds to the
partition number for a single partition copy.ICTYPE : Type of operation
A AlterB Rebuild indexD Check dataF Full Image copyI Incremental copyQ QuiesceR Reorg
ICDATE : Date of entry
START_RBA: A 48-bit positive integer that contain the LRSN of a point in the DB2 recovery log.FILESEQNO : Type file sequence number of the copyDEVTYPE : Device type of the copy is on.DSNAME : For “I” or “F”, DSNAME contains the data set name.ICTIME : The time at which the row was inserted.SHRLEVEL : SHRLEVEL parameter on COPY
C ChangeR Reference
DSVOLSER : The volume serial number of the dataset
SYSIBM.SYSUSERAUTHSyntax:SELECT GRANTEE FROM SYSIBM.SYSUSERAUTHWHERE SYSADMAUTH <> ' '
GRANTOR : Authorization ID of the user who granted the privileges.
GRANTEE : Application id of the user who holds the privileges
NAME : Database nameDATEGRANTED : Granted DateTIMEGRANTED: Granted TimeCREATETABAUTH: Whether the grantee can
create a table within thedatabase.
G Privilege held with the GRANT optionY privilege held without the GRANT NO option
CREATETSAUTH: Whether the grantee can create a table space within databaseDBADMAUTH : 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