l01 db2 9 7 dba pot instance

22
Lab 01 – Instance Exploration IBM Software Lab 01. Instance Exploration A. DB2 Operating System Directories and Files Let us explore how installed DB2 looks on your Windows operating system: Open a Windows Command Prompt: ___1. To check where to find code is installed, type: db2set –all (Note the location of DB2INSTPROF and DB2PATH ) The following are the kinds of DB2 profile registry variables and are parsed by DB2 in this order: Environment variables - denoted by [e] Node level registry - denoted by [n] Instance level registry - denoted by [i] Global level registry - denoted by [g] Lab 01 – Instance Exploration Page 9

Upload: manuvats

Post on 12-Mar-2015

101 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

Lab 01. Instance Exploration

A. DB2 Operating System Directories and Files

Let us explore how installed DB2 looks on your Windows operating system:

Open a Windows Command Prompt:

___1. To check where to find code is installed, type:

db2set –all

(Note the location of DB2INSTPROF and DB2PATH )

The following are the kinds of DB2 profile registry variables and are parsed by DB2 in this order:

Environment variables - denoted by [e]

Node level registry - denoted by [n]

Instance level registry - denoted by [i]

Global level registry - denoted by [g]

Lab 01 – Instance Exploration Page 9

Page 2: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

DB2 install path

___2. Using the Windows Explorer, find that DB2PATH location:

Windows Explorer Program Files IBM SQLLIB

Explore this directory and the BIN directory under it to see all the DB2 binaries

Instance default metadata path

___3. Using the Windows Explorer, find the DB2INSTPROF location by using:

Windows Explorer Documents and Settings All Users Application Data IBM DB2 DB2COPY1 and explore this directory

Page 10 DB2 9.7 Administration for the Experienced Oracle DBA

Page 3: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

___4. Find the folder for instance called DB2:

Find db2systm - this is the dbm config binary file. (Please, do not try to edit this.)

Find db2diag.log - this is the diagnostic log file. (You can edit this…)

Database default metadata path

___5. Now let’s explore the database files managed by instance DB2

___6. Using the Windows Explorer, find:

My Computer C: DB2 NODE0000 SQL0002

___7. Look at directory SQL0002

This is the metadata folder for the SAMPLE database. Even though we are exploring instances in this lab, we still need to see how databases relate to instances and how each are placed on your operating system. We’ll show you later how you know which SQL subdirectory goes with which database

SQL0002 is the directory for the metadata for the SAMPLE database. This is different that the SAMPLE directory which is where the automatic storage containers are kept for the SAMPLE database.

___8. Browse the various directories and files. What do you suppose SQLOGDIR is? (Hint: it’s a default directory)

SQLOGDIR is where your redo logs are written to until you change the location

Lab 01 – Instance Exploration Page 11

Page 4: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

___9. Can you find these special binary DB2 files? Please, do not make changes!

SQLBP.1 & 2 (buffer pool info)

SQLSPCS.1 & 2 (table space info)

SQLOG* (log control files)

SQLDBCON (db configuration)

db2rhist.asc (recovery history file)

___10. SQLDBDIR, which is on the same level as SQL0002, is the location of the local database directory for all databases created under instance DB2. We will be learning about what a local database directory is later.

Page 12 DB2 9.7 Administration for the Experienced Oracle DBA

Page 5: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

B. Start and Stop a DB2 Instance___11. Open a Windows Command Prompt

___12. To see the environment variable that shows the current instance, type:

set db2instance

___13. To stop an instance, type:

db2stop force

This command works against the current instance only

Notice that a DB2 instance is always very quick to start

db2 stop dbm is an alternative using the CLP; you can try it later when we learn how to use the CLP

___14. To start an instance, type:

db2start

A DB2 instance always takes only a few seconds to start

___15. Open Services:

Review all services starting with DB2

Find “DB2 – DB2COPY1 - DB2-0” right click on it stop

What do you suppose this services’ naming convention means?

Windows service naming convention starts all DB2 services with DB2, then it uses the copy of DB2 you are using (usually DB2COPY1 unless you have more than one copy of DB2 running on your server) then "[instance name]" for all instances running. Other DB2.... names are for remaining services, descriptions are available in the service window for each.

Lab 01 – Instance Exploration Page 13

Page 6: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

___16. Start the service again by either using right click start or by using db2start at the command line

___17. You can make Windows automatically start your instance using this screen, right click and choose properties

___18. Minimize your Services window for now; don’t close it yet.

UNIX® notes on instances:

The default instance created on a UNIX system is usually called db2inst1.

To automatically start a DB2 instance upon server startup, use the db2iauto command.

Usage notes on the listening agent:

Since the DB2 instance has the “listening” agent started with it, it can be helpful for Oracle DBAs to think of starting a DB2 instance as starting the Oracle listener.

Page 14 DB2 9.7 Administration for the Experienced Oracle DBA

Page 7: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

C. CLP Introduction ___19. This section is to demonstrate a command line interface for DB2.

___20. Here are terms used throughout these Proof of Technology lab workbooks:

Windows Command Prompt

Windows Explorer

DB2 CLP Command Window

DB2 CLP Interactive

DB2 Command Editor

Windows Operating System command shell

Windows Operating System GUI

DB2 command window running in the OS shell

DB2 command window running in its own shell

DB2 command window GUI

___21. To start the DB2 CLP Command Window, from the Windows Command Prompt, type:

db2cmd

This starts the DB2 shell over the OS shell often called the “DB2 CLP Command Window This is one mode of the Command Line Processor (CLP)

___22. Close the Windows Command Prompt you opened first. We don’t need it for these next few labs.

Lab 01 – Instance Exploration Page 15

Page 8: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

___23. From the new DB2 CLP Command Window you just opened, type:

db2 get dbm cfg

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

These are the instance configuration parameters

___24. To see what is in the instance memory, hit your up arrow key, then finish typing:

db2 get dbm cfg show detail

You will get an error stating you are attached to the instance, so you cannot get detailed information from it. The “detail” will show temporary changes to the cfg settings (if any) so you need to be attached to the instance to ‘”find” this information

The “cfg” it is referencing is simply information in a binary file and saved changes are persistent.

___25. To attach to a DB2 instance, type:

db2 attach to db2

___26. Try again (hint: hit your up arrow key):

db2 get dbm cfg show detail

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

db2 get admin 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

___28. 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

Page 16 DB2 9.7 Administration for the Experienced Oracle DBA

Page 9: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

___29. To verify your instance location, type:

get instance

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

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

!db2cc

(this runs db2cc.bat in the BIN library to launch the Control Center)

Click on SAMPLE database, then “Tables” (this activates the SAMPLE database and establishes a DB2 application)

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

connect to gsdb

___32. Now, type:

list active databases

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

Notice we have two active databases. GSDB was activated when we connected through the CLP. SAMPLE was activated when we connected through the Control Center GUI.

___33. Type:

list applications

Notice that GSDB has a db2bp.exe application name (the CLP)

Notice that SAMPLE has a javaw.exe application name (the Control Center)

___34. Type:

list applications show detail

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

___35. Type:

terminate

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

___36. We are no longer in the interactive mode, but we can still run DB2 commands. Try listing the active database. Then close the Control Center and list active databases again to see what happens.

Lab 01 – Instance Exploration Page 17

Page 10: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

D. DB2 Windows Registry

___37. Start Run

___38. Open regedit [OK] Please, do not make changes here!

___39. In this window, go to HKEY_LOCAL_MACHINE\SOFTWARE\IBM\DB2\PROFILES\

DB2 is the instance

GLOBAL_PROFILE is for all DB2 instances on server

Just note for now the various registers that are kept for DB2

Minimize this Registry Editor window for now, don’t close it yet.

Page 18 DB2 9.7 Administration for the Experienced Oracle DBA

Page 11: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

E. Create a New DB2 Instance

DB2 instance creation on Windows:

1. Requires administration authority to run

2. Creates a Windows Service (with “DB2 – [instance_name – node_name]” convention)

3. Creates an Instance Directory (usually …Documents and Settings…/DB2copy1

/instance_name)

4. Creates a Registry Key (regedit, HKEY_LOCAL…)

DB2 Instance creation on UNIX:

1. Sets environment variables DB2INSTANCE and PATH

Creates /SQLLIB subdirectory in $HOME of the SYSADM (/home/[instance-name]/sqllib)

Configures communication based on servers available protocol

2. Creates files

db2profile – for main environment variable settings (bourne, bash, ksh) userprofile – for upgrade and additional environment variable settings

3. Requires user id to:

Run with root authority – this is because it needs to access the db2icrt command in the DB2 install directory /opt/IBM/db2/[version]/instance/db2icrt on most UNIX platforms /opt/ibm/db2/[version]/instance/db2icrt on Linux®

Specifies an instance name that is tied to a particular user id which has its own home file system and home directory; this user id should also have the SYSADM authority

Create a DB2 instance and then verify it in Windows:

___40. In the DB2 CLP Command Window, change directories to C:\POT_DB2\01INSTANCE

___41. Type:

db2icrt db2bkp

That’s it! The instance is created. For details on this command see file:

Instance_DB2ICRT_Command.txt

___42. Services window check:

Go to Services window (Windows icon) and click Action refresh

Find new service db2bkp (it’s name is: DB2 - DB2copy1 - db2bkp)

Start this instance if it is not already started! (Hint: right click on it)

Close the Services window now.

Lab 01 – Instance Exploration Page 19

Page 12: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

___43. Registry Editor check:

In your Registry Editor window click: View refresh

Find the new folder created for db2bkp

Close the Registry Editor window

___44. Instance directory check:

Windows Explorer View refresh

Find C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2copy1 folder

You should see your new instance folder DB2BKP

___45. Perform other checks in a DB2 CLP Command Window 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=db2bkp (change your current instance)

db2 get instance (you should be pointing to DB2BKP instance now)

___46. Now let’s explore dropping instances:

db2icrt db2jnk (check to see if it created another instance)

db2idrop db2jnk (gets rid of this instance… that’s it!)

This command only has one flag that it so force applications off before dropping, see: Instance DB2IDROP_Command.txt

Creating and dropping instances in DB2 is just that easy

Page 20 DB2 9.7 Administration for the Experienced Oracle DBA

Page 13: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

F. Catalog a New DB2 Instance

Now that we know that the instance has been created, we need to catalog it. To catalog the instance manually with a script:

___47. Go to a DB2 CLP Command Window

___48. Go to directory C:\POT_DB2\01INSTANCE

___49. Review script and execute it: Instance01.CMD

To review scripts you can use “more [scriptname]” or use the Windows Explorer, click on the file and right click on [edit]

To execute a CMD script simply type the name of the file (you can even leave off .CMD)

All scripts in this PoT will be run from a DB2 CLP Command Window from now on!

___50. From the DB2 CLP Command Window type:

db2 list node directory

___51. Notice there is now our instance DB2 “knows about” or has cataloged the DB2BKP instance.

Catalog an instance using the Control Center:

___52. First, exit from the Control Center before starting this if you have it open

___53. From a DB2 CLP Command Window, create a new instance to practice with:

db2icrt db2jnk

___54. List the instances again, type:

db2ilist

___55. Launch the Control Center, type:

db2cc

Lab 01 – Instance Exploration Page 21

Page 14: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

You can also do this with: Start All Programs IBM DB2 DB2COPY1 General Administration Tools Control Center

Expand “All Systems” tree until you find “Instances”, right click on Instances Add

___56. To fill in “Instance Name”, click on [Discover] find DB2JNK [OK]

___57. Fill in instance node name with DB2JNK

Notice [OK], [Apply] and [Show Command] buttons are now available to use

Page 22 DB2 9.7 Administration for the Experienced Oracle DBA

Page 15: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

___58. Click on [Show Command], review the DDL

Notice you can save this script – this is how we created the earlier shown catalog script

___59. Close Show Command window [Close]

___60. Click [OK] to perform the instance catalog

___61. Instance is now cataloged and should be viewable from the Control Center

You may need to right click Instances [Refresh]

___62. Drill down into the instance shown in the Control Center

Notice only instance called “DB2” has a database associated with it so far

You can use the Configuration Assistant GUI or the utilities db2cfexp AND db2cfimp to export and import all of your client’s configuration settings. This allows you to easily share all of the catalog information without doing individual catalog commands. These commands also allow you to exchange protocol, registry, dbm cfg and ODBC/CLI settings.

This tool is demonstrated in the extra exercises of this lab

Setting up a local DB2 client connection to a remote DB2 server:

On the DB2 server, set the registry variable DB2COMM to the protocol(s) used for listening. TCP/IP is commonly used. Example:

db2set DB2COMM=TCPIP

If the protocol at the DB2 server instance is TCP/IP, set the DBM config parameter SVCENAME too.

Example Unix: update dbm cfg using svcename db2c_db2inst1

servicename | portnumber matches the entry in: etc/services

Example Windows: update dbm cfg using svcename 50000

db2c_db2 | 50000/tcp matches the entry in:

%SystemRoot%\system32\drivers\etc\services

After this, recycle the instance with db2stop, then db2start

Catalog the remote instance to your local client, which updates the client NODE DIRECTORY

Catalog the remote database in that remote instance to your local client, which will result in an entry in the client SYSTEM DATABASE DIRECTORY

Helpful hint: If you used the DB2 install wizard GUI, then the default instance in either UNIX or Windows is already properly configured this way. Check out how DB2 did this for you before you create and configure a second instance by yourself.

Lab 01 – Instance Exploration Page 23

Page 16: l01 Db2 9 7 DBA Pot Instance

IBM Software DB2 9.7 Administration for the Experienced Oracle DBA

G. Extra ExercisesDB2SUPPORT usage example

___63. Review script and execute it: Instance02.CMD

Executes problem analysis support tool, db2support , in a full mode

Review Instance02_OUT.zip file (double click on it) and then launch db2support.html

DBMCFG, DBCFG and REG_VARIABLES Administration views usage example

___64. Review and execute script: Instance03.CMD which executes Instance04.SQL

DB2DIAG (diagnostic log tool) usage example

___65. Review and execute script: Instance05.CMD

Review files Instance05a_OUTPUT.TXT and Instance05b_OUTPUT.TXT

Page 24 DB2 9.7 Administration for the Experienced Oracle DBA

Page 17: l01 Db2 9 7 DBA Pot Instance

Lab 01 – Instance Exploration IBM Software

INSPECT and DB2INSPF usage example

___66. Review and execute script: Instance06.CMD

Review files Instance06_OUTPUT.TXT

DB2PD (Problem Determination) usage example

___67. Review and execute script: Instance07.CMD

Review files Instance07_OUTPUT.TXT

DB2GCF (Generic Control Facility) usage example

___68. Review and execute script: Instance08.CMD

Review files Instance08_OUTPUT.TXT

DB2CFEXP (Connectivity Configuration Export Tool) usage example

___69. Review and execute script: Instance09.CMD

Review files Instance09_OUTPUT.TXT

CLP exercises

___70. How do you change your CLP prompt to: “Your next wish master? “

db2set db2_clpprompt=”Your wish master?”

___71. Execute these commands from the CLP interactive mode:

connect to sample

select current date from sysibm.dummy

___72. When you get an error code, check it out by using the following:

DB2 ? SQL0204N

___73. Fix this command by executing this:

select current date from sysibm.sysdummy1

What is this similar to in Oracle? (We’ll see the answer to this in the next lab)

*** End of Instance Exploration Lab ***

Lab 01 – Instance Exploration Page 25