0% found this document useful (0 votes)
68 views8 pages

DB2 Enablement Workshop: Lab 1 - Working With Instances and Databases

This lab helps solidify concepts of DB2 instances and databases by having students work with the command line processor to get started with instances, create and work with databases, and be introduced to DB2's graphical tools; it involves tasks like starting an instance, creating and connecting to databases, running tools to view configurations and tune parameters, and exploring DB2 objects.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views8 pages

DB2 Enablement Workshop: Lab 1 - Working With Instances and Databases

This lab helps solidify concepts of DB2 instances and databases by having students work with the command line processor to get started with instances, create and work with databases, and be introduced to DB2's graphical tools; it involves tasks like starting an instance, creating and connecting to databases, running tools to view configurations and tune parameters, and exploring DB2 objects.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

DB2 Enablement Workshop

Lab 1 – Working with Instances and Databases

Expected duration: 45 minutes

This lab will help you solidify concepts of instances and databases. It is to be completed
following the presentation “DB2 Instances and Databases”.

Prerequisites:
• DB2 Version 8.1.2 Server has been installed (DB2 Express preferred)

Part 1: Getting started with the Command Line Processor (CLP)

1. Launch the DB2 Command Window.

Windows Linux
Log into the operating system as user db2admin Login to the OS as user db2inst1

Start Menu > Programs > IBM DB2 > Open a command line shell
Command Line Tools > Command Window

The DB2 CLP has two modes of use. You can:


o Prefix all your commands with db2, or
o Use the CLP interactive mode by typing db2.

2. View the database manager (instance) configuration file from the operating
system prompt:

db2 get dbm cfg

3. Try the command again, but within DB2’s interactive mode:

Type: db2 (A db2 prompt should appear)

db2 => get dbm cfg

EWLab1_Instances_Databases.doc Page 1 of 1
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

4. Try an operating system command to list files in the current directory

Windows Linux

db2 => ! dir db2 => ! ls

Key Lesson: You can execute operating system commands within the CLP by
prefixing the command with an exclamation mark.

5. What happens when you type the following?

Note: DB2 v8.1 + FixPak 2 (DB2 8.1.2) or DB2 Express Required

db2 => History


db2 => H
db2 => Edit 2
db2 => E 2

Tip: On windows, you can also use the up and down arrow keys.

6. Quit the DB2 CLP interactive mode.

db2 => quit

Part 2: Working with databases

1. When DB2 is installed, no database exists. Create the SAMPLE database


provided by DB2. db2sampl is a program that creates a database and populates
it with data.

In the DB2 command window, type: db2sampl

EWLab1_Instances_Databases.doc Page 2 of 2
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

2. Verify that a database now exists. Enter the CLP interactive mode again and
show the contents of the database directory:

db2 => list db directory

Fill in the following information from the database directory:

Database alias ______________


Directory entry type ______________

Note: Indirect means “local” database

3. DB2 does not have database users. Instead, DB2 uses userIDs and passwords
defined at the operating system (or network authentication facilities) to
authenticate users. Connect to the SAMPLE database using the userID that you
have currently used to log into the operating system.

db2 => connect to sample

Key Lesson: When you do not supply a user id and password, DB2 will try to
authenticate you using your current userID and password.

4. See all connections that currently exist for the current instance

db2 => list applications

Fill in the following information:


Application name: ________________________
Application handle: ________________________

EWLab1_Instances_Databases.doc Page 3 of 3
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

Database name: ________________________

Note: db2bp stands for DB2 background process. CLP connections always appear as
db2bp (UNIX) or db2bp.exe (windows)

5. View data in from the EMPLOYEE table

db2 => select * from employee

6. Disconnect from the database:

db2 => connect reset


or
db2 => disconnect sample

7. Connect to the SAMPLE database using a specific userID and password.

Windows:
db2 => connect to sample user db2admin using ibmdb2

Linux:
db2 => connect to sample user db2inst1 using ibmdb2

Key Lesson: to connect using a specific user id, the syntax is:
connect to <dbname> user <userid> using <password>

8. View the tables that currently exist in the SAMPLE database

db2 => list tables


or
db2 => list tables for all

9. From the output of list tables, you should see that a table called EMPLOYEE
exists. Find out the structure of EMPLOYEE

db2 => describe table employee

What is the maximum length of JOB column? _______________


What is the data type for the Salary Column? _______________

Part 3: Working with Instances

EWLab1_Instances_Databases.doc Page 4 of 4
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

1. Attempt to stop the instance. You should get an error because your database
connection still exists.

db2 => db2stop

What is the SQLCODE associated with the error message? _______________

Find out more information about the error:

db2 => ? SQL1025N

Read the help message carefully. The User Response: message is quite helpful.

Key Lesson: You can find more information about any error or warning by using a
question mark (?) to prefix an SQLCODE

2. To stop the instance, we have to kick off the current connections. In this step,
forcibly disconnect all applications.

db2 => force applications all (kick off connections)


db2 => db2stop (stop the instance)

Note: you can also force applications by application handle using:


force application (handle#)
example: force application (5)

3. By using FORCE APPLICATION, you have terminated your own connection.


Attempt to SELECT from the employee table. You should get the error code
SQL1224N.

db2 => select * from employee

try the command again.

db2 => select * from employee

What error do you get this time? How does it differ?

_______________________________________________________________

4. Start the db2 instance again so that we can continue working with the db2
instance

db2 => db2start

EWLab1_Instances_Databases.doc Page 5 of 5
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

Part 4: Introduction to the DB2 GUI Tools

To encourage self exploration of the tools, only the task to be performed is asked with
limited step-by-step guidance.

1. Launch the DB2 Control Center and locate the SAMPLE database created in Part 2
above. Be sure to explore the objects in the database.

2. View all connections. If any exist, force them off the instance.
Hint: Database connectivity is provided by the instance

3. Create a 2nd database called MYDB2.

Hint: While lots of options are available, the only thing you really need to
provide is the name of the new database to be created.

Once database creation is complete, you should be promoted to run the


Configuration Advisor to automatically tune DB2. Answer YES to this question.

4. In the configuration advisor, read the wizard dialogs carefully to understand what is
happening.

Answer the questions as follows, clicking NEXT to proceed to the next step:
• Step 1: (No action required)
• Step 2: 10%
• Step 3: Mixed
• Step 4: Fewer than 10 (short transactions), 5 transactions per minute
• Step 5: Optimize for BOTH
• Step 6: No, database is not populated with data

EWLab1_Instances_Databases.doc Page 6 of 6
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

• Step 7: 5 local connections, 5 remote connections


• Step 8: Cursor Stability
• Step 9: Run now without saving task history
In step 10, how to you tell which parameters have new recommended values?

____________________________________________________________

• Step 10: Click finish to apply the changes

Key Lesson: DB2 databases, after initial creation, are not well tuned. Therefore, a
good starting point for performance tuning is to run the configuration advisor. As you
continue to work with the database, you may find that some values still need to be
increased. Change parameters only as needed (tuning by exception).

5. View the database manager/instance configuration file (DBM CFG)

• Increase the DB2 diagnostics level (DIAGLEVEL) from 3 (all errors and
warnings) to 4 (all errors, warnings, and informational messages). Be sure to
check “Update when available”.
o Double click the value (it should be the default value 3)
o Click the lookup box (i.e. [. . .])
o Five value choices are displayed, there are radio buttons with descriptions
corresponding top-to-bottom with the values 0 for “No diagnostic data
captured” through 4 “All errors, warnings, and informational messages”.

• Is this parameter dynamically changed? How can you tell?


Hint: View the configuration file again from Control Center

6. Stop the DB2 instance, and be sure to select “Disconnect all applications”.

7. Start the DB2 instance

8. View the database configuration file (DB CFG) for database MYDB2

• Change the amount of memory used to manage locks (LOCKLIST) to 500. Be


sure to check “Update when available”

9. Do NOT drop the MYDB2 database. It will be used in the next lab.

Be sure to compare your answers to the solutions.

EWLab1_Instances_Databases.doc Page 7 of 7
DB2 Enablement Workshop
Lab 1 – Working with Instances and Databases

LAB 1 - Solutions

Part 2:

2.
Database alias SAMPLE
Directory entry type Indirect

4.
Application name: db2bp.exe
Application handle: 2 (your answer may vary)
Database name: SAMPLE

9.
What is the maximum length of JOB column? 8 characters
What is the data type for the Salary Column? DECIMAL(9,2)

Part 3:

1.
What is the SQLCODE associated with the error message? SQL1025N

3.
What error do you get this time, and how does it differ? SQL1024N
This time, we get a different error: database connection does not exist.

Part 4:

4.
In step 10, how do you tell which parameters have new recommended values?
New recommended values are highlighted with bold font.

5.
Was this parameter (DIAGLEVEL) dynamically changeable?
Yes. The parameter was dynamic because the instance did not require re-start
for it to take effect. However, if Update When Available is not selected, the
parameter change will be dynamically changed.

EWLab1_Instances_Databases.doc Page 8 of 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy