CL205v1.0 Student Exercises - 06092016
CL205v1.0 Student Exercises - 06092016
IBM Training
Licensed to Kluger for class on 10/25/2016
Preface
March 2016
NOTICES
This information was developed for products and services offered in the USA.
IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for
information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to
state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not
infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any
non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document.
The furnishing of this document does not grant you any license to these patents. You can send license inquiries, in writing, to:
IBM Director of Licensing
IBM Corporation
North Castle Drive, MD-NC119
Armonk, NY 10504-1785
United States of America
The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in
certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these
changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the
program(s) described in this publication at any time without notice.
Any references in this information to non-IBM websites are provided for convenience only and do not in any manner serve as an endorsement of
those websites. The materials at those websites are not part of the materials for this IBM product and use of those websites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Information
concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available
sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM
products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products.
This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the
examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and
addresses used by an actual business enterprise is entirely coincidental.
TRADEMARKS
IBM, the IBM logo, ibm.com, DB2 and pureScale 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 IBM trademarks is
available on the web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml.
Adobe, and the Adobe logo, are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or other
countries.
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
© Copyright International Business Machines Corporation 2016.
This document may not be reproduced in whole or in part without the prior written permission of IBM.
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Demonstration 1
Create a new DB2 instance
1:
Demonstration 1:
Create a new DB2 instance
Purpose:
This demonstration will create a new DB2 instance that will support the
database that you will create and manage in the following demonstrations.
You will use the DB2 command line processor to create the new instance,
configure some of the instance level options, and issue commands to start
and stop the instance.
Task #1 start
Description: Setting default global profile registry variables
Estimated time 1 second(s)
Task #1 end
Task #2 start
Task #3 start
Description: Configuring DB2 instances
Estimated time 300 second(s)
Task #3 end
Task #4 start
Description: Updating global profile registry
Estimated time 3 second(s)
Task #4 end
DIAGLEVEL 3 3
NOTIFYLEVEL 3 3
DIAGPATH (memory) /home/inst23/diag/
DIAGPATH (disk) /home/inst23/diag/
DIAGPATH_RESOLVED (memory) /home/inst23/diag/
DIAGPATH_RESOLVED (disk) /home/inst23/diag/
ALT_DIAGPATH (memory)
ALT_DIAGPATH (disk)
ALT_DIAGPATH_RESOLVED (memory)
ALT_DIAGPATH_RESOLVED (disk)
DIAGSIZE (MB) 20 20
DFT_MON_BUFPOOL OFF OFF
DFT_MON_LOCK OFF OFF
DFT_MON_SORT OFF OFF
DFT_MON_STMT OFF OFF
DFT_MON_TABLE OFF OFF
DFT_MON_TIMESTAMP ON ON
DFT_MON_UOW OFF OFF
HEALTH_MON OFF OFF
SYSADM_GROUP (memory) ADM01
SYSADM_GROUP (disk) ADM01
SYSCTRL_GROUP (memory)
SYSCTRL_GROUP (disk)
SYSMAINT_GROUP (memory)
SYSMAINT_GROUP (disk)
SYSMON_GROUP (memory)
SYSMON_GROUP (disk)
CLNT_PW_PLUGIN
CLNT_KRB_PLUGIN
GROUP_PLUGIN
LOCAL_GSSPLUGIN
SRV_PLUGIN_MODE UNFENCED UNFENCED
SRVCON_GSSPLUGIN_LIST
SRVCON_PW_PLUGIN
SRVCON_AUTH
AUTHENTICATION SERVER SERVER
ALTERNATE_AUTH_ENC
CATALOG_NOAUTH NO NO
TRUST_ALLCLNTS YES YES
TRUST_CLNTAUTH CLIENT CLIENT
FED_NOAUTH NO NO
DFTDBPATH (memory) /home/inst23
DFTDBPATH (disk) /home/inst23
MON_HEAP_SZ (4KB) AUTOMATIC(90) AUTOMATIC(90)
JAVA_HEAP_SZ (4KB) 2048 2048
AUDIT_BUF_SZ (4KB) 0 0
INSTANCE_MEMORY (4KB) AUTOMATIC(809669) AUTOMATIC(809669)
RSTRT_LIGHT_MEM (4KB) AUTOMATIC(10) AUTOMATIC(10)
RSTRT_LIGHT_MEM_INT (4KB) NEEDS RECOMPUTE(0) NEEDS RECOMPUTE(0)
AGENT_STACK_SZ 1024 1024
BACKBUFSZ (4KB) 1024 1024
RESTBUFSZ (4KB) 1024 1024
SHEAPTHRES (4KB) 0 0
DIR_CACHE YES YES
ASLHEAPSZ (4KB) 15 15
RQRIOBLK (bytes) 65535 65535
UTIL_IMPACT_LIM 10 10
AGENTPRI SYSTEM SYSTEM
NUM_POOLAGENTS AUTOMATIC(100) AUTOMATIC(100)
NUM_INITAGENTS 0 0
MAX_COORDAGENTS AUTOMATIC(200) AUTOMATIC(200)
MAX_CONNECTIONS AUTOMATIC(MAX_COORDAGENTS)
AUTOMATIC(MAX_COORDAGENTS)
KEEPFENCED YES YES
FENCED_POOL AUTOMATIC(MAX_COORDAGENTS)
AUTOMATIC(MAX_COORDAGENTS)
NUM_INITFENCED 0 0
INDEXREC RESTART RESTART
TM_DATABASE 1ST_CONN 1ST_CONN
RESYNC_INTERVAL (secs) 180 180
SPM_NAME ibmclas8 ibmclas8
SPM_LOG_FILE_SZ 256 256
SPM_MAX_RESYNC 20 20
SPM_LOG_PATH
SVCENAME 50230 50230
DISCOVER SEARCH SEARCH
DISCOVER_INST ENABLE ENABLE
SSL_SVR_KEYDB (memory)
SSL_SVR_KEYDB (disk)
SSL_SVR_STASH (memory)
SSL_SVR_STASH (disk)
SSL_SVR_LABEL (memory)
SSL_SVR_LABEL (disk)
SSL_SVCENAME
SSL_CIPHERSPECS (memory)
SSL_CIPHERSPECS (disk)
SSL_VERSIONS (memory)
SSL_VERSIONS (disk)
SSL_CLNT_KEYDB (memory)
SSL_CLNT_KEYDB (disk)
SSL_CLNT_STASH (memory)
SSL_CLNT_STASH (disk)
MAX_QUERYDEGREE ANY ANY
INTRA_PARALLEL NO NO
FCM_NUM_BUFFERS (4KB) AUTOMATIC(4096) AUTOMATIC(4096)
FCM_NUM_CHANNELS AUTOMATIC(2048) AUTOMATIC(2048)
FCM_PARALLELISM 1 1
FCM_PARALLELISM_INT RECOMPUTE(1) 1
CONN_ELAPSE (secs) 10 10
MAX_CONNRETRIES 5 5
MAX_TIME_DIFF (mins) 60 60
START_STOP_TIME (mins) 10 10
WLM_DISPATCHER NO NO
WLM_DISP_CONCUR COMPUTED(4) COMPUTED
WLM_DISP_CPU_SHARES NO NO
WLM_DISP_MIN_UTIL 5 5
KCFD_CFG_SIGNATURE 19 20
COMM_EXIT_LIST (memory)
COMM_EXIT_LIST (disk)
Now that you have created and configured the new DB2 instance, inst23, you
will use that instance to create a new database.
Results:
You created a new DB2 instance that will support the database that you will
create and manage in the following demonstrations. You used the DB2
command line processor to create the new instance, configured some of the
instance level options and issued commands to start and stop the instance.
Demonstration 1
Creating databases and data placement
Database maintenance, monitoring and problem determination © Copyright IBM Corporation 2016
Demonstration 1:
Creating databases and data placement
Purpose:
This demonstration will create a new DB2 database named MUSICDB that will
support the database objects that you will create and manage in the following
demonstrations. You will create a new storage group and use DB2 commands
and SQL queries to investigate database storage.
10 record(s) selected.
Notice that the DMS managed tablespaces do not have an assigned storage
group. Each tablespace is assigned a unique tablespace ID by DB2.
CONTAINER_NAME
TBSP_NAME POOL_READ_TIME
-------------------------------------------------------------------------------- -
------------------- --------------------
/dbauto/path1/inst23/NODE0000/MUSICDB/T0000000/C0000000.CAT
SYSCATSPACE 1052
/dbauto/path1/inst23/NODE0000/MUSICDB/T0000001/C0000000.TMP
TEMPSPACE1 0
/dbauto/path1/inst23/NODE0000/MUSICDB/T0000002/C0000000.LRG
USERSPACE1 10
/dbauto/path1/inst23/NODE0000/MUSICDB/T0000003/C0000000.LRG
SYSTOOLSPACE 4
/dbauto/path2/inst23/NODE0000/MUSICDB/T0000004/C0000000.LRG
TSP01 1
/database/inst23/NODE0000/SQL00001/tsp02
TSP02 1
/database/inst23/NODE0000/SQL00001/tsp03
TSP03 1
/dbauto/path2/inst23/NODE0000/MUSICDB/T0000007/C0000000.LRG
TSP04 3
/dbauto/path2/inst23/NODE0000/MUSICDB/T0000008/C0000000.LRG
TSP05 1
/dbauto/path1/inst23/NODE0000/MUSICDB/T0000009/C0000000.USR
TSP06 1
10 record(s) selected.
Notice that the tablespaces using the APP_DATA storage group use a different
path from those in the default storage group.
DB_PATH_TYPE PATH_NAME
------------------------------ --------------------------------------------
------
DBPATH /database/inst23/NODE0000/SQL00001/
DBPATH
/database/inst23/NODE0000/SQL00001/MEMBER0000/
DB_STORAGE_PATH /dbauto/path2/
DB_STORAGE_PATH /dbauto/path1/
LOCAL_DB_DIRECTORY /database/inst23/NODE0000/sqldbdir/
LOGPATH
/database/inst23/NODE0000/SQL00001/LOGSTREAM0000/
TBSP_CONTAINER /database/inst23/NODE0000/SQL00001/tsp03
TBSP_CONTAINER /database/inst23/NODE0000/SQL00001/tsp02
8 record(s) selected.
The result shows the disk locations that contain the components of the
database, including the log files, database control files and tablespace storage.
• db2pd -db musicdb -storage | more
The output from this command will look similar to the following:
Database Member 0 -- Database MUSICDB -- Active -- Up 0 days 00:04:19 --
Date 2016-02-25-11.45.40.601046
The db2pd command report provides information about the two storage groups
currently defined for the MUSICDB database.
• db2pd -db musicdb -tablespaces | more
The output from this command will look similar to the following:
Database Member 0 -- Database MUSICDB -- Active -- Up 0 days 00:04:45 --
Date 2016-02-25-11.46.06.178912
Tablespace Configuration:
Address Id Type Content PageSz ExtentSz Auto Prefetch BufID
BufIDDisk FSC NumCntrs MaxStripe LastConsecPg RSE Name
0x00007F5EDB326D40 0 DMS Regular 4096 4 Yes 4 1 1
Off 1 0 3 Yes SYSCATSPACE
0x00007F5EDB333EE0 1 SMS SysTmp 4096 32 Yes 32 1 1
On 1 0 31 No TEMPSPACE1
0x00007F5EDB341080 2 DMS Large 4096 32 Yes 32 1 1
Off 1 0 31 Yes USERSPACE1
0x00007F5EDB34E220 3 DMS Large 4096 4 Yes 4 1 1
Off 1 0 3 Yes SYSTOOLSPACE
0x00007F5EDB35B3C0 4 DMS Large 4096 4 Yes 4 1 1
Off 1 0 3 Yes TSP01
0x00007F5EDB3770C0 5 DMS Large 4096 2 Yes 2 1 1
Off 1 0 1 Yes TSP02
0x00007F5EDB384260 6 DMS Large 4096 8 Yes 8 1 1
Off 1 0 7 Yes TSP03
0x00007F5EDB391400 7 DMS Large 4096 2 Yes 2 1 1
Off 1 0 1 Yes TSP04
0x00007F5EDB39E5A0 8 DMS Large 4096 2 Yes 2 1 1
Off 1 0 1 Yes TSP05
0x00007F5EDB3AB740 9 DMS Regular 4096 4 Yes 4 1 1
Off 1 0 3 Yes TSP06
Tablespace Statistics:
Address Id TotalPgs UsablePgs UsedPgs PndFreePgs
FreePgs HWM Max HWM State MinRecTime NQuiescers
PathsDropped TrackmodState
0x00007F5EDB326D40 0 32768 32764 27196 0 5568
27196 27196 0x00000000 0 0 No n/a
0x00007F5EDB333EE0 1 1 1 1 0 0
- - 0x00000000 0 0 No n/a
0x00007F5EDB341080 2 8192 8160 96 0 8064
96 96 0x00000000 0 0 No n/a
0x00007F5EDB34E220 3 8192 8188 144 0 8044
144 144 0x00000000 0 0 No n/a
0x00007F5EDB35B3C0 4 256 252 12 0 240
12 12 0x00000000 0 0 No n/a
Containers:
Address TspId ContainNum Type TotalPgs UseablePgs PathID
StripeSet Container
0x00007F5EDB320580 0 0 File 32768 32764 0
0 /dbauto/path1/inst23/NODE0000/MUSICDB/T0000000/C0000000.CAT
0x00007F5EDB3B9000 1 0 Path 1 1 0
0 /dbauto/path1/inst23/NODE0000/MUSICDB/T0000001/C0000000.TMP
0x00007F5EDB31A480 2 0 File 8192 8160 0
0 /dbauto/path1/inst23/NODE0000/MUSICDB/T0000002/C0000000.LRG
0x00007F5EDB31AAE0 3 0 File 8192 8188 0
0 /dbauto/path1/inst23/NODE0000/MUSICDB/T0000003/C0000000.LRG
0x00007F5EDB317460 4 0 File 256 252 1024
0 /dbauto/path2/inst23/NODE0000/MUSICDB/T0000004/C0000000.LRG
0x00007F5EDB317B80 5 0 File 128 126 -
0 /database/inst23/NODE0000/SQL00001/tsp02
0x00007F5EDB315600 6 0 File 1024 1016 -
0 /database/inst23/NODE0000/SQL00001/tsp03
0x00007F5EDB315D80 7 0 File 26 24 1024
0 /dbauto/path2/inst23/NODE0000/MUSICDB/T0000007/C0000000.LRG
0x00007F5EDB313D40 8 0 File 16 14 1024
0 /dbauto/path2/inst23/NODE0000/MUSICDB/T0000008/C0000000.LRG
0x00007F5EDB30DD00 9 0 File 8192 8188 0
0 /dbauto/path1/inst23/NODE0000/MUSICDB/T0000009/C0000000.USR
The db2pd command report provides information about the tablespaces for the
MUSICDB database, including disk space usage, container assignments and
storage group usage.
2. You can now skip to the end of this demonstration.
7B. Use the Data Server Manager tool.
You can use the DSM tool to execute the SQL file containing the SQL query.
1. Click the Home option on the left side of the DSM application.
You should see the database MUSICDB listed. The database name MUSICDB
provides a drop down list to perform different tasks.
2. Select Administer - Explore Database from the drop down list of the
MUSICDB database.
You will be prompted for a userid and password for the MUSICDB database
connection, use inst23 with a password of ibm2blue.
3. Click on Open SQL Editor.
4. Click Upload (depending on your window size, Upload may be located in the
More Actions list). Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/select_tablespaces.sql. Click on OK to
complete loading the SQL text into the SQL editor.
Review the SQL query text.
5. Click Run, and then wait for the SQL statement to be processed.
The result should show that the SQL statement succeeded. The result also
contains the query result in a columnar report.
Review the report. The result area contains an icon for Open that will show the
query results in its own view.
You will now utilize the SQL query text in the file
inst23/ddl/select_mon_get_tbsp.sql to retrieve table space information and
statistics.
6. Click Open SQL Editor.
7. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/select_mon_get_tbsp.sql. Click on OK to
complete loading the SQL text into the SQL editor.
Review the SQL query text.
8. Click Run, and then wait for the SQL statement to be processed.
The result should show that the SQL statement succeeded. The result also
contains the query result in a columnar report.
9. Review the report. The result area contains an icon for Open that will show the
query results in its own view.
Notice that the two DMS managed table spaces, TSP02 and TSP03, do not
have a storage group, since storage groups only apply to automatic storage
managed table spaces.
You will now utilize the SQL query text in the file
inst23/ddl/select_mon_get_cont.sql to retrieve a list of disk containers for
each table space in the database.
10. Click Open SQL Editor.
11. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/select_mon_get_cont.sql. Click on OK to
complete loading the SQL text into the SQL editor.
12. Review the SQL query text.
13. Click Run, and then wait for the SQL statement to be processed.
The result should show that the SQL statement succeeded. The result also
contains the query result in a columnar report.
Review the report. The result area contains an icon for Open that will show the
query results in its own view.
Notice that the tablespaces using the APP_DATA storage group have two
containers assigned because the storage group has two paths defined.
Use the SQL query text in the file inst23/ddl/dbpaths.sql to retrieve information
about the disk paths used to support components of this database.
14. Click Open SQL Editor.
15. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/dbpaths.sql. Click on OK to complete
loading the SQL text into the SQL editor.
16. Review the SQL query text.
17. Click Run, and then wait for the SQL statement to be processed.
The result should show that the SQL statement succeeded. The result also
contains the query result in a columnar report.
18. Review the report. The result area contains an icon for Open that will show the
query results in its own view.
The query result shows the disk locations that contain the components of the
database, including the log files, database control files and tablespace storage.
Results:
You created a new DB2 database named MUSICDB that will support the
database objects that you will create and manage in the following
demonstrations. You created a new storage group and a set of table spaces.
You used DB2 commands and SQL queries to investigate database storage.
Demonstration 1
Creating database objects
• Create a set of tables using the Data Server Manager to build the
CREATE TABLE statement or using saved DDL in a file.
• Create indexes for tables using the CREATE INDEX statement.
• Create views and alias objects using SQL statements in a file.
• Create foreign key and check constraints for a table using SQL
statements in a file.
• Use the db2look utility to extract database object definitions from a
DB2 database.
Database maintenance, monitoring and problem determination © Copyright IBM Corporation 2016
Demonstration 1:
Creating database objects
Purpose:
This demonstration will create a group of database objects in the DB2
database named MUSICDB.
7. Select Run with SQL Editor for the Run Schedule, and then click Finish.
The result should show that the command processing succeeded.
8. Close the Create Schema tab.
Now you can create a table, ALBUMS, in the new schema, MUSIC.
9. Using the object tree structure, click Tables.
10. At the top, click Create to open a list of options to define a new table.
11. Enter the following values for the PROPERTIES of the new table:
• Name: ALBUMS
• Schema: MUSIC
• Table space: TSP04
• Index table space: TSP05
12. Under the Create Table tab, click Columns to define the table columns.
13. Click Add column to define a column, using:
• Name: TITLE
• Data Type: Varchar
• Length: 50
14. Click Columns to return to the column list.
15. Click Add column to define a column, using:
• Name: ARTNO
• Data Type: Smallint
• Nullable: No
16. Click Columns to return to the column list.
17. Click Add column to define a column, using:
• Name: ITEMNO
• Data Type: Smallint
• Nullable: No
18. Click Constraints.
• Click Add constraint to define a constraint, select Primary key as the
constraint type, using:
• Name: ALBUM_ITEM
19. Click Add, and then select the column ITEMNO.
The DSM tool generates the CREATE TABLE statement and the ALTER
TABLE statement to add the primary key.
4. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/create_tables.ddl.
5. Click OK to complete loading the SQL text into the SQL editor.
Review the options specified for the five CREATE TABLE statements.
The table MUSIC.STOCK will be defined as a System-period temporal table.
The table MUSIC.STOCK_HISTORY will be used as the history table for
MUSIC.STOCK.
Notice the assignments of tables to table spaces.
For DMS and Automatic Storage Managed table spaces, multiple table spaces
can be used for the data, index and large object components of a single table.
Which table space(s) will be used for data, indexes and large objects for the
table STOCK? For CONCERTS? For ARTISTS?
6. Click Run and wait for the SQL statements to be processed.
The result should show that all of the statements succeeded.
Task 4. Create index, view and alias objects for the
application tables.
Next you will create an index on the STOCK table based on the column ITEMNO.
You will also use the SQL statements in the file create_View_Alias.ddl to create view
and alias objects.
The file $HOME/ddl/create_stock_ix.ddl contains the CREATE INDEX statement.
The file contains the following statement text:
create index music.stockitem_ix on music.stock(itemno) ;
At this point, you may choose to create the new index, view, and alias objects using the
DB2 command line processor or the Data Server Manager tool. Follow the steps for
your chosen tool only.
4A. Use the DB2 command line processor.
1. Enter the following commands using the Linux terminal session:
• cd $HOME/ddl
• db2 connect to musicdb
• db2 -tvf create_stock_ix.ddl
• db2 describe indexes for table music.stock
• db2 -tvf create_VIEW_ALIAS.ddl
• db2 list tables for schema music
2. You can now skip to Task 5.
4B. Use the Data Server Manager tool.
You can use the DSM tool to create the index, view and alias objects.
1. Click the Home option on the left side of the DSM application.
You should see the database MUSICDB listed with some basic statistics on
resource usage including, CPU, I/O and Memory. The database name
MUSICDB provides a drop down list to perform different tasks.
2. Select Administer - Explore Database from the drop down list of the
MUSICDB database.
You will be prompted for a userid and password for the MUSICDB database
connection; use inst23 with a password of ibm2blue.
A tree structure of database objects for this database is shown on the left side of
the DSM view.
3. Click Indexes. The current index objects will be listed.
4. Under the Database Explorer tab, click Create to open a list of options to define
a new storage group. Select the MUSIC.STOCK table from the table list and
enter the following values for the new storage group:
• Name: STOCKITEM_IX
• Members: select Add, then select the ITEMNO column
• Leave other options with default values
The DSM tool generates the CREATE INDEX statement that will define the new
index named STOCKITEM_IX.
1. Issue the following series of commands using the DB2 command line
processor.
• cd $HOME/ddl
• db2 connect to musicdb
• db2 -tvf create_ri_cc.ddl
• db2 -tvf create_trigger.ddl
2. You can now skip to Task 6.
5B. Use the Data Server Manager tool.
You can use the DSM tool to execute the SQL file containing the ALTER TABLE
statements to create referential integrity and check constraints.
1. Click Home on the left side of the DSM application.
You should see the database MUSICDB listed. The database name MUSICDB
provides a drop down list to perform different tasks.
2. Select Administer - Explore Database from the drop down list of the
MUSICDB database.
You will be prompted for a userid and password for the MUSICDB database
connection, use inst23 with a password of ibm2blue.
3. Click Open SQL Editor.
4. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/create_ri_cc.ddl.
5. Click OK to complete the loading of the SQL text into the SQL editor.
Review the options specified for the SQL statements.
6. Click Run and wait for the SQL statements to be processed.
The result should show that all statements succeeded.
You can use the file inst23/ddl/create_trigger.ddl in the SQL Editor to define a
new trigger.
7. Click Open SQL Editor.
8. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/ create_trigger.ddl.
9. Click OK to complete the loading of the SQL text into the SQL editor.
Review the options specified for the SQL statements.
The new trigger should be similar to the following:
10. Click Run and wait for the SQL statement to be processed.
The result should show that the command processing succeeded.
CONNECT TO MUSICDB;
------------------------------------------------
-- DDL Statements for Table "MUSIC "."ALBUMS"
------------------------------------------------
----------------------------
----------------------------
SET CURRENT SCHEMA = "INST23 ";
SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","INST23";
create view music.music as select title, classification, name
from music.albums alb, music.artists art
where art.artno = alb.artno;
COMMIT WORK;
CONNECT RESET;
TERMINATE;
Results:
You created a group of database objects in the DB2 database named
MUSICDB.
Moving data
Demonstration 1
Moving data
• Use the DB2 IMPORT command to load data into a DB2 table.
• Run the INGEST command to efficiently load data into a DB2 table.
• Invoke the LOAD utility to process input files and load data into DB2
tables.
• Run SET INTEGRITY commands to resolve the set integrity pending
conditions resulting from loading data into tables with constraints
defined using a LOAD utility.
Demonstration 1:
Moving data
Purpose:
This demonstration uses several methods to load data into DB2 tables
including the IMPORT, INGEST and LOAD commands. You will use the SET
INTEGRITY statement to resolve constraint checking after using a LOAD
command.
SQL3110N The utility has completed processing. "79" rows were read
from the
input file.
SQL3149N "79" rows were processed from the input file. "79" rows
were
successfully inserted into the table. "0" rows were rejected.
2. Select Administer - Explore Database from the drop down list of the
MUSICDB database.
You will be prompted for a userid and password for the MUSICDB database
connection, use inst23 with a password of ibm2blue.
3. Click Open SQL Editor.
4. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/import_artists.sql
5. Click OK to complete loading the SQL text into the SQL editor.
The CALL to the procedure SYSPROC.ADMIN_CMD, will be used to invoke the
IMPORT command. The INSERT option of IMPORT is being used.
Notice the MESSAGES ON SERVER option is included, which allows the
IMPORT to run from a client system but the generated messages are stored on
the database server.
6. Click Run and wait for the SQL CALL statement to be processed.
The result area shows that 79 data rows were read from the file and inserted
into the table MUSIC.ARTISTS.
Task 2. Use the INGEST command to load data into a
DB2 table.
You can use the Linux terminal session to run the INGEST command to load data files
into a DB2 table. The Data Server Manager tool does not currently provide a method to
invoke the INGEST command.
The INGEST command uses a work table SYSTOOLS.INGESTRESTART to save
command restart data.
The file cr_toolspace.ddl will be used to create this table prior to running the INGEST
command. This only needs to be performed once per DB2 database.
The file $HOME/ddl/ingest_albums.ddl contains the following INGEST
command:
ingest from file /home/inst23/albums.del
format delimited messages ingest_albums.txt
RESTART NEW 'ingest_alb' INSERT INTO music.albums ;
1. Issue the following series of commands using the Linux terminal session.
• cd $HOME/ddl
• db2 connect to musicdb
• db2 -tvf cr_toolspace.ddl
• db2 -tvf ingest_albums.ddl
After a few seconds, the output generated will look similar to the following:
5. Click Run and wait for the SQL CALL statement to be processed.
The result area shows that 777 data rows were read from the file and inserted
into the table MUSIC.STOCK.
The LOAD utility placed the STOCK table into set integrity pending state
because the table has constraints defined. You can use the SET INTEGRITY
command to resolve this state.
6. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/set_integrity_stock.sql. Click on OK to
complete loading the SQL text into the SQL editor.
The file contains the following SQL text:
SET INTEGRITY FOR MUSIC.STOCK
ALLOW NO ACCESS IMMEDIATE CHECKED
;
The SET INTEGRITY statement is needed to check the foreign key and check
constraints defined for the STOCK table
7. Click on Run and wait for the SQL statement to be processed.
The result should show that the SET INTEGRITY statement succeeded.
Task 4. Run a file containing a series of LOAD commands and
SET INTEGRITY statements.
You may want to periodically refresh or extend tables with new data. If you use the DB2
LOAD utility and the target tables include referential or check constraints, you will need
to run SET INTEGRITY statements following the load processing.
You will utilize a command script that contains LOAD commands and SET INTEGRITY
statements to load data into several tables.
It is normally a good idea to use exception tables during a LOAD operation. You have
been provided a script (named create_exception_tables.ddl) that will create exception
tables for ARTISTS and ALBUMS.
At this point, you may choose to use the DB2 command line processor or the Data
Server Manager tool, to perform the LOAD and SET INTEGRITY processing.
Follow the steps for your chosen tool only.
1 record(s) selected.
0 record(s) selected.
2. You have now completed this lab exercise.
Demonstration 1
Backup and recovery
Demonstration 1:
Backup and recovery
Purpose:
This demonstration utilizes the database MUSICDB to perform backup and
recovery related tasks. During this demonstration, you will prepare the
database for archival logging, create a backup image and recover the
database to a selected point in time. You will also configure the database log
space to handle applications with large transactions.
Now you will connect to the MUSICDB database and run two SQL command
files using the DB2 command line processor.
For the change processing, you will include the +C option to process the
statements as a single unit of work or transaction.
The DB2 command line processor will automatically commit each statement
processed by default. The +C option turns autocommit off, so that all of the
changes made by multiple statements must be retained in the DB2 active log
files to support rolling back the changes, if necessary.
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I The SQL command completed successfully.
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0964C The transaction log for the database is full. SQLSTATE=57011
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0964C The transaction log for the database is full. SQLSTATE=57011
Once your limited database log space is filled, the database changes fail with
the SQL0964 message indicating that “The transaction log for the database is
full”.
Use the DB2 command file increase_logs.ddl to allocate sufficient database
log space to process the database changes.
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I The SQL command completed successfully.
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I The SQL command completed successfully.
insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I The SQL command completed successfully.
insert into temp_stock select itemno,type,price,qty from stock where TYPE = 'C'
DB20000I The SQL command completed successfully.
CURRENT_SIZE 2 3
------------ ---------- --------
259 09/16/2015 06:55:25
1 record(s) selected.
3. Run the command file a second time to make additional logged changes and
note the results.
• db2 -tvf stock_insert2.sql
4. Record the following from the SQL result:
• Current Table size: ____________ (result 2)
• Local date: _____________ (result 2)
• Local time: _____________ (result 2)
5. You can now skip to Task 4.
3B. Use the Data Server Manager tool.
You will use the Data Server Manager tool to run the SQL scripts that perform the
database changes.
1. Click the Home option on the left side of the DSM application.
You should see the database MUSICDB listed. The database name MUSICDB
provides a drop down list to perform different tasks.
2. Select Administer - Explore Database from the drop down list of the
MUSICDB database.
You will be prompted for a userid and password for the MUSICDB database
connection, use inst23 with a password of ibm2blue.
A tree structure of database objects for this database is shown on the left side of
the DSM view.
3. Click Open SQL Editor.
4. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/stock_insert2.sql.
5. Click OK to complete loading of the SQL text into the SQL editor.
Review the SQL statements.
6. Click Run and then wait for the SQL statements to be processed.
7. Record the following from the SQL result:
• Current Table size: ____________ (result 1)
• Local date: _____________ (result 1)
• Local time: _____________ (result 1)
Now run the INSERT script a second time to generate a second set of logged
changes.
8. Click Run and wait for the SQL statements to be processed.
9. Record the following from the SQL result:
Now connect to the database and check the count of rows in the
MUSIC.TEMP_STOCK table. The count should match the number of rows
recorded for the first execution of the SQL insert script.
2. Issue the following series of commands using the DB2 command line
processor.
• db2 connect to musicdb
• db2 “select count(*) from music.temp_stock“
• db2 terminate
Results:
You utilized the database MUSICDB to perform backup and recovery related
tasks, including configuring the database for archival logging, creating a
backup image and recovered the database to a selected point in time. You
also configured the database log space to handle applications with large
transactions.
Database maintenance,
monitoring and problem
determination
Demonstration 1
Using DB2 tools for performance
• Use an explain tool to analyze the access plan for an SQL statement.
• Create an index for a table to reduce processing costs for SQL.
• Invoke the DB2 Design Advisor to suggest new indexes for an SQL
workload.
• Use the DB2 RUNSTATS and REORG commands to reorganize a
table based on an index and collect new catalog statistics.
Database maintenance, monitoring and problem determination © Copyright IBM Corporation 2016
Demonstration 1:
Using DB2 tools for performance
Purpose:
This demonstration uses several DB2 tools and utilities to improve the
performance of a SQL query. You will use the Data Server Manager Visual
Explain tool to review the access plans and the estimated costs for
processing SQL statements. You will use the DB2 design advisor to suggest a
new index to reduce processing costs. You will execute a DB2 REORG utility
to reorganize a table to improve performance.
Task 1. Load a test table and create a set of explain tables for
query analysis.
1. Logon to the Linux system using the user id inst23, with a password of
ibm2blue.
You will use the Linux Terminal session to enter DB2 commands.
2. Right-click the empty Linux desktop and select Open in Terminal.
In this section, you will run a SQL script that creates and loads a DB2 table,
TEST.HISTORY, that will be used to analyze the performance of a test query.
You will also create a set of explain tables that can be used to support explain
tool access plan analysis. The file explain.ddl calls the SYSINSTALLOBJECTS
procedure to create a set of explain tables matching the current DB2 release.
3. Issue the following series of commands in the Linux terminal session.
• cd $HOME/ddl
• db2 connect to musicdb
• db2 -tvf explain.ddl
• db2 -tvf create_testhist.ddl
The SQL statements show a sum from the QTY column for a set of rows before
and after the UPDATE processing.
SQL3150N The H record in the PC/IXF file has product "DB2 02.00", date
"20120817", and time "154700".
SQL3050W Conversions on the data will be made between the IXF file code
page
"1252" and the application code page "1208".
SQL3110N The utility has completed processing. "200000" rows were read
from
the input file.
SQL3515W The utility has finished the "LOAD" phase at time "02/29/2016
06:46:05.885784".
CONNECT RESET
DB20000I The SQL command completed successfully.
5. Click Upload (which may be part of a list labelled More Actions). Use the
Browse button for the Open SQL Script window to locate and select the file
inst23/ddl/query_history.sql
6. Click OK to complete loading of the SQL text into the SQL editor.
The SQL statement is a SELECT from the table test.HISTORY with two
predicates, one on the BRANCH_ID column and one on the TELLER_ID
column.
7. Click Explain to generate the access plan report.
8. Select the TBSCAN operation and look at the cost statistics that appear to the
left of the TBSCAN octagon.
A TBSCAN operation will read every page in the table to produce the result.
Look at the following:
• Estimated Cardinality: _____________ (test result 162)
• Cumulative Total Cost: _____________ (test result 3,328)
• Cumulative I/O Cost : _____________ (test result 3,575)
Your results may be slightly different, but a test result produced the estimated
cardinality of 162 rows, and an estimated I/O cost of 3,575, which is the number
of pages in the table being accessed. There are 200,000 rows in the test table,
so the access plan will scan every row and only return about 162 rows of result.
You should be able to tune this query to run more efficiently.
9. Close the Explain tab to return to the SQL Editor.
This index may be very efficient for processing this one SQL statement, but you
will create a simple two column index, on BRANCH_ID and TELLER_ID, that
will require less disk space.
You will start a second SQL Editor view in Data Server Manager to run the
CREATE INDEX and RUNSTATS statements, using the file,
inst23/ddl/create_testhist_ix.ddl, that contains the following commands:
create index test.histix on test.history (branch_id, teller_id) ;
Call SYSPROC.ADMIN_CMD( 'runstats on table test.history and indexes all
' ) ;
2. Using DSM, click Open SQL editor.
3. Click Upload. Use the Browse button for the Open SQL Script window to
locate and select the file inst23/ddl/create_testhist_ix.ddl.
4. Click OK to complete loading the SQL text into the SQL editor.
5. Review the CREATE INDEX statement and the ADMIN_CMD procedure call
that is used to invoke the RUNSTATS processing.
6. Click Run and wait for the SQL statements to be processed.
2. Select the FETCH operation and look at the cost statistics that appear.
The DSM tool generates the REORG TABLE command with a procedure call to
ADMIN_CMD.
The command text should be similar to the following:
CALL SYSPROC.ADMIN_CMD ('REORG TABLE TEST.HISTORY INDEX TEST.HISTIX
USE TEMPSPACE1');
7. Click Next.
8. Select Run with SQL Editor for Run schedule, and then click Finish.
The result should show that the command processing succeeded.
9. Close the Reorganize Table Data tab.
You need to collect new table and index statistics, so that the DB2 Optimizer
can accurately plan access to the newly reorganized table.
10. Click the Table History tab.
11. Select Collect Statistics (which may be listed under the More Actions list).
12. Click Next. (If 'Next' does not appear, you may have to clear your browser
History and Cache, and log in again after closing your browser.)
13. Leave all of the options with default values, and then click Next.
14. Select Run with SQL Editor for the Run schedule, and then click Finish.
The result should show that the command processing succeeded.
15. Close the Statistics Collection tab.
Task 6. Use the Explain SQL capability of DSM to recheck the
access plan and estimated costs after table
reorganization.
You will be using the SQL in the file inst23/ddl/query_history.sql which should still be
in a SQL Editor view in DSM. If not, open a new SQL Editor and upload the SQL text
from the file.
1. Click Explain to generate the access plan report.
The access plan utilizes the index with an IXSCAN, or index scan operation,
followed by the FETCH to retrieve data rows using the index pointers. The new
estimated costs are much lower with a reorganized table.
2. Select the FETCH operation and look at the cost statistics that appear.
Demonstration 1
Investigating DB2 locking
Database maintenance, monitoring and problem determination © Copyright IBM Corporation 2016
Demonstration 1:
Investigating DB2 locking
Purpose:
This demonstration uses several SQL scripts to demonstrate the types of
locks used for processing SQL statements with different application isolation
levels. You will create and analyze a lock wait condition. A LOCKING event
monitor will be used to capture diagnostic data about lock related events.
Locks:
Address TranHdl Lockname Type Mode Sts
Owner Dur HoldCount Att ReleaseFlg rrIID
0x0000000001131F80 3 09000400280001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001137280 3 09000500150000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001132600 3 09000400200001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001136A00 3 090005000D0000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001132C00 3 090004002B0001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001132E00 3 09000500050000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001131980 3 4141414141664164FE8BC714C1 PlanLock ..S G 3
1 0 0x00000000 0x40000000 0
0x0000000001131880 3 09000400230001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001136D00 3 09000500100000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001132800 3 090004001B0001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
1. Issue the following series of commands using the Linux terminal session:
• db2 update db cfg using mon_lockwait without_hist
• db2 update db cfg using mon_locktimeout without_hist
• db2 -tvf create_lock_monitor.sql
The command output will look similar to the following:
create event monitor mon_locks for locking write to table autostart
DB20000I The SQL command completed successfully.
SCHEMA MON_TABLE
---------- ----------------------------------------
INST23 CONTROL_MON_LOCKS
INST23 LOCK_MON_LOCKS
INST23 LOCK_PARTICIPANTS_MON_LOCKS
INST23 LOCK_PARTICIPANT_ACTIVITIES_MON_LOCKS
INST23 LOCK_ACTIVITY_VALUES_MON_LOCKS
2. Issue the following series of commands using the Linux terminal session:
• db2 connect to musicdb
• db2 +C -tvf stock_update.sql
3. To start a second Linux terminal session, right-click the empty Linux desktop
and select Open in Terminal.
4. Using the second Linux terminal session, issue the following series of
commands:
• cd $HOME/ddl
• db2 connect to musicdb user user23 using ibm2blue
You will start by running the SQL script, stock_select_ur.sql. The script starts
by setting the special registers CURRENT LOCK TIMEOUT and CURRENT
ISOLATION. The statement SET CURRENT ISOLATION ur sets the locking
isolation level to Uncommitted Read, the lowest level for isolation. This allows
the connection to access data rows updated by other applications that have not
committed those changes.
5. Using the second Linux terminal session, issue the following command:
• db2 -tvf stock_select_ur.sql
The command output will look similar to the following:
1
-----------
115
1 record(s) selected.
The result for the sum(QTY) using isolation level UR reflects the changes made
by the uncommitted UPDATE in the other CLP session.
Next you will run the SQL script, stock_select_cs.sql. The script starts by
setting the special registers CURRENT LOCK TIMEOUT and CURRENT
ISOLATION. The statement SET CURRENT ISOLATION cs, sets the locking
isolation level to Cursor Stability, the default level for isolation. This does not
allow the connection to access data rows updated by other applications that
have not committed those changes, but DB2 can use special log records to
retrieve the data rows contents before the changes were made.
6. Using the second Linux terminal session, issue the following command:
• db2 -tvf stock_select_cs.sql
The command output will look similar to the following:
set current lock timeout 300
DB20000I The SQL command completed successfully.
1
-----------
112
1 record(s) selected.
The result for the sum(QTY) using isolation level CS does not include the
changes made by the uncommitted UPDATE in the other CLP session.
Next you will run the SQL script, stock_select_rs.sql. The script starts by
setting the special registers CURRENT LOCK TIMEOUT and CURRENT
ISOLATION. The statement SET CURRENT ISOLATION rs sets the locking
isolation level to Read Stability. This isolation level requires row locks for any
row of data included in the SQL result. Since the UPDATE executed in the first
CLP session was not committed, the SELECT for that data in this second
session will cause a lock wait condition.
7. Using the second Linux terminal session, issue the following series of
commands:
• db2 connect to musicdb user user23 using ibm2blue
• db2 -tvf stock_select_rs.sql
The SELECT SQL statement cannot complete because row locks are needed
to produce the result that are held by the other CLP session. Right now, it
appears to have been successful.
You can use the db2pd command to look for active lock waits, but you will need
to run the command from the first CLP session.
8. Switching back to the first terminal session, issue the following command:
• db2pd -db musicdb -wlock
The command output will look similar to the following:
Database Member 0 -- Database MUSICDB -- Active -- Up 0 days 00:12:13 -- Date
2015-09-18-10.20.38.667000
The db2pd command output shows that a row lock is held (G) by one user
connection, inst23, but a NS read lock is waiting (W) for the connection user
user23.
You can use the -lock report of db2pd to see the full list of locks held by the two
connections, including the lock that is being waited for.
9. Using the first terminal session, issue the following series of commands:
• db2pd -db musicdb -lock
The command output will look similar to the following:
Locks:
Address TranHdl Lockname Type Mode Sts
Owner Dur HoldCount Att ReleaseFlg rrIID
0x0000000001131F80 3 09000400280001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001137280 3 09000500150000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001132600 3 09000400200001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001136A00 3 090005000D0000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001132C00 3 090004002B0001000000000052 RowLock ..X G 3
1 0 0x00200000 0x40000000 0
0x0000000001132E00 3 09000500050000000000000052 RowLock ..X G 3
1 0 0x00200008 0x40000000 0
0x0000000001131980 3 4141414141664164FE8BC714C1 PlanLock ..S G 3
1 0 0x00000000 0x40000000 0
0x000000000113B080 12 4141414141664164FE8BC714C1 PlanLock ..S G
12 1 0 0x00000000 0x40000000 0
The SQL command file included the SET CURRENT LOCK TIMEOUT
statement to limit the time that a SQL statement will wait for a lock, before a
SQL error return code is generated.
10. In the second Linux terminal session, wait for the lock timeout condition to
occur and the DB2 error message to be returned.
The command output will look similar to the following:
set current lock timeout 180
DB20000I The SQL command completed successfully.
select participant_no,
varchar(auth_id,10) as auth_id,
varchar(appl_name,20) as appl_name,
varchar(table_name,12) as tabname,
varchar(table_schema,12) as tabschema,
lock_object_type , participant_type , lock_status
from lock_participants_mon_locks
where event_type='LOCKTIMEOUT' ;
select
participant_no, effective_isolation,
varchar(stmt_operation,20) as operation,
varchar(stmt_text,50) as sql_text
from lock_participant_activities_mon_locks
where event_type='LOCKTIMEOUT' ;
The first query uses the LOCK_MON_LOCKS table to show the type of each
locking event and the time stamp when the data was captured. There should be
at least one LOCKTIMEOUT and one or more LOCKWAIT events.
The next query looks at the LOCK_PARTICIPANTS_MON_LOCKS table to see
which user, application and table were associated with the lock timeout.
The third query uses the LOCK_PARTICIPANT_ACTIVITY_MON_LOCKS
table to see the SQL text and isolation level for the application that received the
lock timeout condition.
You should use the SET EVENT MONITOR command to stop collecting the
locking data.
1. Using the first Linux terminal session, issue the following series of
commands:
• db2 commit
• db2 connect to musicdb
• db2 set event monitor mon_locks state 0
• db2 -tvf query_lock_events.sql | more
The command output will look similar to the following:
select event_id , event_type, event_timestamp from lock_mon_locks
EVENT_ID EVENT_TYPE
EVENT_TIMESTAMP
-------------------- ------------------------------------------------
1 LOCKWAIT
2015-12-03-13.05.57.075574
2 LOCKTIMEOUT
2015-12-03-13.09.09.809327
3 LOCKWAIT
2015-12-03-13.13.06.622011
4 LOCKTIMEOUT
2015-12-03-13.16.24.172684
4 record(s) selected.
4 record(s) selected.
Results:
You created and analyzed a lock wait condition. A LOCKING event monitor
was used to capture diagnostic data about lock related events.
Security
Demonstration 1
Database security
• Describe the default privileges that were granted to PUBLIC and the
database creator when the database was created.
• Implement a SECADM user for the database that does not have either
SYSADM or DBADM authorities
• Grant privileges to individuals, groups, or roles
• Compare the privileges that can be used to run utilities like LOAD,
IMPORT or RUNSTATS.
Database maintenance, monitoring and problem determination © Copyright IBM Corporation 2016
Demonstration 1:
Database security
Purpose:
This demonstration allows the student to manage the security privileges of
the DB2 database to support different types of users. A security administrator
with the SECADM authority will be implemented. Another user will be given
the DBADM authority for this database. An application developer will be
granted specific privileges to support their assignment. Several database
roles will be created to provide access based on role membership, rather than
managing the authorizations at the user level.
This task will be performed using the DB2 command line processor.
3. Issue the following series of commands using the Linux terminal session.
• cd $HOME/ddl
• db2 connect to musicdb
• db2 grant secadm on database to user ctrl23
• db2 -tvf select_dbauth.sql
The output will look similar to the following:
GRANTEE GRANTOR CONNECTAUTH LOADAUTH DBADMAUTH SECURITYADMAUTH
------------ ------------ ----------- -------- --------- ---------------
INST23 SYSIBM N N Y Y
PUBLIC SYSIBM Y N N N
CTRL23 INST23 N N N Y
3 record(s) selected.
You will need a second Linux terminal session to be able to start a second
database connection that will be used by the security administrator, ctrl23. You
will connect to the MUSICDB database using a different system userid, ctrl23,
to make it easier to manage the security privileges for the database.
4. To start a second Linux terminal session, right-click the empty Linux desktop
and select Open in Terminal.
5. Using the second Linux terminal session, issue the following series of
commands.
• cd $HOME/ddl
• db2 connect to musicdb user ctrl23 using ibm2blue
Rather than grant the DBADM authority directly to the user dba23, you will
create a new database role named dba_role. This role can be used to define a
set of database authorizations that new staff can utilize as needed. The
WITHOUT ACCESSCTRL option will be used to provide broad access to table
data, but not allow users of this role to grant and revoke privileges. The new
security administrator can perform this work.
6. Using the second Linux terminal session, issue the following series of
commands:
• db2 create role dba_role
• db2 grant dba_role to user dba23
• db2 grant dbadm without accessctrl on database to role dba_role
The user system user23 does not have the SELECT authority for the table
MUSIC.ALBUMS. You could grant the authority to the user directly, but you will
grant the access to the developer role dev_role, so all the developers can
perform the access if needed. You will grant the SELECT privilege on the table
MUSIC.ALBUMS to the role dev_role.
7. Using the second Linux terminal session, issue the following series of
commands:
• db2 create role dev_role
• db2 grant dev_role to user user23
• db2 grant load on database to role dev_role
• db2 -tvf select_dbauth.sql
The output should look similar to the following:
GRANTEE GRANTOR CONNECTAUTH LOADAUTH DBADMAUTH SECURITYADMAUTH
------------ ------------ ----------- -------- --------- ---------------
INST23 SYSIBM N N Y Y
PUBLIC SYSIBM Y N N N
CTRL23 INST23 N N N Y
DBA_ROLE CTRL23 N N Y N
DEV_ROLE CTRL23 N Y N N
5 record(s) selected.
2. Using the third Linux terminal session, issue the following series of
commands:
• cd $HOME/ddl
• db2 connect to musicdb user dba23 using ibm2blue
Try to create a new table space using this database user.
3. Using the third Linux terminal session, issue the following command:
• db2 create tablespace testdata
The CREATE TABLESPACE fails with a SQL0552N message. The DBADM
database authority does not allow a user to create new table spaces. Currently
the inst23 user would need to perform that task.
The user dba23 can be used to create a new table and load data into the new
table.
Issue the following SQL statements using the third terminal session connected
as dba23.
4. Using the third Linux terminal session, issue the following series of
commands:
• db2 create table test.albums like music.albums in userspace1
• db2 “export to album.del of del select * from music.albums“
• db2 “import from album.del of del insert into test.albums“
• db2 runstats on table test.albums
• db2 runstats on table music.albums
As a DBADM user, you were able to access the table MUSIC.ALBUMS, and
execute RUNSTATS commands for any table.
The user named user23 was placed in a role for developers named
dev_role. You can run some SQL statements using the user23 user to test
its ability to access data and perform development tasks.
Issue the following SQL statements using the third terminal session
connected as dba23.
5. Using the third Linux terminal session, issue the following series of
commands:
• db2 connect to musicdb user user23 using ibm2blue
• db2 create table test.album2 like music.albums in tsp01
The CREATE TABLE fails with a SQL0551N message. The user user23 does
not have the USE authority for the tablespace TSP01. When the database was
created, USE authority for the tablespace USERSPACE1 was granted to
PUBLIC. Create the new test table using the USERSPACE1 table space.
• db2 create table test.album2 like music.albums in userspace1
Now attempt to copy some rows from the table MUSIC.ALBUMS to the new test
table.
6. Using the third Linux terminal session, issue the following command:
• db2 “insert into test.album2 select * from music.albums where artno =
42 “
The INSERT fails with a SQL0551N message.
The user user23 does not have the SELECT authority for the table
MUSIC.ALBUMS. You could grant the authority to the user directly, but you will
grant the access to the developer role dev_role, so all the developers can
perform the access if needed. The security administrator will perform the task.
7. Using the second Linux terminal session, issue the following series of
commands:
• db2 grant select on table music.albums to role dev_role
• db2 grant select,update on table test.albums to role dev_role
You run some additional SQL statements using the user23 user to test its ability
to access data in the database.
8. Using the third DB2 command line window, issue the following series of
commands:
• db2 connect to musicdb user user23 using ibm2blue
• db2 “insert into test.album2 select * from music.albums where artno =
42 “
The INSERT is now successful. The user user23 now has the authority to
SELECT from the table MUSIC.ARTISTS as a member of the role dev_role. As
the creator of the table TEST.ALBUM2 the user has all SQL privileges for that
table.
Next, run the SQL statements in the script file test_user23.sql.
9. Using the third DB2 command line window, issue the following series of
commands:
• db2 connect to musicdb user user23 using ibm2blue
• db2 -tvf test_user23.sql | more
The output should look similar to the following:
select title from test.albums where itemno =97
TITLE
--------------------------------------------------
1962 - 1966
1 record(s) selected.
The only statement execution that failed security tests was the DELETE from
the table TEST.ALBUMS. The user user23, as a member of the role dev_role
was able to perform SELECT and UPDATE access to the table TEST.ALBUMS
that was created by the user dba23. As creator of the table TEST.ALBUM2, the
user user23 could perform any type of access and could drop the table.
Results:
You managed the security privileges of the DB2 database to support different
types of users. A security administrator with the SECADM authority was
implemented. Another user was given the DBADM authority for this database.
An application developer was granted specific privileges to support their
assignment. Several database roles were created to provide access based on
role membership rather than managing the authorizations at the user level.