labora normal

Upload: luis-zaconeta

Post on 07-Aug-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 labora normal

    1/198

    DB2 9 Database

    Administration Workshop forLinux(Course code CL2X2)

    Student ExercisesERC 10.3

    IBM certified course material

    5.3

    over

    Front cover

  • 8/21/2019 labora normal

    2/198

    Student Exercises

    July 2010 edition

    The information contained in this document has not been submitted to any formal IBM test and is distributed on an as is basis withoutany warranty either express or implied. The use of this information or the implementation of any of these techniques is a customerresponsibility and depends on the customers ability to evaluate and integrate them into the customers operational environment. Whileeach item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results willresult elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk.

    Copyright International Business Machines Corporation 1999, 2010. All rights reserved.

    This document may not be reproduced in whole or in part without the prior written permission of IBM.

    Note to U.S. Government Users Documentation related to restricted rights Use, duplication or disclosure is subject to restrictionsset forth in GSA ADP Schedule Contract with IBM Corp.

    Trademarks

    IBM is a registered trademark of International Business Machines Corporation.

    The following are trademarks of International Business Machines Corporation in the United

    States, or other countries, or both:

    VMware and the VMware "boxes" logo and design, Virtual SMP and VMotion are

    registered trademarks or trademarks (the "Marks") of VMware, Inc. in the United Statesand/or other jurisdictions.

    Intel and Pentium are trademarks or registered trademarks of Intel Corporation or its

    subsidiaries in the United States and other countries.

    Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc.in the United States, other countries, or both.

    Linux is a registered trademark of Linus Torvalds in the United States, other countries, or

    both.

    Microsoft, Windows, Windows NT and Windows Vista are trademarks of MicrosoftCorporation in the United States, other countries, or both.

    UNIX is a registered trademark of The Open Group in the United States and other

    countries.

    AMD, and combinations thereof, is a trademark of Advanced Micro Devices, Inc.

    Other company, product, or service names may be trademarks or service marks of others.

    AIX AIX 5L Approach

    CICS ClearCase DB2

    DB2 Connect DB2 Universal DatabaseDistributed RelationalDatabase Architecture

    DRDA Express Informix

    InfoSphere iSeries LotusScript

    Lotus MQSeries Optim

    OS/390 OS/400 pSeries

    S/390 Symphony Tivoli

    WebSphere z/OS zSeries

    1-2-3

  • 8/21/2019 labora normal

    3/198

    Student Exercises

    5.3

    OC

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Contents iii

    Contents

    Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

    Exercises description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

    Exercise 1. Starting your lab environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

    Starting the VMware image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

    Exercise 2. DB2 CLP usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

    Section 1: Exploring the CLP usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2Section 2: Exploring the CLPPlus usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3Section 3: Looking at Release Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6

    Exercise 3. Create an instance and explore the environment . . . . . . . . . . . . . . . . . 3-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Section 1: Creating the instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Section 2: Checking your environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6Section 3: Exploring DB2 and Setting up Remote Connectivity . . . . . . . . . . . . . . . 3-8Section 4: Setup for Remaining Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

    Exercise 4. Creating databases and data placement . . . . . . . . . . . . . . . . . . . . . . . . 4-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Section 1: Creating the database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

    Section 2: Creating Table Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11Script files used for lab4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19

    Exercise 5. Create objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2Section 1: Create Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3Section 2: Create Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9Section 3: Create Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12Section 4: Create Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14Section 5: Add Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16Section 6: Add Check Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20Section 7: Create a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22Section 8: Working with Temporary tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24Section 9 (Optional): Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27Script files used for lab5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30

    Exercise 6. Moving data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2

  • 8/21/2019 labora normal

    4/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    iv DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-2Section 1: Import Data in Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-2Section 2: Create Exception Tables ARTISTS, ALBUMS, STOCK . . . . . . . . . . . .6-5Section 3: Backup Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-6Section 4: Load Data with INSERT option into CONCERTS . . . . . . . . . . . . . . . . . .6-7Section 5: Load Data with REPLACE option into ARTISTS . . . . . . . . . . . . . . . . . . .6-9Section 6: Examining the SET INTEGRITY PENDING State . . . . . . . . . . . . . . . . .6-11

    Section 7: Understanding CHECK CONSTRAINT Enforcement . . . . . . . . . . . . . .6-15Section 8: Understanding TRIGGER Enforcement . . . . . . . . . . . . . . . . . . . . . . . . .6-17Section 9: Using the db2look tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-19Section 10 (Optional): Working with LOB Data . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-20Script files used for lab6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-24

    Exercise 7. Backup and recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-2Section 1: Determining Log Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-2

    Section 2: Backup/Restore Support with Archive Logging . . . . . . . . . . . . . . . . . . . .7-7Section 3: Resetting the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-15Script files used for lab7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-16

    Exercise 8. Investigating DB2 locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-3Section 1: Basic Lock Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-4Section 2: Lock Timeouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-7Section 3: Deadlocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-12Section 4: Resetting the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-14

    Script files used for lab8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-15

    Exercise 9. Problem determination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2

    Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-2Section 1: Collecting information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-2Section 2: Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-6Section 3: Reset DIAGLEVEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-8Script files used for lab9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-9

    Exercise 10. Security (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1

    Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2Section 0: Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-2Section 1: Default PUBLIC Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-2Section 2: DB2 Authorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-8Section 3: DB2 User and Group Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-15Section 4: Database roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-21Section 5: Resetting the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-23Script files used for lab10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-24

  • 8/21/2019 labora normal

    5/198

    Student Exercises

    5.3

    OC

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Contents v

    Appendix A. UNIX vi Editor command summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1

    Appendix B. Application performance tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1Exercise instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2

    Section 1: Access strategies and utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2Script files used for labappdxc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7

  • 8/21/2019 labora normal

    6/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    vi DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

  • 8/21/2019 labora normal

    7/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Trademarks vii

    5.4

    MK Trademarks

    The reader should recognize that the following terms, which appear in the content of this

    training document, are official trademarks of IBM or other companies:

    IBM and the IBM logo are registered trademarks of International Business Machines

    Corporation.

    The following are trademarks of International Business Machines Corporation, registered in

    many jurisdictions worldwide:

    Windows is a trademark of Microsoft Corporation in the United States, other countries, or

    both.

    Linux is a trademark of Linus Torvalds in the United States, other countries, or both.

    Other company, product, or service names may be trademarks or service marks of others.

    AIX AIX 5L Approach

    CICS ClearCase DB2

    DB2 Connect DB2 Universal DatabaseDistributed RelationalDatabase Architecture

    DRDA Express Informix

    InfoSphere iSeries LotusScript

    Lotus MQSeries OptimOS/390 OS/400 pSeries

    S/390 Symphony Tivoli

    WebSphere z/OS zSeries

    1-2-3

  • 8/21/2019 labora normal

    8/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    viii DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

  • 8/21/2019 labora normal

    9/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercises description ix

    4.0

    ef Exercises description

    The students will learn how to administer a Linux database server using either DB2's GUI

    interface or a DB2 Command Window.

    DO NOT CHANGE ANY OF YOUR PASSWORDS!Each exercise in this course is divided into sections as described below.

    Objectives This section outlines the learning points of the exercise.

    Reference Materials List of documents which you may find useful in performing theexercise.

    Lab Exercise The step-by-step guide to the lab.

    The exercise instructions include hints to help you perform the tasks requested or to

    provide answers to the questions posed in the exercise. Where possible, both the Terminal

    session and the GUI solutions are given.Optional Exercises This section gives you additional exercises to perform relating to the

    unit of discussion. It is strictly optional and should be performed when you have completedthe required exercises. The required exercises pertain to the most pertinent information

    provided in the unit. This section may help round out the hands-on experience for a relatedunit.

    Table 0-1: Lab Guide Substitutions

    Description Your Value Substitution in Lab GuideStudent User ID inst20

    Roots Password dalvm3

    Server hostname ibmclass

    Administrative Server dasusr1

    Admin Server Password ibm2blue

    Initial User Name inst00

    Initial User Password ibm2blue

  • 8/21/2019 labora normal

    10/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    x DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Lab environment

    Copyright IBM Corporation 2010

    Artistsartno name classification bio picture

    inx Pk CLOB BLOB

    TS tsp02 tsp01 tsp03

    Albums

    itemno title artno

    inx Pk Fk

    TS tsp05 tsp04

    Stock

    itemno type price qty

    inx Fk cc trigger

    TS tsp06

    Reorder

    itemno timestamp

    trigger trigger

    tsp07

    Check Constraint: cctype

    Stock.type = D or C or R

    Trigger: reorder

    Stock.qty

  • 8/21/2019 labora normal

    11/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 1. Starting your lab environment 1-1

    4.0

    empty Exercise 1. Starting your lab environment

    What this exercise is about

    This exercise covers the use of VMware Player. Your lab environment

    is a virtual machine image, used with the VMware Player product or inthe case where you are attending the ILO (3L2X), you will use an eLab

    environment to perform the exercises.

    What you should be able to do

    At the end of the exercise, you should be able to:

    Find your DB2 VMware virtual machine image

    Start your DB2 VMware virtual machine image using VMware

    Player

    Introduction

    You will use a VMware virtual machine (VM) image to run exerciseswithin. The DB2 VMware VM lab image you will use is a Linux image,

    in a single user environment.

    This image contains the DB2 server used for the CL2X and 3L2Xcourses.

  • 8/21/2019 labora normal

    12/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    1-2 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Exercise instructions

    Starting the VMware image

    Note

    If you are in the ILO class - 3L2X - then your instructor will inform you of how you can usean eLab environment for your exercises.

    Note

    Steps 1 through 3 are not used for the eLab environment.

    The VMware VM (virtual machine) image you will be using is a Virtual Machine image of anoperating system, run within the native Windows operating system of your computer.

    __ 1. Logon to your student workstation with the username and password supplied by

    your instructor.

    ________________________________________________________________

    __ 2. Start a Linux VMware VM image on your computer.

    __ a. On your local computer, find the VMware Player icon and start it.

    __ b. The VMware Player window opens, which is a browser. Navigate on the browserto the location of your VMware VM image (your instructor will inform you of the

    location).

    ________________________________________________________________

    __ c. Select the file with the .vmxextension, whose icon looks like this:

    __ d. Click the Openbutton.

    __ 3. This starts your Virtual Machine image. The image has preset parameters which willensure that the native OS will not be overtaxed for resources.

    __ 4. Logon to the system within your VM image. Your username and password for thelocal Linux system is: inst00

    ibm2blue

    __ 5. Become familiar with the method of file handling and navigation for the system youare using.

  • 8/21/2019 labora normal

    13/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 1. Starting your lab environment 1-3

    4.0

    emptyLinux

    SUSE:Right-click the inst00s Home icon in the upper left of the screen, and

    select Browse Folder. This opens a window similar to Windows Explorer that youcan use to work with files in the various directories. Double-click the Filesystem

    icon.

    __ 6. Maximize your VMware VM image by clicking the Maximizeicon on the upper rightof your image window.

    __ 7. Leave your Virtual Machine image running while we continue the class.

    End of exercise

  • 8/21/2019 labora normal

    14/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    1-4 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

  • 8/21/2019 labora normal

    15/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 2. DB2 CLP usage 2-1

    4.0

    empty Exercise 2. DB2 CLP usage

    What this exercise is about

    This exercise will let you explore the CLP and DB2 GUIs, making you

    familiar with them by using the DB2 default instance - inst00 - and theSAMPLE database.

    What you should be able to do

    At the end of the exercise, students should be able to:

    Use the CLP

    Use the different GUIs

    Know the possibilities of the CLP and the GUIs

    Introduction

    Before class started, the DB2 product was installed on the Databaseserver that you are using. A Database Administration Server (DAS)

    was also created and started. Also the default DB2 instance with theSAMPLE database was created. You will now be able to familiarize

    yourself with the CLP and the GUIs.

    Refer to Appendix Bfor the SAMPLE database model.

    The general approach taken in the classroom for DB2 9 is to use aVMware VM image running on the same PC that you log into.

    When you are using Linux commands, there might be slightdifferences depending on the versions of Linux (RedHat, SuSE, ...).

  • 8/21/2019 labora normal

    16/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    2-2 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Exercise instructions

    Section 1: Exploring the CLP usage

    Because you will use the default DB2 instance and the sample database, you must logon

    with the appropriate userid and password to be able to perform all operations.

    Note

    You might have already completed Step 1 in Exercise 1.

    __ 1. At the VMware Linux VM image, enter the username and password on the GUI loginscreen of the virtual machine (VM). If this VM has to be started, the instructor will

    give you directions on how to do so.

    Enter inst00as the UsernameEnter ibm2blueas the Password

    (Your login and password might differ, depending on the classroom environment and

    setup. The instructor will give you the username and password if these are differentin your classroom.)

    __ 2. If not already done, open a Terminal session.

    __ a. Right-click the empty Linux desktop and select Open Terminal.

    __ 3. First, try to get general information about commands that can be used in the CLP.

    db2 ? | more

    You will get a list with all possible commands. Scroll through this list to see thepossibilities.

    __ 4. Now examine what can be done with the getcommand.

    db2 ? get | more

    ________________________________________________________________

    __ 5. Next lets assume you receive an SQLSTATE=08003. How you can determine whatthis SQLSTATE means? Execute the correct command and explain the meaning.

    ________________________________________________________________

    __ 6. Next lets examine the options set for your CLP session. Issue the correct command

    and determine which options are set to on.

    ________________________________________________________________

    ________________________________________________________________

  • 8/21/2019 labora normal

    17/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 2. DB2 CLP usage 2-3

    4.0

    empty __ 7. Next lets create a script with the name myscript00.cmd, which connects to the

    sampledatabase, selects the columns empnoand lastnamefrom the table

    employeeand lists the database manager configuration. Use the appropriate tool(for example, gedit or vi) to create and save the script.

    gedit myscript00.cmd

    or

    vi myscript00.cmd

    Enter these lines in the file:

    db2start;

    connect to sample;

    select name, price from product;

    get dbm cfg;

    If using vi, save this by issuing :wqwithin vi.

    __ 8. Now execute the created script using your CLP session and echo the current

    command.

    db2 -tvf myscript00.cmd

    __ 9. As there is a lot of information returned from the select statement and the database

    manager configuration, it might be helpful to store the information in a file called

    myout00.txtto be able to examine it step by step. Execute the script again and

    save the output in a file named myout00.txt.

    db2 -tvf myscript00.cmd -z myout00.txt

    __ 10. You can now examine the file using the morecommand.

    more myout00.txt

    Section 2: Exploring the CLPPlus usage

    This is a short lab, exposing you to the use of Command Line Processor Plus (CLPPlus).

    __ 1. There are several ways that you can use CLPPlus to connect to a database.

    __ a. The first way is to issue a command string that starts CLPPlus and connects to adatabase at the same time. On a DB2 command window, issue:

    clpplus inst00@localhost:30000/sample

    When asked for the password, enter ibm2blue.

    Notice that you are connected to the SAMPLE database as the inst00user.

    __ 2. Now exit CLPPlus (with either exit or quit):

    exit;

    __ 3. Start CLPPlus again, but with no arguments:

  • 8/21/2019 labora normal

    18/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    2-4 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    clpplus

    Notice you are not connected to a database yet.

    __ a. Connect to the SAMPLE database.

    CONNECT inst00/ibm2blue@localhost:30000/sample

    Note

    If you cannot use the @ key for some reason, simple issue the CONNECT commandand you will be prompted for the rest of the information needed.

    __ b. You should see:

    C:\Documents and Settings\inst00>clpplus

    CLPPlus: Version 1.0

    Copyright (c) 2009, IBM CORPORATION. All rights reserved.

    SQL> CONNECT inst00/ibm2blue@localhost:30000/sample

    Database Connection Information

    Hostname = localhost

    Database server = DB2/NT SQL09070

    SQL authorization ID = inst00

    Local database alias = SAMPLE

    Port = 30000

    SQL>

    __ 4. Now create a new table (test) in the SAMPLE database that you can use:

    Note

    You must include the statement terminator character; in this case, the semi-colon

    (;), whenever you issue a command with CLPPlus.

    CREATE TABLE test (c1 int, c2 char(20));

    __ a. Now check the table structure with DESCRIBE:

    DESCRIBE test;

    __ b. Populate the table by inserting a new row of data:

    INSERT INTO test VALUES (1, 'TEST');

  • 8/21/2019 labora normal

    19/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 2. DB2 CLP usage 2-5

    4.0

    empty __ c. Now retrieve data from the test table:

    SELECT * FROM test;

    __ d. Update a row of data in the test table:

    UPDATE test SET c2 = 'HOME';

    __ e. Now check your change:

    SELECT * FROM test;

    __ 5. Finally, drop the test table and exit the CLPPlus utility:

    drop table test;

    quit;

  • 8/21/2019 labora normal

    20/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    2-6 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Section 3: Looking at Release Notes

    __ 1. Look at the files located in the Readme subdirectory. They are located in the DB2installation directory, under Readme/en_US.iso88591(or similar directory). Thesefiles will redirect you to a URL that contains the Release Notes.

    __ 2. Start the Control Center: enter db2cc &. When given the opportunity to select the

    Control Center view, just click the OKbutton. This will provide the advanced view.

    __ 3. Click the + next to the All Databases folder in the left pane. Select the + left of the

    SAMPLE database to explore what is under the database. You will see folders likeTables, Views, Aliases, and so forth.

    __ 4. Next click the folder named TABLES. In the Contents pane, all tables are shown.

    __ 5. Select the EMPLOYEEtable. What is displayed in the Detail pane?

    ________________________________________________________________

    ________________________________________________________________

    __ 6. Now click the OPENtab in the Detailpane. What is the result?

    ________________________________________________________________________________________________________________________________

    __ 7. Close this window and click the QUERYtab. What happens now?

    ________________________________________________________________

    ________________________________________________________________

    __ 8. Leave the select * line and add a line with the following: select empno fromemployee; and execute this using the green arrow on the top left corner or bypressing Ctrland Enter. Is the execution of two SQL statements successful and are

    the results displayed under the Query results tab?________________________________________________________________

    ________________________________________________________________

    __ 9. Change back to the Control Center using the appropriate button (Object View tab),and examine the different options by first selecting database and then right-clicking

    the database.

    Repeat this examination for other objects like instance, table, and so forth.

    Terminal

    more /opt/ibm/db2/V9.7/Readme/en*/Release.Notes

    This file will instruct you to view the Release notes at this web site:

    http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com

    .ibm.db2.luw.common.doc/doc/c0023859.html

  • 8/21/2019 labora normal

    21/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 2. DB2 CLP usage 2-7

    4.0

    empty __ 10. You can also examine the other files under sqllib subdirectory.

    ls -l sqllib

    __ 11. Determine your systems DB2 registry values:

    db2set -all

    __ 12. Log off asinst00from the Windows XP VM image.

    End of exercises

  • 8/21/2019 labora normal

    22/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    2-8 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

  • 8/21/2019 labora normal

    23/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 3. Create an instance and explore the environment 3-1

    4.0

    empty Exercise 3. Create an instance and explore theenvironment

    What this exercise is about

    In this exercise, you will create an instance on the Linux databaseserver to be prepared for further steps.

    What this unit is about

    At the end of the exercise, students should be able to:

    Create an instance

    Set environment variables Determine the type of DB2 installation from the Database Manager

    Configuration file Define the Administration Server (DAS) and a database instance

    through the DB2 Control Center on the remote administrativesystem

    Introduction

    You will now perform the steps needed to create an instance andexamine what file structures are built when creating an instance.

    The general approach taken in the classroom for DB2 9 is to use aVMware VM image running on the same PC that you login to.

    When you are using Linux commands, there may be slight differencesdepending on the versions of Linux (RedHat, SuSE, ...).

  • 8/21/2019 labora normal

    24/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    3-2 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Exercise instructions

    Section 1: Creating the instance

    Note

    For the single-user VMware Linux environment, your user ID will generally be inst20.

    Note

    You may have already completed Step 1 in a previous exercise.

    __ 1. Log in as inst00.

    login: inst00

    inst00s Password: ibm2blue

    The login dialog may be different depending on the vendor of the Linux system

    but will always require a username and password.

    __ 2. If not already done, open a Terminal session.

    __ a. Right-click the empty Linux desktop and select Open Terminal.

    You may get a message that the db2profile cannot be found this can be

    ignored at this time.

    __ b. You will need to start the DAS to use the GUIs.

    su - dasusr1

    (password is ibm2blue)

    db2admin start

    exit

    __ 3. Switch user to root.

    su - rootEnter root's password that your instructor gave you.

  • 8/21/2019 labora normal

    25/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 3. Create an instance and explore the environment 3-3

    4.0

    empty

    __ 4. Create your FencedID user group named fence20. The use of the term Fencedwill

    be discussed in lecture later.

    __ 5. Create your user group named adm20. This will be used to provide a level ofauthorization in the database server.

    __ 6. Create your instance user name called inst20. inst20's primary group should be

    adm20.

    __ 7. Create your fenced user name of fenced20. The primary group for fenced20should

    be fence20.

    Background Information Do not execute these steps.

    The command syntax to create a DB2 Instance on your Linux server is(DO NOT issue this command now; it will be issued later):

    db2icrt -u FencedID InstName

    You must be the Linux system administrator (root) in order to execute thiscommand. The command can be found in the DB2DIR/instancedirectory

    where DB2DIR =

    /opt/ibm/db2/V9.7

    As an alternative, you can have the DB2 Installer utility, db2setup, create thegroups and usernames for the DB2 Administration Server and a default user

    instance. The DB2 Installer program can also be used to create additionalinstances after the DB2 product is installed. Reference the appropriate chapter

    for your operating system in the Quick Beginnings Guide.

    The InstName and FencedID names must already exist before you issue the

    db2icrtcommand. You also need separate and unique Group names for theInstName and FencedID names for security purposes. The next set of stepshave you create Linux group names and user names for InstName and

    FencedID.

    Terminal groupadd fence20

    Terminal groupadd adm20

    Terminal useradd -m -g adm20inst20

    Terminal useradd -m -g fence20fenced20

  • 8/21/2019 labora normal

    26/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    3-4 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 8. Provide a password for user inst20. inst20's password should be ibm2blue.

    __ 9. Provide a password for user fenced20. fenced20's password should be ibm2blue.

    __ 10. You are now ready to create your instance. Create your instance using inst20forInstName and fenced20for FencedID. This command may take a few minutes to

    execute.

    Remember, since you are logged in as root,the Linux operating system will notautomatically look in the current directory for an executable, so you must eitherspecify the complete path, or tell the operating system to look in the current directory

    by prefixing the command with ./as in ./db2icrt. (Thats a dot slash).

    /opt/ibm/db2/V9.7/instance/db2icrt -u fenced20 inst20

    Note

    You may get an error indicating that ulimit cannot raise limit, but you should also

    see a DB2 return code (DBI1070I) that indicates that the program db2icrtcompleted successfully.

    __ 11. Look at the instances that have been created using the db2ilistcommand. Doyou see any other instances?

    _______________________________________________________________

    /opt/ibm/db2/V9.7/instance/db2ilist

    Terminal

    ibmclass:~ # passwd inst20

    Changing password for inst20.

    New Password:Reenter New Password:

    Password changed.

    ibmclass:~ #

    Terminal

    ibmclass:~ # passwd fenced20

    Changing password for fenced20.

    New Password:

    Reenter New Password:

    Password changed.

    ibmclass:~ #

  • 8/21/2019 labora normal

    27/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 3. Create an instance and explore the environment 3-5

    4.0

    empty __ 12. When you created your instance, a directory named sqllib was added under theHOME directory of the instance (/home/inst20). List the attributes of this directory

    by executing the following Linux command:

    ls -dl /home/inst20/sqllib

    The output should look like this:

    drwxrwsr-t 15 inst20 adm20 1072 Jun 30 14:01 /home/inst20/sqllib__ 13. What is the owner name?

    ________________________________________________________________

    __ 14. What is the group name?

    ________________________________________________________________

    __ 15. What file permissions does the owner have?

    ________________________________________________________________

    __ 16. What file permissions does the group have?________________________________________________________________

    __ 17. What file permissions do the users have?

    ________________________________________________________________

  • 8/21/2019 labora normal

    28/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    3-6 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Section 2: Checking your environment

    You will now exit from your session as rootand become the Database Server instanceowner. You no longer need to be the Linux administrator to configure DB2.

    __ 1. Exit from your current terminal session.

    exit (exit from root)

    exit (exit from inst00)

    This will close your Linux terminal session.

    __ 2. Log out from the Linux image.

    __ a. Click the Computermenu at the bottom left of the Linux screen and select

    Logout.

    __ b. Click Log Out.

    __ 3. Log in as inst20. If prompted to change your password, continue to use ibm2blueas the password.

    Your login dialog may be different depending on the vendor of the Linux system

    but will always require a username and password. If you have to enter a new

    password, you will always have to do so twice to verify that you typed the new

    password consistently.

    __ 4. On Linux systems, DB2 creates a profile named db2profilewhich is used to set

    your sessions environment when you log in. Look at the file sqllib/db2profile.

    __ a. Open a terminal session by right-clicking the empty Linux desktop and select

    Open Terminal.

    cdmore sqllib/db2profile

    Note

    To increase the font size on your Terminal window, click on the Editmenu and

    select Current Profile...

    Then uncheck the'Use the system terminal font' box.

    Click the Closebutton.

    __ 5. What will the DB2INSTANCE variable be set to?

    ________________________________________________________________

    __ 6. Quit the more command (type q).

  • 8/21/2019 labora normal

    29/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 3. Create an instance and explore the environment 3-7

    4.0

    empty __ 7. When you created your instance, the db2icrtcommand updated your .bashrctoexecute the db2profilecommand file. Look at your .bashrcfile. Note the lines

    added by DB2 to execute your db2profile.

    You should see lines that indicate:

    # The following three lines have been added by DB2.

    if [ -f /home/inst20/sqllib/db2profile ]; then

    . /home/inst20/sqllib/db2profile

    fi

  • 8/21/2019 labora normal

    30/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    3-8 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Section 3: Exploring DB2 and Setting up Remote Connectivity

    __ 1. Issue the db2 getcommand that shows your current instance value.

    ________________________________________________________________

    __ 2. Issue the db2 getcommand that shows your database manager configuration fileparameters. (Pipe to more.)

    ________________________________________________________________

    __ 3. What is your node type?

    Note

    Second textual line from the top in the previous step.

    ________________________________________________________________(If it is NOT Enterprise Server Edition with local and remote clients,

    Communication Support may not have been installed correctly contact yourinstructor.)

    __ 4. What is the default database path?

    ________________________________________________________________

    __ 5. How is the authentication set for your instance (where will the userid/password be

    validated)?

    __________________________________________________________________ 6. Look at your DB2 Registry variables by issuing the following command:

    db2set -all

    __ 7. What is the DB2 Administration Server (DAS) name?

    ________________________________________________________________

    __ 8. Look at the entry for the DB2 System Name it should be set to the machine namefor your server computer.

    ________________________________________________________________

    __ 9. Update your Database Manager Configuration file to add the correct SYSADMGroup (this may already be done for you). Issue the following command:

    db2 update dbm cfg using sysadm_group adm20

    __ 10. Update your Database Manager Configuration file to add a TCP/IP Port number in

    order to support remote communications. First, find the port number you will beusing:

    view /etc/services

  • 8/21/2019 labora normal

    31/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 3. Create an instance and explore the environment 3-9

    4.0

    empty Type Gto get to the bottom of the file. Your port number (previously set up for you)should be 30200. Issue :q!to exit the view.

    __ 11. Issue the following command:

    db2 update dbm cfg using svcename 30200

    __ 12. Set the DB2COMM variable in your DB2 Registry indicating that you support TCP/IP

    communications to your instance. Issue the following command:db2set DB2COMM=TCPIP -i inst20

    __ 13. Look at your DB2 Registry variables by issuing the following command:

    db2set -all

    __ 14. What value is DB2COMM set to?

    ________________________________________________________________

    __ 15. Start your instance by issuing the db2startcommand. If you receive an errormessage about not being able to start communications, contact your instructor.

    Note

    If you get a message about using evaluation period licenses, this can be ignored.

    ________________________________________________________________

  • 8/21/2019 labora normal

    32/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    3-10 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Section 4: Setup for Remaining Exercises

    __ 1. Copy the files from the labfilessource directory to your home directory by issuing thefollowing commands. Ignore any error messages about not having permissions

    (some files are not to be copied).

    cd

    cp -r /home/labfiles/cl2x/lab* .ls

    Note

    In the above task, the cl2x is lowercase CL2X.

    End of exercises

  • 8/21/2019 labora normal

    33/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-1

    4.0

    empty Exercise 4. Creating databases and dataplacement

    What this exercise is about

    During this exercise, you will create your database and your tablespaces. Also in this exercise, you will select information on table

    spaces from the system catalog (SYSCAT) views.

    What you should be able to do

    At the end of the exercise, students should be able to:

    Create a database Create a table space

    Execute a script file to create multiple table spaces Access the SYSCAT views containing table space information

    List table space information List container information

    Introduction

    This exercise will step you through the creation of your database andthe table spaces that will be needed to hold the tables in your

    database. In most cases, you will have an option in this exercise toperform the functions using either of:

    Using a Terminal session on your Linux system (referred to as

    Terminal) Using the graphical tools on your Linux system (referred to as GUI)

  • 8/21/2019 labora normal

    34/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-2 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Exercise instructions

    Section 0: Setup

    If not already done, start your Linux VMware VM image and log in as the inst20 user.

    __ 1. If not already done, open a Terminal session.__ a. Right-click the empty Linux desktop and select Open Terminal.

    Section 1: Creating the database

    You will be looking at the create database command and determining what would be

    produced if you ran it. DO NOT create the database until the exercise specifically

    instructs you to do so.

    __ 1. Creating a database can be done with the DB2 command create database. Use the

    online help facility to display the DB2 command syntax for create database.

    __ 2. What information can you specify on the create database command?

    ________________________________________________________________

    __ 3. Based on what you learned in lecture, what table spaces are created when a

    database is created?

    ________________________________________________________________

    __ 4. What type of table space, SMS or DMS, will your database use by default for thesedefault table spaces?

    ________________________________________________________________

    Terminal db2 ? create db | more

    GUI

    __ Start the DB2 Control Centerby entering db2cc &on your Terminalsession. This starts the DB2 Control Centerin the background, so you

    can continue to use the Terminal session for other things.

    __ From the DB2 Control Center, open the Command Editor(either choosethe Tools option on the menu bar and then select Command Editor, or

    choose the Command Editor icon on the tool bar (4th from the left)).

    __ From the DB2 Command Editor, in the Commandsbox, enter:

    ? create database

    __ Choose Selectedfrom the menu bar.

    __ Select Executefrom the pull-down menu.

  • 8/21/2019 labora normal

    35/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-3

    4.0

    empty __ 5. Before we create our MUSICDBdatabase, remember what you learned in lectureabout what some of the defaults will be.

    What is the default path that the database will be created on?

    What will be the default table space type (SMS or DMS) for the table spaces that

    will be created to hold User Tables, Catalog Tables, and Temporary Tables?

    What are the default Extent and Prefetch sizes? What are the default Territory, Code Set and Collating Sequence values?

    _______________________________________________________________

    __ 6. Create your database with a Database name of MUSICDBusing the directories

    shown. It will take a few minutes to create the database.

    TerminalFrom your Terminal session, run the following command:

    db2 create db musicdb on /dbauto/path1 dbpath on /database

  • 8/21/2019 labora normal

    36/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-4 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 7. You should now have your MUSICDBdatabase created. The System Database

    Directorycontains an entry for all databases known by this instance. Check the

    System Database Directoryfor an entry for the MUSICDBdatabase by issuing thelist db directorycommand.

    GUI

    To start the Control Center, enter the following command in a Terminal

    session:

    db2cc &

    From the Control Center, click the +next to your INST20 instance, and thenright-click the Databasesfolder and select Create Database -> Standard.

    __ On the Namepage, enter a database name of MUSICDB. The default isto let DB2 manage the storage, but change that and specify the dbpathbe placed in the /databasedirectory while the database datawill be

    placed in the /dbauto/path1directory.

    __ On the Regionpage, make sure Country/Regionis set to default. (If yourinstructor has told you to use a different language, please verify the

    change with your instructor.)

    __ Accept the values for Territory and Codeset.

    __ Select the System Collating Sequenceradio button.

    __ On the Summarypage, click Show Command. Look at the generated

    command and Closethe Show Commandwindow.

    __ Click the Finishbutton.

    __ Wait a couple of minutes while your database is being created. Youmight receive an information message that you could launch the

    Configuration Advisorto tune your database. Do not use the

    Configuration Advisorat this time. Click the Nobutton.

    __ Your database will appear under the Databasesfolder in the left pane of

    your DB2 Control Centerpanel. Select the +next to the Databasefolderto see your MUSICDBdatabase listed.

    Note:The first request that you make from the client to access information

    in the database (for example, if you look at the list of tables via the DB2

    Control Center) will automatically bind a number of packages to support the

    client utilities. This might take a few moments; please be patient.

    Terminal db2 list db directory

  • 8/21/2019 labora normal

    37/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-5

    4.0

    empty

    __ 8. What is the Database alias name and where did it come from?________________________________________________________________

    __ 9. What does a Directory entry type of Indirect mean?

    ________________________________________________________________

    __ 10. It is time to connect to your MUSICDBdatabase. Check your current connectionstate with the get connection statecommand.

    __ 11. What is the connection state?

    ________________________________________________________________

    __ 12. Connect to your MUSICDBdatabase.

    __ 13. Did you get connected to your MUSICDBdatabase?

    ________________________________________________________________

    __ 14. Check your connection state again. What does it show?

    ________________________________________________________________

    GUI

    __ From the DB2 Command Editor, enter:

    list db directory

    __ Press Ctrl-Enterto cause the command to be executed.

    Terminal db2 get connection state

    GUI

    From the DB2 Command Editor, enter:

    get connection state

    Select the green arrow icon under the Commandstab to execute the

    command.

    Terminal db2 connect to musicdb

    GUIFrom the DB2 Command Editor, enter and execute:

    connect to musicdb

    Terminal db2 get connection state

  • 8/21/2019 labora normal

    38/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-6 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 15. Every database has its own Database Configuration file that contains informationabout the database and tuning parameters. Look at the Database Configuration file

    for your MUSICDBdatabase.

    __ 16. Find the default values for two specific configuration parameters for your database,

    LOCKLIST and MAXLOCKS. Since there are a large number of configuration

    parameters, we can use grepto find the specific ones we want when using a localconnection the option -imeans case insensitive.

    _______________________________________________________________

    __ 17. Values of some of the parameters can be changed. Update the following parametersand specify the values shown.

    Change maxlocks to 20

    Change num_freqvalues to 12

    GUI

    From the DB2 Command Editor, delete the last statement you entered in

    the Commandsbox.

    Choose Selectedfrom the menu bar and then select History.

    Select get connection statein the Commandsbox, and click the Pastebutton.

    Execute the command:

    get connection state

    Terminal db2 get db cfg for musicdb | more

    GUI

    __ Switch to your DB2 Control Centersession.

    __ Select MUSICDB in the left pane under the Databasesfolder.

    __ Right-click and select Configure Parametersfrom the pop-up menu.

    __ Scroll through the list to see the parameters that can be changed.

    __ Click the Cancelbutton when finished.

    Terminal db2 get db cfg for musicdb | grep -i lock

    GUISwitch to the DB2 Control Centersession looking for these two specific

    configuration parameters and their values: LOCKLISTand MAXLOCKS.

    Terminaldb2 update db cfg for musicdb using maxlocks 20 num_freqvalues

    12

  • 8/21/2019 labora normal

    39/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-7

    4.0

    empty

    __ 18. When do these database configuration file changes take effect?

    __________________________________________________________________ 19. Check to see if the Current and Delayed Valuesare the same for maxlocks and

    num_freqvalues.

    __ 20. Some default table spaces were created during creation of the database. List thetable space information.

    __ 21. What are the table space names and what ID number is associated with the table

    space?

    ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    Note

    dbsize returns the size of the database (in bytes) and is calculated as follows:

    dbsize = sum (used_pages * page_size) for each table space (SMS and DMS).

    dbcapacity returns the database capacity (in bytes) (not available on partitioned

    database systems) and is calculated as follows: dbcapacity = SUM (DMSusable_pages * page size) + SUM (SMS container size + file system free size per

    GUIFrom the Command Editor, enter and execute:

    update db cfg for musicdb using maxlocks 20 num_freqvalues 12

    Terminaldb2 get db cfg for musicdb show detail | more

    Scroll through the output.

    GUI

    Issue the following command from Command Editor:

    get db cfg for musicdb show detail

    Scroll through the output. (You might need to scroll to the right to see bothCurrent and Delayed Values.)

    Terminal db2 list tablespaces | more

    GUI

    From the Command Editor:

    list tablespaces

  • 8/21/2019 labora normal

    40/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-8 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    container). If multiple SMS containers are defined on the same file system, the filesystem free size is included only once in the calculation of capacity.

    __ 24. Table space container information can be displayed with the list tablespacecontainerscommand. Use the Help facility to show the DB2 command syntax.

    .

    __ 25. Show the container information for table space ID 0. What type of container is thisand where is it located?

    ________________________________________________________________

    __ 26. List the names of the system catalog tables. What are these tables?

    ________________________________________________________________

    __ 27. Get more detailed information for the table spaces and indicate which table spaces

    are set to automatic size increase.

    Terminal db2 "? list tablespace containers"

    GUI ? list tablespace containers

    Terminal db2 list tablespace containers for 0

    GUI list tablespace containers for 0

    Terminal

    db2 list tables for system | more

    -or-db2 "select substr(tabname,1,18) as tabname,

    substr(definer,1,10) as definer,

    case type when 'T' then 'T Table'

    else 'Error' end as type

    from syscat.tables where type = 'T' and definer = 'SYSIBM' " |

    more

    GUI

    list tables for system

    -or-

    select tabname, definer,

    case type when 'T' then 'T Table' else 'Error' end as type

    from syscat.tables where type = 'T' and definer = 'SYSIBM'

  • 8/21/2019 labora normal

    41/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-9

    4.0

    empty ________________________________________________________________

    __ 28. Verify which default path containers are associated with the temporary table space

    and the default user table space.

    ________________________________________________________________

    __ 29. Retrieve detailed container information from the Catalog tables. What is thecontainer types for each container (you will use a script file)?

    ________________________________________________________________

    Terminal db2 get snapshot for tablespaces on musicdb | more

    GUI get snapshot for tablespaces on musicdb

    Terminaldb2 list tablespaces

    db2 list tablespace containers for 1

    db2 list tablespace containers for 2

    GUI

    On the Command Editor, Commandstab, first make sure the Toolisconfigured for multiple commands.

    __ Select Tools Settingsicon on the tool bar.

    __ Make sure the checkbox next to Use statement termination character

    is checked, and that the statement termination character specified is asemicolon.

    __ Close Tools Settingwindow.

    list tablespaces;

    list tablespace containers for 1;

    list tablespace containers for 2;

    Terminal

    Verify how to set the script options by examining the output from thefollowing command:

    db2 list command options | more

    Execute the script to retrieve the information:

    cd $HOME/lab4

    more select_containers.sql

    db2 -tvf select_containers.sql

  • 8/21/2019 labora normal

    42/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-10 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    GUI

    Using the Command Editor, execute the following statement:

    select tbsp_name, tbsp_id, container_name, container_id,

    container_type

    from sysibmadm.snapcontainer order by tbsp_id

  • 8/21/2019 labora normal

    43/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-11

    4.0

    empty Section 2: Creating Table Spaces

    Your MUSICDBdatabase requires additional table spaces. You will create one of thesetable spaces. You will then create the remaining six table spaces via a script command file.

    __ 1. Create your first table space. It should have the following characteristics:

    Table space name is TSP01

    Table Space Type is Regular

    Buffer Pool should be IBMDEFAULTBP (which is also the default)

    Table Space management is DMS (also called high performance)

    Container size should be 104 pages with 4 KB pages

    Container should be a File

    Container path and filename should be /dbauto/path1/inst20/dms/tsp01

    Table space extent size and prefetch size should be 4

    Terminal

    Change to the lab4directory:

    cd $HOME/lab4

    This work has been done for you. View thecreate_tablespace_tsp01.ddl file, then execute it.

    more create_tablespace_tsp01.ddl

    db2 -tvf create_tablespace_tsp01.ddl

  • 8/21/2019 labora normal

    44/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-12 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 2. Verify your new table space (TSP01) by listing table spaces.

    Verify that the Allocated size is 104 pages. Verify that the extent size and prefetch

    size are both 4. If not, drop the table space and create it again.

    GUI part 1

    From the Control Centerright-click Table Spacesand choose Create.

    __ Use the Create Table Space Wizardto specify the characteristics as

    shown in the instructions above.

    __ On the Namepage, indicate name of tsp01. Click the I want to managemy storage manuallyradio button.

    __ On the Typepage, indicate Regular.

    __ On the Space Managementpage, indicate Database-managed space(high performance).

    __ On the Containerspage, click Add; specify 4 KBpages, then a size of

    104. Indicate the file name as given in the instructions. (Select thedirectory name of /dbauto/path1/inst20 , but you will need to type

    in dms/tsp01as the Container name since the dmsdirectory does notyet exist.)

    __ Click OK.

    __ Ensure that on the Read/Writewindow, you indicate Extentsize as 4

    pages (four 4KB pages).

    __ Ensure that on the Recoverywindow, you uncheck the box: Enable

    dropped table recovery.

    GUI part 2

    After specifying all the characteristics, check your settings by clicking ShowSQL on the Summarypage before creating the table space. Your SQL

    should look like this:

    CREATE REGULAR TABLESPACE TSP01 PAGESIZE 4 K MANAGED BY

    DATABASE USING ( FILE '/dbauto/path1/inst20/dms/tsp01' 104 )EXTENTSIZE 4 OVERHEAD 10.5 PREFETCHSIZE 4 TRANSFERRATE 0.14

    BUFFERPOOL IBMDEFAULTBP DROPPED TABLE RECOVERY OFF;

    Click Finishto create the table space.

    Terminaldb2 connect to musicdb

    db2 list tablespaces show detail | more

    GUIFrom the Command Editor:

    list tablespaces show detail;

  • 8/21/2019 labora normal

    45/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-13

    4.0

    empty __ 3. On your Linux Database Server, a script file named create_tablespaces.ddl contains SQL statements to create your additional table spaces.

    From your terminal session:

    more create_tablespaces.ddl

    Notice that the file creates six table spaces named tsp02, tsp03, tsp04, tsp05, tsp06,

    and sms01.__ 4. Execute the script file, which you viewed in the previous step, to create your

    remaining table spaces.

    Make sure you have the following options set before executing the script:

    Auto commit should be enabled.

    Execution should be stopped if there is an error.

    Commands and statements should be echoed back to the screen.

    A semicolon should be used as the termination character.

    ________________________________________________________________

    ________________________________________________________________

    __ 5. Confirm that the additional six table spaces are present. Are your new table space

    names listed?

    ________________________________________________________________

    __ 6. From your Terminal session, change directories to /dbauto/path1/inst20/dms and do a list of the files.

    cd /dbauto/path1/inst20/dms

    ls

    __ 7. What are these files?

    TerminalExecute the script with the following script options:

    db2 -tvsf create_tablespaces.ddl

    Terminal db2 list tablespaces | more

    GUI

    From the DB2 Control Center, refresh table spaces.

    __ Right-click and select Table Spaces.

    __ Select Refreshfrom the pop-up menu.

    __ Check the Objectpane for your new table spaces.

  • 8/21/2019 labora normal

    46/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-14 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    ________________________________________________________________

    __ 8. Where are the rest of the DMS table space files?

    db2 list tablespace containers for 7

    db2 list tablespace containers for 8db2 list tablespace containers for 7

    Tablespace Containers for Tablespace 7

    Container ID = 0Name = /dbauto/path1/inst20/NODE0000/MUSICDB/T0000007/C0000000.LRG

    Type = File

    Container ID = 1

    Name = /dbauto/path2/inst20/NODE0000/MUSICDB/T0000007/C0000001.LRG

    Type = File

    Container ID = 2

    Name = /dbauto/path2/inst20/NODE0000/MUSICDB/T0000007/C0000002.LRG

    Type = File

    db2 list tablespace containers for 8

    Tablespace Containers for Tablespace 8

    Container ID = 0

    Name = /dbauto/path1/inst20/NODE0000/MUSICDB/T0000008/C0000000.USR

    Type = File

    Container ID = 1

    Name = /dbauto/path2/inst20/NODE0000/MUSICDB/T0000008/C0000001.USR

    Type = File

    Container ID = 2

    Name = /dbauto/path2/inst20/NODE0000/MUSICDB/T0000008/C0000002.USRType = File

    __ 9. Display detailed information about the table spaces. You must be connected to the

    database first.

    __ 10. What ID numbers are associated with each of the table spaces? How many usable

    pages are there in the DMS table spaces? List a few differences between SMS andDMS table spaces.

    Terminaldb2 connect to musicdb

    db2 list tablespaces show detail | more

    GUI

    From the Command Editor:

    connect to musicdb;

    list tablespaces show detail;

  • 8/21/2019 labora normal

    47/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-15

    4.0

    empty ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    __ 11. Show the container information for table space ID 4. What type of container is this

    and where it is located?

    _______________________________________________________________

    _______________________________________________________________

    __ 12. Show the container information for your SMS table space ID 10. What type of

    containers are being used and where are they?

    ________________________________________________________________

    ________________________________________________________________

    __ 13. From your Terminal session, change directory to the smsdirectory and list thedirectory.

    cd /dbauto/path1/inst20/sms/sms01

    ls -l

    __ 14. Table data is stored in .DAT files, indexes in .INX files, and LOB info in .LB and .LBA

    files. And there is an SQLTAG.NAM file that holds overhead information about thiscontainer, and the tables that are found there.

    Currently there are no tables in this table space.

    __ 15. From your Terminal session, create a table and an index on that table in this table

    space. And then list the contents of the directory again. What do you see now? Arethe new files named after the table name?

    db2 "create table t (i int) in sms01"

    db2 "create index ii on t(i)"

    ls -l

    ________________________________________________________________

    Terminal db2 list tablespace containers for 4 show detail

    GUI list tablespace containers for 4 show detail

    Terminal db2 list tablespace containers for 10 show detail

    GUI list tablespace containers for 10 show detail

  • 8/21/2019 labora normal

    48/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-16 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 16. Drop table tas it is no longer needed:

    db2 drop table t

    __ 17. Perform another list of the directory and compare the file sizes from the previous list:

    ls -l

    __ 18. Table space information is accessible through a view with the name

    SYSCAT.TABLESPACES. The fields that contain table space information are:

    TBSPACE Name of primary table space for this table

    DEFINER Authid of table space creator

    TBSPACEID Internal table space identifier

    TBSPACETYPE Type of table space. D for DMS or S for SMS.

    DATATYPE Type of data that can be stored in the table space. L for long dataonly, A for all types of permanent data, or T for temporary tables only.

    Issue a select from SYSCAT.TABLESPACES to answer the following questions.

    __ 19. What is the authorization ID of table space definer for the default table spaces?

    ________________________________________________________________

    __ 20. Which of the various table spaces allows long data types?

    ________________________________________________________________

    __ 21. Which table space only allows temporary table data?________________________________________________________________

    __ 22. Table space information for individual tables can be accessed through theSYSCAT.TABLES view. The fields that contain table space information are:

    TBSPACEID Table space ID of primary table space for this table

    TBSPACE Name of primary table space for this table

    INDEX_TBSPACE Table space containing the indexes for this table

    Terminal

    cd $HOME/lab4

    more select_tablespaces.sql

    db2 -tvf select_tablespaces.sql

    GUI

    select tbspace, definer, tbspaceid, tbspacetype, datatype

    from syscat.tablespaces

    If the results do not show up on the Query Resultstab, either change your

    select statement to the one shown in the Local instructions so you can see

    the fields without excessive scrolling, or exit the Command Editor, reopen it,and reissue your statement.

  • 8/21/2019 labora normal

    49/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-17

    4.0

    empty LONG_TBSPACE Table space containing LONG or LOB data for this table

    List the table space information for the table SYSIBM.SYSTABLES.

    __ 23. Is the SYSIBM.SYSTABLES table divided between different table spaces?

    ________________________________________________________________

    ________________________________________________________________

    ________________________________________________________________

    __ 24. In DB2 Version 9.7, there is a new way to view table space information. Use theMON_GET_TABLSPACE function to view metrics for the table spaces.

    db2 "SELECT varchar(tbsp_name, 30) as tbsp_name, member, tbsp_type,

    pool_data_p_reads

    FROM TABLE(MON_GET_TABLESPACE('',-2)) AS t

    ORDER BY pool_data_p_reads DESC"

    __ a. This SQL has been done for you. View the select_mon_get_tbsp.sqlfile then

    execute it:

    more select_mon_get_tbsp.sqldb2 -tvf select_mon_get_tbsp.sql

    Example output:

    TBSP_NAME MEMBER TBSP_TYPE POOL_DATA_P_READS

    ------------------------------ ------ ---------- --------------------

    SYSCATSPACE 0 DMS 130

    USERSPACE1 0 DMS 34

    TSP03 0 DMS 10

    SYSTOOLSPACE 0 DMS 6

    TSP01 0 DMS 6TSP06 0 DMS 6

    TSP02 0 DMS 4

    TSP04 0 DMS 4

    TSP05 0 DMS 4

    TEMPSPACE1 0 SMS 0

    SMS01 0 SMS 0

    11 record(s) selected.

    Terminalmore select_systables.sql

    db2 -tvf select_systables.sql

    GUI select tabname, tbspaceid, tbspace, index_tbspace, long_tbspacefrom syscat.tables where tabname='SYSTABLES'

  • 8/21/2019 labora normal

    50/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-18 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 25. Now use the MON_GET_CONTAINER function to return metrics about table spacecontainers:

    db2 "SELECT varchar(container_name,70) as container_name,

    varchar(tbsp_name,20) as tbsp_name,

    pool_read_time

    FROM TABLE(MON_GET_CONTAINER('',-2)) AS t

    ORDER BY pool_read_time DESC"

    __ a. This SQL has been done for you. View the select_mon_get_cont.sqlfile thenexecute it:

    more select_mon_get_cont.sql

    db2 -tvf select_mon_get_cont.sql

    Example output:

    CONTAINER_NAME TBSP_NAME POOL_READ_TIME--------------------------------------------------------------- -------------- --------------

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000000/C0000000.CAT SYSCATSPACE 613

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000002/C0000000.LRG USERSPACE1 25

    /dbauto/path2/inst20/NODE0000/MUSICDB/T0000007/C0000001.LRG TSP04 14

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000003/C0000000.LRG SYSTOOLSPACE 8

    /dbauto/path1/inst20/dms/tsp01 TSP01 6

    /dbauto/path1/inst20/dms/tsp03 TSP03 3

    /dbauto/path1/inst20/dms/tsp06 TSP06 2

    /dbauto/path1/inst20/dms/tsp02 TSP02 1

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000008/C0000000.USR TSP05 1

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000001/C0000000.TMP TEMPSPACE1 0

    /dbauto/path2/inst20/NODE0000/MUSICDB/T0000001/C0000001.TMP TEMPSPACE1 0

    /dbauto/path2/inst20/NODE0000/MUSICDB/T0000001/C0000002.TMP TEMPSPACE1 0

    /dbauto/path1/inst20/NODE0000/MUSICDB/T0000007/C0000000.LRG TSP04 0/dbauto/path2/inst20/NODE0000/MUSICDB/T0000007/C0000002.LRG TSP04 0

    /dbauto/path2/inst20/NODE0000/MUSICDB/T0000008/C0000001.USR TSP05 0

    /dbauto/path2/inst20/NODE0000/MUSICDB/T0000008/C0000002.USR TSP05 0

    /dbauto/path1/inst20/sms/sms01 SMS01 0

    17 record(s) selected.

    __ 26. Enter connect reset to break your database connection.

    Terminal db2 connect reset

    GUI connect reset

  • 8/21/2019 labora normal

    51/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-19

    4.0

    empty Script files used for lab4

    create_tablespace_tsp01.ddlconnect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/create_tablespace_tsp01.logr on /home/inst20/lab4/create_tablespace_tsp01.out;

    create regular tablespace tsp01

    managed by database

    using (file '/dbauto/path1/inst20/dms/tsp01' 104)

    extentsize 4 autoresize yes ;

    create_tablespaces.ddlalter database musicdb add storage on '/dbauto/path2';

    connect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/create_tablespaces.log

    r on /home/inst20/lab4/create_tablespaces.out;

    create regular tablespace tsp02

    managed by database

    using (file '/dbauto/path1/inst20/dms/tsp02' 14)

    extentsize 2 autoresize yes maxsize 2 M ;

    create large tablespace tsp03

    managed by database

    using (file '/dbauto/path1/inst20/dms/tsp03' 728)

    extentsize 8 autoresize yes maxsize 10 M ;

    create tablespace tsp04

    managed by automatic storage initialsize 100 K maxsize none

    extentsize 2;

    create regular tablespace tsp05 initialsize 64 K maxsize 1 Mextentsize 2;

    create regular tablespace tsp06

    managed by database

    using (file '/dbauto/path1/inst20/dms/tsp06' 40)

    extentsize 4;

  • 8/21/2019 labora normal

    52/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-20 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    create regular tablespace sms01

    managed by system

    using ('/dbauto/path1/inst20/sms/sms01')

    extentsize 4;

    select_containers.sql

    connect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/select_containers.log

    r on /home/inst20/lab4/select_containers.out;

    select tbsp_id as TS_ID, substr(tbsp_name,1,20) as TS_name,

    container_type, substr(container_name,1,60) as container_name

    from sysibmadm.snapcontainer

    order by tbsp_id, container_id;

    select_mon_get_cont.sqlconnect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/select_mon_get_cont.log

    r on /home/inst20/lab4/select_mon_get_cont.out;

    select varchar(container_name, 70) as container_name,

    varchar(tbsp_name, 20) as tbsp_name, pool_read_time

    from table(mon_get_container('', -2)) as torder by pool_read_time desc ;

    select_mon_get_tbsp.sqlconnect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/select_mon_get_tbsp.log

    r on /home/inst20/lab4/select_mon_get_tbsp.out;

    select varchar(tbsp_name, 30) as tbsp_name, member,tbsp_type, pool_data_p_reads

    from table(mon_get_tablespace('', -2)) as t

    order by pool_data_p_reads desc ;

    select_systables.sqlconnect to musicdb user inst20 using ibm2blue;

  • 8/21/2019 labora normal

    53/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 4. Creating databases and data placement 4-21

    4.0

    empty update command options using

    l on /home/inst20/lab4/select_systables.log

    r on /home/inst20/lab4/select_systables.out;

    select substr(tabname,1,18) as tabname, tbspaceid,

    substr(tbspace,1,20) as tbspace, substr(index_tbspace,1,20) as

    index_tbspace,substr(long_tbspace,1,20) as long_tbspace

    from syscat.tables where tabname='SYSTABLES' ;

    select_tablespaces.sqlconnect to musicdb user inst20 using ibm2blue;

    update command options using

    l on /home/inst20/lab4/select_tablespaces.log

    r on /home/inst20/lab4/select_tablespaces.out;

    select substr(tbspace,1,18) as tbspace,

    substr(definer,1,10) as definer, tbspaceid, tbspacetype,

    datatype from syscat.tablespaces;

    End of exercises

  • 8/21/2019 labora normal

    54/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    4-22 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

  • 8/21/2019 labora normal

    55/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 5. Create objects 5-1

    4.0

    empty Exercise 5. Create objects

    What this exercise is about

    This exercise is an online exercise which creates objects used in a

    database.

    What you should be able to do

    At the end of the exercise, students should be able to:

    Create tables

    Create indexes

    Create views

    Create an alias Add referential integrity constraints to a table

    Add check constraints to a table

    Add triggers to a table

    Access System Catalog information about objects

    Retrieve an XML document

    IntroductionNow that the database and table spaces have been created, the

    database objects needed for your MUSICDBdatabase need to becreated. The DB2 Control Center (GUI exercises) or a DB2 statement

    will be used to create at least the first object of each type, such as thefirst table. Where there are multiple objects of the same type to be

    created, a script file will be executed to create all the remaining objectsof a certain type.

  • 8/21/2019 labora normal

    56/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    5-2 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    Exercise instructions

    Throughout the exercise, if the DB2 Message Window appears, or if you are looking at aShow SQL or Show Command window, in many cases, the exercise instructions will not

    specifically tell you to close the window. Read the message, look at the SQL or Command,and then click Close to close the window.

    If a GUI window, other than the Control Center, appears to be hung, check to be sure thatthe Control Center does not have a message window open. If there is a message windowopen in the Control Center, it might impact the usability of the other GUI tools.

    Commands are generally to be entered on the Command Editor, Commands tab. If you

    want to enter them on the Terminal session (prefaced with db2), that will generally work aswell.

    In some cases, the window might need to be scrolled to access the Action buttons on the

    window (like OK, Cancel, or Apply). If you cannot see the Action button, scroll down thewindow to see them.

    If, at any point in the exercises, when you are importing a new script into the CommandEditor, Commands tab, you are prompted on whether you want to discard your current

    script, indicate Yes.

    Section 0: Setup

    If not already done, start your Linux VMware image and log in as the inst20user.

    __ 1. If not already done, open a Terminal session.

    __ a. Right-click the empty Linux desktop and select Open Terminal.

  • 8/21/2019 labora normal

    57/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    Copyright IBM Corp. 1999, 2010 Exercise 5. Create objects 5-3

    4.0

    empty Section 1: Create Tables

    In this section, you will be creating the tables needed for your MUSICDB database.

    __ 1. Create your ARTISTS table. The table should have the following characteristics.

    Table schema of inst20

    Table Name of artists

    Regular data to go in table space tsp01

    Indexes to go in table space tsp02

    Long data to go in table space tsp03

    The column artno should be defined as a primary key

    Columns defined like the following:(artno smallint not null,

    name varchar (50),

    classification char (1) not null,

    bio clob (100K) logged compact,

    picture blob (500k) not logged compact)

    Terminal

    cd $HOME/lab5

    A script file, create_table_artists.ddl contains the DDL needed tocreate the artists table. View it, then execute it.

    more create_table_artists.ddl

    db2 -tvf create_table_artists.ddl

    GUI

    __ Select Commandstab on the Command Editorpanel.

    __ Selected-> Open(menu bar)

    __ Verify that the System nameis your local workstation.

    __ In the Directorieslist, select the $HOME/lab5directory by clicking twice.

    __ Scroll down the Files listuntil you reach a file named

    create_table_artists.ddl and select it.

    __ Note that the Pathbox gets filled in with the

    create_table_artists.ddl file name.

    __ Click OK.

  • 8/21/2019 labora normal

    58/198

    Student Exercises

    Course materials may not be reproduced in whole or in part

    without the prior written permission of IBM.

    5-4 DB2 9 DB Admin Workshop for Linux Copyright IBM Corp. 1999, 2010

    __ 2. Verify the creation of y