670 likes | 933 Views
DB2 UDB the Basics. Keith E. Gardenhire keithgar@us.ibm.com. DB2 UDB V8.2 Basic Database Administration. Introduction. Products. DB2 Enterprise Server Edition. DB2 Workgroup Server Unlimited Edition. DB2 Workgroup Server Edition. DB2 UDB Express Edition. DB2 Personal Edition.
E N D
DB2 UDB the Basics Keith E. Gardenhire keithgar@us.ibm.com
DB2 UDB V8.2 Basic Database Administration Introduction
Products DB2 Enterprise Server Edition DB2 Workgroup Server Unlimited Edition DB2 Workgroup Server Edition DB2 UDB Express Edition DB2 Personal Edition
Instance • Manages one or more databases • Must have root or Administrator Authority to create • db2icrt is used to create an instance • db2idrop is used to drop an instance • db2iupdt is used to update the instance db2icrt -u fencedusr instance_name db2start will start an instance db2stop will stop an instance
Creating the Database • Create db database-name • Creates three table spaces • Creates System Catalog Tables
Create Database Command CREATE DATABASE dbname AS alias_name
Table Space 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
System Containers SMS Containers USING (‘container string’) DMS Containers USING (FILE ‘container string’ number of pages) (DEVICE ‘container string’ number of pages)
Table Space Example CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘/home/inst01/database/ts1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:\DMS\DATABASE\DMS01D’ 1000)
Create Tables Command Line db2 create table ARTISTS ( ARTNO SMALLINT NOT NULL, NAME VARCHAR(40), COMPANY CHAR(20), BIO CLOB (10K) NOT LOGGED, PICTURE BLOB (2700K) NOT LOGGED ) IN DMS01D INDEX IN DMS01I LONG IN DMS01L
Create Table Script File create table warehouse (itemno smallint, warehousename char(20), qty integer ) in dms03d; The script file cr_warehouse contains the above info db2 –tvf cr_warehouse
Table Characteristics Describe command db2 describe table ARTISTS Column Type Type name schema name Length Scale Nulls --------------- --------- ------------------ -------- ----- ------ ARTNO SYSIBM SMALLINT 2 0 No NAME SYSIBM VARCHAR 40 0 Yes COMPANY SYSIBM CHARACTER 20 0 Yes BIO SYSIBM CLOB 20480 0 Yes PICTURE SYSIBM BLOB 2764800 0 Yes
Moving Data • IMPORT • EXPORT • LOAD • db2move
Import / Export Import File Export
IMPORT utility IMPORT FROM filename OF IXF DEL ASC LOBS FROM lob-path MODIFIED BY options MESSAGES INSERT INTO table-name INSERT_UPDATE REPLACE REPLACE_CREATE
Export EXPORT TO file OF IXF MESSAGES message-file DEL WSF select statement
LOAD • Load Loads data, collects index keys • Build creates the indexes • Delete Delete unique key violations place into exception tables. • Index Copy – copy indexes from temp table space
LOAD Command LOAD FROM filename OF IXF ASC DEL LOBS FROM lob-path MODIFIED BY options MESSAGES message-file INSERT INTO table-name REPLACE RESTART TERMINATE
LOAD from Cursor 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 db2move db2move.lst table.ixf
db2move syntax db2move database-name import export load tc table-creators tn table-name sn schema-names ts table space-names
GUI Tools Using Graphical User Interface
Examples of Table Space CREATE TABLESPACE TS1 MANAGED BY SYSTEM USING (‘C:\SMS\MUSICKEG\TS1’) CREATE TABLESPACE DMS01D MANAGED BY DATABASE USING (FILE ‘C:\DMS\MUSICKEG\DMS01D’ 161) EXTENTSIZE 8 PREFETECHSIZE 8 CREATE TABLESPACE DMS01I MANAGED BY DATABASE USING (FILE ‘C:\DMS\MUSICKEG\DMS01I’ 48) EXTENTSIZE 4 PREFETCHSIZE 4
Recovery Defining logs Recovery of database Recovery of a table space Offline versus Online
Backup • 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
Recovery • 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
Modes of Recovery • Offline • Online RESTORE DB database-name FROM file TAKEN AT time ROLLFORWARD DATABASE database-name TO isotime AND STOP END OF LOGS
Performance and Tuning • Database Configuration parameters • Database Structure • SQL Statements