Database Access Db2
Database Access Db2
1
Database access using DB2
In this training module, you learn about starting DB2, viewing tables for DB2 schemas,
and performing DB2 maintenance.
database_access_db2.ppt
Page 1 of 16
Starting DB2
Verify that the DB2 database created for IBM Tivoli Workload Scheduler is
\\Switch to the db2 instance owners user and source the db2 environment
# su - db2inst1
$ . sqllib/db2profile
\\ List the databases that exist on this db2 instance "TWS" is the default db name for TWS
V8.3
$ db2 list db directory
To start the DB2 environment, make sure the DB2 environment source is set correctly.
Log in as your DB2 instance ID. Run a DB2 profile from the DB2 home SQL live directory.
If you do not know the name of your Tivoli Workload Scheduler database, run the
command db2 list db directory.
database_access_db2.ppt
Page 2 of 16
Database alias
= TWS
Database name
= TWS
Comment
= TWS Database
Database 2 entry:
Database alias
= TWS_DB
Database name
= TWS
Node name
= LBNODE
Comment
=
You see an output similar to the one shown, which includes your database alias names
and the database names. It also has the release information, any particular comments or
descriptions about the DB2 environment, and additional DB2 information.
database_access_db2.ppt
Page 3 of 16
Database server
= DB2/AIX64 9.5.0
EVT
LOG
MDL
NULLID
SQLJ
SYSCAT
SYSFUN
SYSIBM
SYSIBMADM
SYSIBMINTERNAL
SYSIBMTS
SYSPROC
SYSSTAT
SYSTOOLS
After you know the name of your Tivoli Workload Scheduler database, connect to it. Use
db2 connect to and the database name. Select db2 select schema name from. Then,
use syscat.schemata to generate a list of the db2 schema names used by Tivoli
Workload Scheduler.
database_access_db2.ppt
Page 4 of 16
DB2 schema
$ db2 list tables for schema dwb
Table/View
Schema
-------------------------------
--------------- -----
ALL_ALLOCATIONS
DWB
2010-04-09-12.48.50.771858
ALR_ALLOCATION_RESOURCES
DWB
2010-04-09-12.48.51.099697
ARE_ABSTRACT_RESOURCES
DWB
2010-04-09-12.48.53.613348
CSR_COMPUTER_SYSTEM_RESOURCES
DWB
2010-04-09-12.48.51.834397
EPR_ENDPOINT_REFS
DWB
2010-04-09-12.48.46.145017
FSR_FILE_SYSTEM_RESOURCES
DWB
2010-04-09-12.48.52.064104
JOA_JOB_ARCHIVES
DWB
2010-04-09-12.48.47.508713
JOB_BROKER_JOBS
DWB
2010-04-09-12.48.46.410286
JOD_BROKER_JOB_DEFINITIONS
DWB
2010-04-09-12.48.46.804807
JOR_JOB_RESOURCES
DWB
2010-04-09-12.48.47.147652
JRA_JOB_RESOURCE_ARCHIVES
DWB
2010-04-09-12.48.48.572429
LGR_LOGICAL_RESOURCES
DWB
2010-04-09-12.48.52.309830
MEA_METRIC_ARCHIVES
DWB
2010-04-09-12.48.48.699851
MET_METRICS
DWB
2010-04-09-12.48.47.928200
NSR_NETWORK_SYSTEM_RESOURCES
DWB
2010-04-09-12.48.52.555379
NSS_NOTIFICATION_STATES
DWB
2010-04-09-12.48.48.264270
--------------------------
OSR_OPERATING_SYSTEM_RESOURCES
DWB
2010-04-09-12.48.52.785587
PPS_PRODUCT_PROPERTIES
DWB
2010-04-09-12.48.51.326873
RAA_RESOURCE_ADVISORY_AGENTS
DWB
2010-04-09-12.48.53.335531
REL_RESOURCE_DEPS
DWB
2010-04-09-12.48.53.081108
RGS_RESOURCE_GROUPS
DWB
2010-04-09-12.48.53.876648
SRV_SERVERS
DWB
2010-04-09-12.48.54.134014
TAJ_TWS_AGENT_JOBS
DWB
2010-04-09-12.48.50.195709
This example is a list of associated tables generated for the schema Dynamic Workload
Broker. In the output is job information, calendars, dependencies, and properties. The
output also contains prompts, job streams, and information related to the scheduling of
Tivoli Workload Scheduler jobs.
database_access_db2.ppt
Page 5 of 16
Schema
MDL
AJS_ABSTRACT_JOB_STREAMS
MDL
2010-04-09-12.48.14.664073
2010-04-09-12.48.14.599346
CALENDARS_V
MDL
2010-04-09-12.48.34.145755
CAL_CALENDARS
MDL
2010-04-09-12.48.12.807603
DOM_DOMAINS
MDL
2010-04-09-12.48.13.424041
FILE_REFS_V
MDL
2010-04-09-12.48.34.591297
INTERNETWORK_DEPS_V
MDL
2010-04-09-12.48.34.477235
JDP_JOB_STREAM_INSTANCE_DEPS
JHR_JOB_HISTORY_RUNS
MDL
MDL
T
T
2010-04-09-12.48.13.886978
2010-04-09-12.48.14.536816
JOB_DEFINITION_REFS_V
MDL
2010-04-09-12.48.34.643748
JOB_DEPS_V
MDL
2010-04-09-12.48.34.413775
JOB_HISTORY_V
MDL
2010-04-09-12.48.34.308417
JOB_JOBS
MDL
2010-04-09-12.48.13.976201
JOB_STATISTICS_V
MDL
2010-04-09-12.48.34.236171
JOB_STREAM_DEPS_V
MDL
JOB_STREAM_REFS_V
MDL
2010-04-09-12.48.34.823317
JOS_JOB_STATISTICS
MDL
2010-04-09-12.48.14.460549
2010-04-09-12.48.34.531715
JSI_JOB_STREAM_INSTANCES
MDL
2010-04-09-12.48.13.783504
JST_JOB_STREAMS
MDL
2010-04-09-12.48.12.976221
NDP_NETWORK_DEPS
MDL
2010-04-09-12.48.14.160828
PROMPTS_V
MDL
2010-04-09-12.48.34.091416
PROMPT_REFS_V
MDL
2010-04-09-12.48.34.705880
PROPERTIES_V
MDL
2010-04-09-12.48.34.967084
RCY_RUN_CYCLES
MDL
2010-04-09-12.48.13.263102
RDP_RESOURCE_DEPS
MDL
2010-04-09-12.48.13.699290
RESOURCE_REFS_V
MDL
2010-04-09-12.48.34.770530
WKS_WORKSTATIONS
MDL
2010-04-09-12.48.13.543574
MDL
2010-04-09-12.48.14.310074
WUS_WINDOWS_USERS
6
A similar list can be generated for Modeling by using the command db2 list tables for
schema followed by the mdl schema name.
database_access_db2.ppt
Page 6 of 16
Schema
LOG
2010-04-09-12.48.33.792746
ACTION_RUNS_V
LOG
2010-04-09-12.48.33.733142
AUDIT_RECORDS_V
LOG
2010-04-09-12.48.33.976844
EVENT_RULE_INSTANCES_V
LOG
2010-04-09-12.48.33.863459
LLRC_LOG_RECORDS
LOG
2010-04-09-12.48.11.905529
LOG_MESSAGES_V
LOG
2010-04-09-12.48.33.917087
LRPR_RECORD_PROPERTIES
LOG
2010-04-09-12.48.12.327225
database_access_db2.ppt
Page 7 of 16
dbrunstat (1 of 2)
2.Check that the user who is going to run the procedure has the appropriate rights
On UNIX
1.Issue the command su - db2inst1, or change to the subdirectory sqllib of the home
directory of the owner of the DB2 instance (by default db2inst1)
2.Launch the command . ./db2profile
On Windows
Click Start > Programs > IBM DB2 > Command Line Tools > Command Window
If your DB2 administrator does not have a set maintenance schedule, you run dbrunstats.
DB2 reorg and dbrunstats reconfigure the tables and schemas in your database.
For both Windows and UNIX platforms, perform a dbrunstat with the database name, in
this case Tivoli Workload Scheduler. Then, select the instance ID and password. A more
detailed procedure is on the DB Tools websites.
database_access_db2.ppt
Page 8 of 16
dbrunstat (2 of 2)
4. Check that the command shell is correctly initialized by issuing the command db2, and
checking that the command is recognized
5. Issue the command quit to leave the DB2 Processor mode
6. From within the shell, change to the directory <TWA_home>/TWS/dbtools/db2/scripts
7. Run the script
On UNIX
dbrunstats.sh database [user [password]]
On Windows
dbrunstats database [user [password]]
database_access_db2.ppt
Page 9 of 16
Using this tool, the database physically reorganizes the data tables and indexes, optimizing
disk space usage and ease of data access
The process is time-consuming, requires that the database is backed up, and that Tivoli
Workload Scheduler is stopped. However, at the end, you have a database that is
completely reorganized
10
The DB reorg command is used after you have run the runstat command. DB reorg is like
running the old composer build commands in Tivoli Workload Scheduler. Run these
commands periodically. If there is a lag when running a Jnex plan or if you see issues with
slow retrieval from the database, run a DB2 runstat and reorg.
database_access_db2.ppt
Page 10 of 16
dbreorg steps
11
database_access_db2.ppt
Page 11 of 16
dbreorg (1 of 2)
5. Check that the command shell is correctly initialized by issuing the command db2, and
checking that the command is recognized
6. Issue the command quit to leave the DB2 Processor mode
7. From within the shell, change to the directory <TWA_home>/TWS/dbtools/db2/scripts
12
database_access_db2.ppt
Page 12 of 16
dbreorg (2 of 2)
Run the script
UNIX
dbreorg.sh database [user [password]]
Windows
dbreorg database [user [password]]
where:
database
The name of the database:
If you are running this from the computer where the DB2 server is installed, the installed default name is TWS.
Supply this value unless you have changed it.
If you are running this from the computer where the DB2 client is installed, the installed default name is TWS_DB.
Supply this value unless you have changed it.
user
The DB2 administration user. When omitted the ID of the user running the command will
be used.
password
The password of the DB2 administration user. If this is omitted it will be requested
interactively.
The script runs, giving you various messages denoting its progress and successful
conclusion.
Restart Tivoli Workload Scheduler.
13
database_access_db2.ppt
Page 13 of 16
Summary
In this module, you learned about starting DB2, viewing tables for DB2 schemas,
and performing DB2 maintenance
14
In this module, you learned about starting DB2, viewing tables for DB2 schemas, and
performing DB2 maintenance.
database_access_db2.ppt
Page 14 of 16
Feedback
15
You can help improve the quality of IBM Education Assistant content by providing
feedback.
database_access_db2.ppt
Page 15 of 16
IBM, the IBM logo, ibm.com, DB2, and Tivoli are trademarks or registered trademarks of International Business Machines Corp., registered in many
jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of other IBM trademarks is
available on the web at "Copyright and trademark information" at http://www.ibm.com/legal/copytrade.shtml
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
Windows, and the Windows logo are registered trademarks of Microsoft Corporation in the United States, other countries, or both.
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE
MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED
"AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBMS CURRENT
PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE. IBM SHALL NOT BE RESPONSIBLE FOR
ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, NOR SHALL HAVE THE EFFECT OF, CREATING ANY WARRANTIES OR
REPRESENTATIONS FROM IBM (OR ITS SUPPLIERS OR LICENSORS), OR ALTERING THE TERMS AND CONDITIONS OF ANY AGREEMENT
OR LICENSE GOVERNING THE USE OF IBM PRODUCTS OR SOFTWARE.
Copyright International Business Machines Corporation 2010. All rights reserved.
16
database_access_db2.ppt
Page 16 of 16