Sei sulla pagina 1di 20

Lab 01.

Instance Exploration

A. DB2 Operating System Directories and Files

• To list the path where Db2 database products are installed on your system and list the Db2 database
product level.
The command lists the following information for each Db2 database product installed on your system:
o Installation path
o Level
o Fix pack
o Special Install Number. This column is used by IBM Db2 Support.
o Installation date. This column shows when the Db2 database product was last modified.
o Installer UID. This column shows the UID with which the Db2 database product was installed.

su – db2inst1
db2ls

• To list information about Db2 database products or features in a particular installation path
the q parameter must be specified:

db2ls -q -p -b /opt/ibm/db2/V10.5
where:
o q specifies that you are querying a product or feature. This parameter is mandatory.
o p specifies that the listing displays products rather than listing the features.
o b specifies the installation directory of the product or feature. This parameter is mandatory if
you are not running the command from the installation directory.

B. Setting registry and environment variables

• To set a registry variable:

Issue the db2set command with the relevant parameters.

The following table shows some of the ways that you can set registry variables with
the db2set command. See the db2set command reference topic for more information about the
parameters and usage of this command.

Display all defined values for the current instance:

db2set -all
C. DB2 Operating System Directories and Files

• Using the command find that DB2PATH location:

cd /home/db2inst1/db2inst1/NODE0000
ls

Location of DB2 objects after a default root installation


• Directory structure - default local database directory information for the DB2 instance db2inst1

cd /home/db2inst1/db2inst1/NODE0000/SQL00001
ls
1. Local database directories.
2. Database configuration file

• Directory structure - directory information for the DB2 instance db2inst1

cd /home/db2inst1/sqllib
ls
1. The db2diag log files in this directory logs DB2 error messages.
2. System database directory
3. The db2nodes.cfg file is used in a partitioned database environment.
4. Database manager configuration file
5. The dasusr1 directory contains the DB2 administration server (DAS) configuration files and
the symbolic links to DB2 core files.

D. Start and Stop a DB2 Instance

• Start Instance

To start an instance, type:

db2stop

• This command works against the current instance only

• Start Instance

To start an instance, type:

db2start

• This command works against the current instance only


• Notice that a DB2 instance is always very quick to start

E. CLP Introduction

• From the command, type:

db2 get dbm cfg

• Notice the use of “dbm” (data base manager = instance)


• These are the instance configuration parameters

• To see the DB2 Administration Server (DAS) settings, type:

db2 get dbm cfg

• This is a special process that helps administrate communication between instances and
databases, locally and remotely which has its own configuration settings
• For UNIX systems, a special DAS user needs to be created, normally called dasusr1

• Try the DB2 CLP in the “interactive mode”, type:

db2

• This is usually called the “DB2 Command Line Processor” or CLP, however, it really is just
another mode of the DB2 CLP
• To verify your instance location, type:

get instance

• Notice this time we did not need to preface the command with “db2”

• Run run a Windows command or launch a .bat file, preface it with a !, type:

!ls

• To understand connections and applications, in the DB2 CLP interactive window type:

connect to sample

• Now, type:

list active databases

• Active databases have at least one connection to them by at least one application

• Type:

list applications

• Type:

list applications show detail

• This demonstrates there are other applications to the database started on our behalf when
the database was activated
• Type:

terminate

• This command does the following: resets the connection to SAMPLE, refreshes the
directory cache, stops the background process and leaves the CLP interactive session

F. Create a New DB2 Instance

• Type:

su -
cd /opt/ibm/db2/V10.5/instance
./db2icrt -u db2fenc1 lab1

• Instance directory check:

su – lab1
cd /home/lab1
ls

• Perform other checks in a command line to see you new instance, type:

db2set –l (shows available instance profiles)


db2ilist (shows same thing, but with some options)
db2 get instance (what is your default instance?)
set db2instance=db2inst1 (change your current instance)
db2 get instance (you should be pointing to lab1 instance now)
• Now let’s explore dropping instances:

su -
cd /opt/ibm/db2/V10.5/instance
./db2idrop lab1
Lab 02. Database Creation and Exploration

A. General DB2 Database Commands

• In this command line type:

su - db2inst1
db2 get instance

• To enter the DB2 CLP interactive mode type:

db2

• To see the database configuration parameters, type:

get db cfg for sample

• Connect to the SAMPLE database:

connect to sample

• To explore further, type these and hit [Enter] after each line:

get db cfg
get connection state
list tables

• Continue exploring your database, type the following using [Enter] after each line:

describe table department


describe indexes for table department
select * from employee
describe output select * from employee
list tablespaces show detail
values user
values current date
runstats on table employee

B. The DB2 System and Local Database Directories

• In order to learn about DB2 database directories, use commands from the DB2 CLP
Command Window:

db2 list database directory


• This is a system database directory, which means a directory of all databases both
remote and local that are cataloged for the current instance.

• Refresh the directory cache (and terminate the background process as well):

db2 terminate

C. Creating a Database

• To create a database in the instance DB2, try these commands:

db2 create database sample2

• This will take approximately 90 seconds…while this command is executing, see the
explanation in the box below for what it is doing

• Run this command next:

db2 list db directory


D. Altering a Table

• Change a column type in a base table. There are views and functions that are directly or
indirectly dependent on the base table.
db2
connect to sample
describe table DB2INST1.SALES
ALTER TABLE DB2INST1.SALES ALTER COLUMN SALES_PERSON SET DATA TYPE VARCHAR(20)
describe table DB2INST1.SALES

Extra Lab: IBM Data Studio

A. Launching IBM Data Studio

• Open the IBM Data Studio by clicking on this icon on your desktop or in your quick launch:

• Expand the view Administration Explorer a little more by clicking on its edge and dragging it
over.
• Right click on the connection property  Connect

• You are now in a Properties for SAMPLE screen. Fill in the following (case sensitive!)
• User name: db2inst1
• Password: password
• Save password: [check]

• Try [Test Connection]. You should get: Ping succeeded!


B. Instance management

• Maximize your Data Studio screen in order to best take advantage of the entire Data
perspective.
• Expand SAMPLE database and right click on Instance. Notice the functionality that is
available to you for the instance that manages SAMPLE. We won’t be using any of these yet
so don’t choose any of them.
(Configure means changing the DBM cfg parameters; we will explore this in a later lab)

C. Database management

• Right click on the SAMPLE database to see what database management activities you
can perform with the GUI.
• Choose Configure. This will allow you to change database (DB) configuration
parameters.
D. Editing and Running SQL

• Click Icon New SQL Script

• The Editor view will open with a blank SQL editor session, and write SQL Statement:

select * from sales fetch first 5 rows only;

• Highlight the first SQL statement and hit [F5] (You can also right click on the highlighted
SQL statement and then choose: Run SQL

• The bottom right pane of your Data perspective is the results view. You may have to
expand it
a bit to see the results better.
• Right click in the Editor view and choose: Format SQL (or [Ctrl][Shift][F]). Notice
that your SQL is nicely formatted for better readability.

E. Exploring Tables

• Expand the top of your Administration Explorer to see more of it


• Expand the objects in this view by clicking on the > signs by:
• 1) SAMPLE database
• 2) Tables.
F. Editing and viewing table data

• Find table ACT. Right click on it then  Data  Browse Data

G. Generating DDL

• Select all tables in schema: Sales (hint: hold [Shift]).


• Right click then choose: Generate DDL
• Click Next

• Preview DDL
H. Table maintenance runstats, reorg

• Right click on any table (we show CL_SCHED) and choose: Manage -> Run Statistics.
Review the SQL
• Results to see how it did the runstats.

Potrebbero piacerti anche