You are on page 1of 92

IBM DB2 LUW

ADMINISTRATION
FOR SAP -
HANDS-ON LABS

IBM PureData Ecosystem and SAP Information Management


April 2012
Olaf Depper (OD@de.ibm.com)

Page 1/92
Table of Contents
VMWare Image ....................................................................................................................................................... 4

Hands-On Labs ........................................................................................................................................................ 5

Unit 1 Basics ......................................................................................................................................................... 6

Hands-On Lab 1.1 Accessing DB2 .................................................................................................................. 6

Hands-On Lab 1.2 Database Objects ...........................................................................................................11

Hands-On Lab 1.3 Security ...........................................................................................................................15

Hands-On Lab 1.4 Communication ..............................................................................................................18

Hands-On Lab 1.5 DB2 Process Model ........................................................................................................21

Hands-On Lab 1.6 Configuration..................................................................................................................24

Hands-On Lab 1.7 Memory Model ..............................................................................................................28

Unit 2 Storage Management .............................................................................................................................31

Hands-On Lab 2.1 Get Tablespace Information ..........................................................................................31

Hands-On Lab 2.2 Manage Tablespaces and Storage.................................................................................38

Unit 3 Table and Index Maintenance ...............................................................................................................43

Hands-On Lab 3 Automatic Table Maintenance .........................................................................................43

Unit 4 Log File Management .............................................................................................................................50

Hands-On Lab 4.1 Log File Management ....................................................................................................50

Hands-On Lab 4.2 Enable Archival Logging .................................................................................................51

Unit 6 Backup and Recovery .............................................................................................................................62

Hands-On Lab 6.1 Backup and Restore .......................................................................................................62

Hands-On Lab 6.2 Redirected Restore ........................................................................................................70

Unit 7 Performance Monitoring and Tuning ....................................................................................................74

Hands-On Lab 7.1 Health Check ..................................................................................................................74

Hands-On Lab 7.2 SQL Cache Analysis.........................................................................................................76

Hands-On Lab 7.3 ST05 Trace ......................................................................................................................80

Unit 8 Problem Analysis ....................................................................................................................................86

Hands-On Lab 8.1 db2look, db2top, INSPECT, db2support .......................................................................86

Page 2/92
Hands-On Lab 8.2 Lock-wait Scenario .........................................................................................................88

Page 3/92
VMWare Image

To run the hands-on labs a VMware image is provided on the classroom computers.

The image contains the following software:

SUSE Linux Enterprise Server 11 SP1 (x86_64)


IBM DB2 for Linux, UNIX, Windows 10.1
SAP NetWeaver 7.3 (SAP Basis SP8)

The host name of the image is n4shost.[sapdemo.com].

On the Linux VMware an SAP system with the name (<SAPSID>) N4S is installed. It is running
on a DB2 LUW database with the database name (<DBSID>) N4S.

The following table lists users and passwords for the VMware image:

User Password
root passw0rd
db2n4s passw0rd
n4sadm passw0rd
sapn4s passw0rd

The following table lists users and passwords to log on to the SAP system N4S (client 001):

User Password
bwuser passw0rd
sap* passw0rd

Page 4/92
Hands-On Labs

The objective of each hands-on lab is described in this document. Each lab is aligned with
the topics covered within the boot camp.

Each hands-on lab consists of multiple exercises and each exercise contains at least one
task or question.

The questions are followed by hints that help to solve the exercise.

Page 5/92
Unit 1 Basics

Hands-On Lab 1.1 Accessing DB2

Objective:

Get familiar with the lab environment

Learn to work with the DB2 command line processor (CLP) and SAP transaction DBA Cockpit
to access the DB2 database

Questions:

(1) Which DB2 10.1 Fix Pack is installed on the system?

(2) How many applications are connected against database N4S? Use both CLP and DBA
Cockpit to get this information. How is the output different provided by CLP and SAP?

(3) What is the command syntax for the GET SNAPSHOT command? And what is the
meaning of SQL code SQL1024?

Hints:

Log on to n4shost as user root and open a terminal window (click on GNOME Terminal
icon). In the Terminal window, switch to user db2n4s (with command: su db2n4s)

Page 6/92
IMAGE 1 - GNOME TERMINAL

Open the SAP Logon on the Windows host and select entry N4S. Logon to SAP with user
BWUSER in client 001

IMAGE 2 SAP LOGON

Page 7/92
Open SAP transaction code DBA Cockpit (alternatively, use ST04, DB02) to access the
DBA Cockpit. In the transaction, log on to the WebDynpro (Image 4).

IMAGE 3 ENTER SAP TRANSACTION CODE

IMAGE 4 ENTER CREDENTIALS IN WEBDYNPRO

Page 8/92
On the Linux Terminal window, enter the following commands (as user db2n4s):

o To show the DB2 version, release and Fix Pack level of your DB2 instance use the
command db2level.

o To list all the connection applications on the DB2 system, use this CLP command:
db2 list applications
To list all the applications including the internal DB2 engine connections (like the
db2stmm) on the DB2 system, use this CLP command:
db2 list applications show detail

o The CLP online help can be used to see the command syntax for a DB2 command as
well as the description of a SQL message:
db2 \? backup
db2 \? SQL1024

In the DBA Cockpit, select database N4S, then Performance Snapshots


Applications
Click on "Database
N4S"

IMAGE 5 DBA COCKPIT: SELECT DATABASE N4S

Page 9/92
IMAGE 6 DBA COCKPIT: APPLICATION SNAPSHOT

Page 10/92
Hands-On Lab 1.2 Database Objects

Objective:

Understand and access the different DB2 objects on the N4S system: Instance, database,
database directory, SAP schema.

Understand the directory structure of a DB2 SAP installation

Run SQL commands to get information about the tables in the database

Use SAP to find the largest tables in the database

Questions:

(1) What is the name of the DB2 instance?

(2) Where is the DB2 instance home and which user is the DB2 instance owner?

(3) What is the database name and where is the database directory?

(4) What schema is used by the SAP system?

(5) Whats under the directory /db2/<DBSID>?

(6) How to connect to database? How to disconnect again?

(7) What is the SAP kernel level?

(8) How many tables are in the entire database? And how many tables belong to the SAP
ABAP stack?

(9) What are the largest tables in the database?

(10) Can you run a SQL command from within SAP DBA Cockpit?

Page 11/92
Hints:

On the Terminal window, work as user db2n4s

o To identify the DB2 instance name, run:


echo $DB2INSTANCE

o The DB2 instance home can be seen with:


echo $INSTHOME

o The owner of the current DB2 instance can be queried with:


db2 "values auth_get_instance_authid()"

o List the database directory to identify the catalogued databases:


db2 list db directory

o Find the database directory for database N4S and list the contents:
db2 list db directory on /db2/N4S
ls /db2/N4S/db2n4s/NODE0000/SQL00001

o Identify the SAP schema:


echo $dbs_db6_schema

o List the contents of /db2/N4S


ls l /db2/N4S

o Connect to the database N4S:


db2 connect to N4S
Close the connection and the background process:
db2 terminate

o Query the SAP table SVERS to see the SAP kernel release of system N4S:
db2 "select * from sapn4s.svers"

o Query the DB2 system catalog to get the total number of tables in the database as
well as the number of tables that belong to the SAP schema:
db2 "select count(*) from syscat.tables where type='T'"
db2 "select count(*) from syscat.tables where tabschema =
'SAPN4S' and type='T'"

Logon to SAP transaction DBA Cockpit (as user BWUSER): In the DBA Cockpit, select
database N4S, then Space Tables and Index Top Space Consumers and find the

Page 12/92
largest tables in the database.
Please note depending on the uptime of the database, the transaction might not
return any data if the SAP collector did not run already.

IMAGE 7 DBA COCKPIT: SPACE ANALYSIS

Choose Time Frame


Since DB Start

IMAGE 8 DBA COCKPIT: TOP SPACE CONSUMERS

In the DBA Cockpit, go to Diagnostics SQL Commands to execute SQL queries from
inside the SAP system

Page 13/92
IMAGE 9 DBA COCKPIT: CLP COMMANDS

IMAGE 10 DBA COCKPIT: CLP COMMANDS EXAMPLE

Page 14/92
Hands-On Lab 1.3 Security

Objective:

Understand the security settings on the N4S system.

Questions:

(1) Where is the password file for SAP ABAP system users? What is the content of the file?

(2) What are the instance level authorities, and which OS groups are assigned to them?
Which OS users have which authorities on DB2 instance level?

(3) What is the authentication type of the database?

(4) Does the user sapn4s hold DBADM authority on the database N4S?

(5) Can you get some of the information from the DBA Cockpit?

Hints:

Work as user n4sadm for this exercise (either open a new Terminal window or switch to
user db2n4s using the command: su n4sadm)

o The password file dscdb6.conf for the SAP ABAP engine is located in the global
directory of the SAP instance:
ls l /usr/sap/N4S/SYS/global/dscdb6.conf

o The password file will contain two entries for user n4sadm and sapn4s:
cat /usr/sap/N4S/SYS/global/dscdb6.conf

o To see the authorities groups of instance db2n4s, issue:


db2 get dbm cfg | grep GROUP

Page 15/92
o To map the DB2 authorities groups with the groups on the operating system, look at
the /etc/group and /etc/password files:
cat /etc/group
cat /etc/passwd

o The authentication type of the database is set in the database configuration file:
db2 get db cfg for n4s | grep AUTHENTICATION

o Query the AUTH_LIST_AUTHORITIES_FOR_AUTHID table function to see the


authorities of the sapn4s user:
SELECT varchar(AUTHORITY,25) User, D_USER, D_GROUP,
D_PUBLIC FROM TABLE
(SYSPROC.AUTH_LIST_AUTHORITIES_FOR_AUTHID ('SAPN4S', 'U')
) AS T ORDER BY AUTHORITY;

While you cannot check the OS security configuration settings from within the SAP
transaction, you can use the DBA Cockpit to see the configuration of the database
manager and the database:

IMAGE 11 DBA COCKPIT: DBM CFG

Page 16/92
IMAGE 12 DBA COCKPIT: AUTHORITY GROUPS

Page 17/92
Hands-On Lab 1.4 Communication

Objective:

Understand the communication settings of the DB2 instance and how the SAP application
connects to DB2.

Questions:

(1) Does the DB2 instance have a node directory?

(2) Is TCP/IP communication enabled on the DB2N4S instance? On which port is the
instance listening?

(3) How does the SAP application connect to the database via TCP/IP or IPC? Where is the
configuration file for the SAP application servers?

(4) Can you get some of the information also through the DBA Cockpit?

Hints:

Work in the Terminal window as user db2n4s. Use the following commands to get the
required information:

o To list the node directory on the instance, issue:


db2 list node directory
This will be empty since all new SAP applications will connect not via a traditional
DB2 client but via the CLI driver (aka thin client)

o To see if the TCP/IP communication is turned on, use:


db2set all | grep DB2COMM

o The TCP/IP port for the communication with the instance is set in the instance
configuration:
db2 get dbm cfg | grep SVCENAME

Page 18/92
The service name sapdb2N4S is translated in the Linux system through the
/etc/services file:
cat /etc/services | grep sapdb2N4S

o Run a db2 list applications again.


The column Application Id will contain an IP address for all SAP connections
signifying that this is a remote connection (local connections will have an entry
starting with *LOCAL.

Switch to user n4sadm in the Terminal window for the next commands:

o To check if the SAP system is using the CLI driver or the traditional DB2 client you
could run
R3trans d
Open the trans.log file created by R3trans and search for driver.

o The configuration for the communication between SAP application servers and DB2
database via CLI driver is located in the global SAP directory:
cat /sapmnt/N4S/global/db6/db2cli.ini

While you cannot check the OS communication configuration settings from within the
SAP transaction, you can use the DBA Cockpit to see the configuration of the database
manager and the DB2 Registry:

IMAGE 13 DBA COCKPIT: SVCENAME SETTING

Page 19/92
IMAGE 14 DBA COCKPIT: REGISTRY SETTINGS

Page 20/92
Hands-On Lab 1.5 DB2 Process Model

Objective:

Understand the DB2 process model and list the different DB2 threads (EDUs)

Learn how different settings in the instance configuration can influence the number of DB2
agents

Questions:

(1) List all threads of the DB2 engine. How many DB2 TCP/IP communication managers do
you see? What is the PID of the db2sysc process?

(2) How many db2agents are on the system?

(3) How many DB2 agents will be created initially and how many DB2 agents will be pooled?

(4) How many threads defined for reading and writing of pages from/to buffer pool? Can
you influence the number of these threads?

(5) In the N4S SAP system, how many work processes are defined? Do you see DB2 threads
corresponding to each SAP work process?

(6) Can you use an application to find the process ID of the SAP disp+work process for a
given DB2 connection?

Hints:

Work in the Terminal window as user db2n4s. Use the following commands to get the
required information:

o To list all threads (EDUs) of the DB2 engine, use the db2pd edus command.

Page 21/92
o The output of db2pd edus will also provide you with the PID of the db2sysc, the
number of DB2 TCP/IP communication managers (search for db2tcpcm) and the
db2agents

o The database manager parameter NUM_INITAGENTS defines the number of initial


db2agents created during db2start. The database manager parameter
NUM_POOLAGENTS defines the number of idle db2agents that will be kept in the
agent pool for future use by an application.

o Look for the db2pclnr (page cleaner) and db2pfchr (prefetcher) EDUs. The number
of cleaners and prefetchers are determined by database configuration parameters
NUM_IOCLEANERS and NUM_IOSERVERS.

Use the SAP system for the next part.

Transaction SM50 will provide you with a list of SAP work processes

In the DBA Cockpit, go to Performance Snapshots Applications. Make sure to


select all Application States to get the complete information:

Select all states

IMAGE 15 DBA COCKPIT: LIST ALL CONNECTIONS

Double-click on one of the application handles to access the application snapshot:

Page 22/92
Thread ID of the PID of the disp+work
db2agent process

IMAGE 16 DBA COCKPIT: APPLICATION SNAPSHOT

You can map the PID using ps ef | grep <PID> and the TID using db2pd edus |grep
<TID>

Page 23/92
Hands-On Lab 1.6 Configuration

Objective:

Learn how to get configuration settings of the DB2 database and instance

Understand how you can change parameters using the DBA Cockpit

Questions:

(1) What are the settings of the DB2 registry? Which parameter influences almost all
settings in the registry?

(2) Using DB2 CLP: What is the current (memory) value of the database configuration
parameter SORTHEAP?

(3) Using DBA Cockpit: What is the path for the DB2 diagnostic information (DIAGPATH)?

(4) Increase the size of the catalog cache of the database using the DBA Cockpit. Is this
change immediately propagated to the database? How about a change of the log buffer
size?

Hints:

Work in the Terminal window as user db2n4s. Use the following commands to get the
required information:

o To list the DB2 registry, use:


db2set -all
You will see that almost all settings are influenced by the parameter
DB2_WORKLOAD.

o To see the current value of the database configuration parameter SORTHEAP, issue
the following commands:
db2 connect

Page 24/92
db2 get db cfg for n4s show detail
db2 terminate
Alternatively, you can use db2pd to get the same information without the need to
connect to the database:
db2pd db n4s dbcfg

Use the DBA Cockpit for the next steps.

o The DIAGPATH is set on the database manager configuration:

IMAGE 17 DBA COCKPIT: DIAGPATH

o The size of the catalog cache is determined by database parameter


CATALOGCACHE_SZ:

Page 25/92
Click on "Change

IMAGE 18 DBA COCKPIT: CATALOG CACHE

IMAGE 19 DBA COCKPIT: CHANGING CATALOG CACHE

Page 26/92
IMAGE 20 DBA COCKPIT: CATALOG CACHE CHANGED ONLINE

o The size of the log buffer is determined by database parameter LOGBUFSZ. It is one
of the few parameters in the database configuration that cannot be changed online
(i.e. it requires a restart of the DB2 database to activate the change). After the
change in the DBA Cockpit you will notice the new value is listed as Deferred
Value.

IMAGE 21 DBA COCKPIT: CHANGE OF LOGBUFSZ

Page 27/92
Hands-On Lab 1.7 Memory Model

Objective:

Understand the DB2 memory model and which commands to use to see the overall memory
usage of the DB2 instance.

See which parameters are influenced by the self-tuning memory manager (STMM)

Questions:

(1) How much memory is the DB2 instance allowed to use? What is the high-water mark
usage?

(2) Can you increase the memory usage limit for DB2 online?

(3) How much memory is currently used by the DB2 database N4S? Which memory sets are
using the most of the database memory?

(4) Using DBA Cockpit: Is STMM enabled on the database?

(5) How many buffer pools does the N4S database have and what is the size?

Hints:

Work in the Terminal window as user db2n4s.

o Use command db2pd dbptnmem to get the required information about the
memory limit as well as the HWM of the DB2 partition.

o Yes, the instance parameter INSTANCE_MEMORY can be changed online, for


example:
db2 attach to db2n4s
db2 update dbm cfg using instance_memory 275000

Page 28/92
db2 terminate
Double-check with db2pd dbmcfg | grep INSTANCE

o The memory usage of the DB2 database can be seen in the output of db2pd
dbptnmem (search for DB-N4S).

o To see which memory sets are using the most memory inside database memory,
you can use the db2pd db n4s memsets command. Alternatively, you can use
db2top m

IMAGE 22 SCREENSHOT OF DB2TOP WITH MEMORY OPTION

Use the DBA Cockpit for the next steps. Using Configuration Database will show
that STMM is enabled on the database.

The defined buffer pools can be seen with Configuration Buffer Pools. The
database N4S has only one user buffer pool; the size is tuned by STMM:

Page 29/92
IMAGE 23 DBA COCKPIT: BUFFER POOLS

Page 30/92
Unit 2 Storage Management

Hands-On Lab 2.1 Get Tablespace Information

Objective:

Learn how to use DB2 CLP and DBA Cockpit to access information about the DB2 tablespaces
and containers.

Use the DBA Cockpit to add a new tablespace to the database.

Questions:

(1) Using CLP: Which SQL can you use list all tablespaces and see the extent size in the N4S
database? Is there an alternative command to access the information?

(2) Using CLP: Which containers are defined for tablespace N4S#FACTD?

(3) Using CLP: Which information is provided in the tablespace snapshot? Can you see the
MAXSIZE of tablespace SYSCATSPACE?

(4) Using DBA Cockpit can you see whether any tablespace in N4S is not using automatic
storage management?

(5) What is the largest tablespace in the database? What is the total size of the database?

(6) How many storage group paths are defined on database N4S?

(7) Can you increase the size of tablespace N4S#FACTD? Create a new tablespace
N4S#MYTS as a DMS tablespace can you increase the size for this tablespace?

Page 31/92
Hints:

Work in the Terminal window as user db2n4s. Use the following commands to get the
required information:

o You can query the MON_TBSP_UTILIZATION view to access information about the
tablespaces of the database:
db2 "select substr(tbsp_name,1,16) as tbsp_name, tbsp_type,
substr(tbsp_page_size,1,6) as page_size, substr(tbsp_extent_size,1,2) as
extent_size, tbsp_utilization_percent from sysibmadm.mon_tbsp_utilization"
Alternatively, you could use the db2pd db n4s tablespaces command to retrieve
similar information

o To list all containers for a given tablespace you can query the
MON_GET_CONTAINER table function:
db2 "select tbsp_name, container_name, fs_total_size, fs_used_size from
table(mon_get_container('N4S#FACTD',-1))"

o The snapshot for the tablespaces will list the tablespace parameters like MAXSIZE:
db2 get snapshot for tablespaces on n4s | more
and search for Maximum tablespace size

Work in the DBA Cockpit for the next steps.

o Using Space Tablespaces we see that all tablespaces in N4S are using
automatic storage:

IMAGE 24 DBA COCKPIT: TABLESPACES

Page 32/92
o You can find the largest tablespace by sorting the output by KB Total

o Using Space Database you can see the size of the database (and also the
growth rates):

IMAGE 25 DBA COCKPIT: DATABASE SIZE

o Using Space Automatic Storage we see that database N4S has one storage
group IBMSTOGROUP with four storage paths:

IMAGE 26 DBA COCKPIT: STORAGE GROUPS

o Since tablespace N4S#FACTD is managed by automatic storage, you cannot define


the size of the tablespace; you could only change parameters like increase size or
maximum size:

Page 33/92
Click on Change

IMAGE 27 DBA COCKPIT: CHANGE A TABLESPACE

IMAGE 28 DBA COCKPIT - CHANGE TABLESPACE PARAMETERS

o You can use the DBA Cockpit to create a new tablespace N4S#MYTS on the
database. If you choose managed by database you have to provide the name and
size of the tablespace containers. Once created, you can change the size of the
tablespace by adding containers or change the size of the existing one.

Page 34/92
o To add a tablespace, just click on the Add Tablespace button in the tablespace
overview in DBA Cockpit. A popup window similar to the following example will
appear:

Choose DMS

IMAGE 29 DBA COCKPIT: CREATING A DMS TABLESPACE

Fill out the necessary fields and make sure to choose Space Management By
Database. Click on Execute to create the tablespace. It will be listed on the
DMS/SMS Tablespaces tab now:

Page 35/92
IMAGE 30 DBA COCKPIT: DMS/SMS TABLESPACES

When you click on Change for this tablespace you will notice that you have more
options to fill out in the popup window:

IMAGE 31 DBA COCKPIT: CHANGE ATTRIBUTES OF A DMS TABLESPACE

Once finished, you can drop the tablespace N4S#MYTS again:

Page 36/92
IMAGE 32 DBA COCKPIT: DELETE A TABLESPACE

Page 37/92
Hands-On Lab 2.2 Manage Tablespaces and Storage

Objective:

Learn how to add a storage path to a storage group.

Use the DBA Cockpit to reduce the high-water mark of a tablespace.

Questions:

(1) How do you add a storage path to an existing storage group? Will the new path be used
immediately?

(2) Can you easily reduce the high-water mark of a DB2 tablespace?

Hints:

As user db2n4s issue the following command:


mkdir /db2/N4S/sapdata5

In the DBA Cockpit, switch back to the traditional SAPGUI version by pressing F5. In the
SAPGUI version of transaction DB02 go to Space Automatic Storage:

Page 38/92
IMAGE 33 DB02: AUTOMATIC STORAGE

o Add a new storage path /db2/N4S/sapdata5 to the IBMSTOGROUP storage group


and click on Save:

IMAGE 34 DB02: CHANGE AUTOMATIC STORAGE

o The storage group will now show five storage paths. You will see that the new
storage path is created but Not_in_use:

Page 39/92
IMAGE 35 DB02: AUTOMATIC STORAGE AFTER CHANGE

o Go back to the WebDynpro version of the DBA Cockpit by entering transaction code
/ndb02

o A new storage path will only be used by DB2 once needed, i.e. because the other
storage paths are full and DB2 cannot grow containers any further. You can also
force DB2 to use a new storage path by rebalancing a tablespace.

o Go to Space Tablespaces and start a Rebalance Process for a small tablespace


like N4S#CLUD:

IMAGE 36 DBA COCKPIT: START REBALANCE

Click on Yes in the pop-up window:

Page 40/92
IMAGE 37 START REBALANCE OPERATION

o You can monitor the progress by running a tail on the db2diag.log as db2n4s
user run db2diag f. You will see messages like the following example:

IMAGE 38 DB2DIAG.LOG - ADM6062I MESSAGE

o In the DBA Cockpit you will notice that the N4S#CLUI tablespace has now five
containers; also the storage path will now be listed as In Use:

Page 41/92
IMAGE 39 DBA COCKPIT: TABLESPACE WITH 5 CONTAINERS

IMAGE 40 DBA COCKPIT: STORAGE GROUP WITH 5 PATHS

Page 42/92
Unit 3 Table and Index Maintenance

Hands-On Lab 3 Automatic Table Maintenance

Objective:

Learn how to monitor and influence the automatic maintenance feature of DB2.

See how you can analyze single tables in the DBA Cockpit to get information about statistics,
table structure or compression state.

Use the DBA Cockpit to define a new maintenance policy for REORG.

Questions:

(1) Can you see the queue of the automatic table maintenance of the DB2 database?

(2) Does the N4S SAP database use the virtual table functionality?

(3) When was the last RUNSTATS on table SAPN4S./BIC/AODSBENCH00 performed? Is


compression enabled for this table? How many indexes does the table have?

(4) Does the database N4S have tables marked as VOLATILE? Do they have current
statistics?

(5) Is an automatic REORG policy implemented on database N4S? Can you see the policy on
CLP level?

Hints:

Use the DBA Cockpit for this exercise

Page 43/92
o In DB2 10 you can see the queue for the automatic maintenance feature of DB2. Go
to Space Tables and Indexes Automatic Maintenance Queue / RTS
Requests to see if there are any outstanding requests for RUNSTATS or REORG:

IMAGE 41 DBA COCKPIT: ATM QUEUE

o To get information about a specific table, you can go to Space Single Table
Analysis. Table SAPN4S./BIC/AODSBENCH00 has one index and is compressed using
static (row) compression:

Page 44/92
IMAGE 42 DBA COCKPIT: SINGLE TABLE ANALYSIS

o Database N4S was installed using the virtual table functionality. You can see all
virtual tables with Space Tables and Indexes Virtual Tables

Page 45/92
IMAGE 43 DBA COCKPIT: VIRTUAL TABLES

o As every SAP DB2 database, N4S has a couple of tables that are marked as
volatile. These tables will not be considered by automatic RUNSTATS. The DBA
Cockpit will list these tables under Configuration Special Tables Regarding
RUNSTATS:

IMAGE 44 DBA COCKPIT - VOLATILE TABLES

o The automatic maintenance in DB2 is controlled by so-called policies. You can


maintain them in the DBA Cockpit via Configuration Automatic Maintenance.

Page 46/92
To configure the policy for the automatic REORG go to the proper tab and click on
Configure:

IMAGE 45 DBA COCKPIT: CONFIGURE AUTOMATIC REORG

o In the pop-up window logon again as BWUSER; make sure to uncheck the Cancel all
existing logons

Page 47/92
IMAGE 46 ATM POLICY POP-UP WINDOW

o In the wizard make sure to implement the SAP Default policies for both automatic
RUNSTATS and REORG. Do not define an offline maintenance window.

Page 48/92
IMAGE 47 CONFIGURE MAINTENANCE WIZARD

o On DB2 CLP level, you can double-check the reorg policy by running the following
command as user db2n4s:
db2 "call sysproc.automaint_get_policyfile('AUTO_REORG',
'policy.xml')"
This will create a XML file in /db2/db2n4s/sqllib/tmp. The file could be adapted to
your specific needs and used as a new policy by using:
db2 "call sysproc.automaint_set_policyfile('AUTO_REORG',
'policy_new.xml')"

Page 49/92
Unit 4 Log File Management

Hands-On Lab 4.1 Log File Management

Objective:

Understand the current settings of logging in the N4S database.

Questions:

(1) How many primary and secondary logs are defined for the N4S database?

(2) Looking at your configuration, would you be able to recover the table at a specific point
in time?

Hints:

You can use either the DB2 CLP or the DBA Cockpit to see the configuration of database
N4S.

o To check the settings for LOGPRIMARY and LOGSECOND on DB2 CLP use:
db2 get db cfg for n4s | grep Number | grep LOG

o To check the settings for the log archiving on database N4S, run:
db2 get db cfg for n4s | grep LOGARCHMETH
Database N4S is running in circular logging, as both parameters are set to OFF;
therefore only offline backups are possible and the database does not support a
point in time recovery

Page 50/92
Hands-On Lab 4.2 Enable Archival Logging

Objective:

Learn how to catalog an additional database in DBA Cockpit.

Turn on archival logging on database SAMPLE.

Tasks:

(1) We will use database SAMPLE for this hands-on lab. Catalog the database on both the
DB2 database directory as well as in the SAP DBA Cockpit

(2) Configure database SAMPLE to archive log files to disk

Hints:

First, on DB2 CLP, check whether the SAMPLE database is already cataloged in the
database directory. The output of db2 list db directory should like this:

Page 51/92
IMAGE 48 OUTPUT OF DB2 LIST DB DIRECTORY

If the database SAMPLE is not already catalogued, issue a


db2 catalog db sample on /db2/SAMPLE
db2 terminate

Activate the SAMPLE database and invoke the stored procedure db2sap:
db2 activate db sample
db2 connect to sample
db2 invoke db2sap
db2 terminate

Create a log_archive directory:


mkdir /db2/SAMPLE/log_archive

In the DBA Cockpit, go to the System Landscape tab and click on Add:

Page 52/92
IMAGE 49 DBA COCKPIT: SYSTEM LANDSCAPE

In the Integrate a System wizard, follow these steps:

IMAGE 50 INTEGRATE A SYSTEM 1

Click Continue

Page 53/92
IMAGE 51 INTEGRATE A SYSTEM 2

Enter SAMPLE as the database name; choose Remote Database Connection

Page 54/92
IMAGE 52 INTEGRATE A SYSTEM 3

In this screen, enter exactly this information:

Database Connection name: SAMPLE


User name: db2n4s
Password: passw0rd
Confirm: passw0rd
Database Host: n4shost.sapdemo.com
Database Name: SAMPLE
Port Number: sapdb2N4S
Schema Name: DB2N4S

A Test connection should be successful.

Page 55/92
IMAGE 53 INTEGRATE A SYSTEM 4

Select all three monitoring settings.

Page 56/92
IMAGE 54 INTEGRATE A SYSTEM 5

Click on Execute and ignore the following warning:

Page 57/92
IMAGE 55 INTEGRATE A SYSTEM 6

Back in the System Landscape click on Refresh

IMAGE 56 SYSTEM LANDSCAPE WITH SAMPLE DATABASE 1

Now you will see SAMPLE listed in the list; click on the SAMPLE entry; you will now
also see an entry in the database overview on the left (if not, click Refresh):

Page 58/92
IMAGE 57 SYSTEM LANDSCAPE WITH SAMPLE DATABASE 2

Click on the database entry for SAMPLE on the left side. This will connect the DBA
Cockpit with the SAMPLE database. You will now work with Database SAMPLE:

IMAGE 58 DBA COCKPIT - CONNECTED TO SAMPLE

Once connected to SAMPLE, change the configuration parameter ( Configuration


Database) LOGARCHMETH1 to DISK:/db2/SAMPLE/log_archive

Page 59/92
IMAGE 59 DBA COCKPIT: CHANGE OF LOGARCHMETH1

Please note: Due to a bug in the DBA Cockpit you might not be able to execute the
above command in the GUI. In this case, please, go to CLP and issue the following
command:
db2 update db cfg for sample using logarchmeth1
disk:/db2/SAMPLE/log_archive

Exit the DBA Cockpit by clicking on the yellow arrow (or press Shift+F3)

Go back to the Terminal window and continue as user db2n4s on the DB2 command
line.

o First, make sure no one is connected anymore to SAMPLE:


db2 list applications for db sample

o If there is still a connection, force the connection with:


db2 "force application (<appl. handle>)"

o Now, deactivate the database SAMPLE:


db2 deactivate db sample

o Try to connect now:


db2 connect to sample
This should fail with a message SQL1116N at this point saying that the database is
in BACKUP PENDING state.

Page 60/92
o You need to take a full offline backup to get the database to a normal state. And
you have to do this through CLP:
First, create your backup directory (mkdir /db2/SAMPLE/backup).
Now start the offline backup with
db2 backup db sample to /db2/SAMPLE/backup

o Once the backup has finished successfully you can now activate the database again:
db2 activate db SAMPLE

o Now, force a log switch on the database by running:


db2 archive log for db sample
Running db2diag f will show that the log file archive operation was successful.

Page 61/92
Unit 6 Backup and Recovery

Hands-On Lab 6.1 Backup and Restore

Objective:

Use the DBA Cockpit to schedule online database backups.

Learn how to use the DB2 RECOVER command to restore and roll-forward a database.

See how a new log chain is created after a restore operation

Tasks:

(1) Use the DBA Cockpit (DB13) to schedule an online backup of the SAMPLE database and
check that the backup finishes successfully.

(2) Connect to database SAMPLE on CLP. Run the script /storage/scripts/pit_recovery.clp.


This will update table EMPLOYEE in database SAMPLE. Record all timestamps of the
updates.

(3) Disconnect from database sample.

(4) Check the log_archive directory, notice that you have a directory created for your log
chains.

(5) Run db2ckbkp on the latest backup image to confirm that it is usable for recovery.

(6) Use the RECOVER command to restore the database to the point of the second update
statement from step 2.

(7) Connect to the database SAMPLE and query the EMPLOYEE table.

(8) Check the log_archive directory again. Notice that a new log chain directory is created.

Page 62/92
Hints:

Make sure to use the SAMPLE database for this exercise. In the DBA Cockpit, go to the
DBA Planning Calendar ( Jobs DBA Planning Calendar) or enter transaction code
DB13 directly:

IMAGE 60 DB13 FOR DATABASE SAMPLE

o Start the Plan a New Action wizard and follow the steps in the pop-up window. In
step 2, choose Database Backup to Device and Start immediately:

Page 63/92
IMAGE 61 DB13 - SCHEDULE ONLINE BACKUP

o In Step 3, leave all options as they are and choose /db2/SAMPLE/backup as the
backup location.

Page 64/92
IMAGE 62 DB13 - BACKUP DIRECTORY

o Execute the backup and finish the wizard. Back in the calendar you can monitor the
backup operation (alternatively, you can go to the DB2 CLP and run db2pd
util).

o Once the backup has finished, the Planning Calendar should look similar to this
screenshot:

Page 65/92
IMAGE 63 DB13 - SUCCESSFUL BACKUP

Now logon as user db2n4s and work on the DB2 command line. Connect to the SAMPLE
database (db2 connect to sample). Run the script /db2/storage/scripts/pit_reocvery.clp:
db2 -tvf /storage/scripts/pit_recovery.clp
This script will update the EMPLOYEE table in the database. Please note the timestamp
after second update.

Page 66/92
IMAGE 64 CLP: RUNNING PIT_RECOVERY.CLP SCRIPT

o Close your connection and deactivate the SAMPLE database:


db2 terminate

o Probably the DBA Cockpit is still connected and needs to be forced off of the
database with the FORCE APPLICATION command:

Page 67/92
IMAGE 65 CLP: FORCE APPLICATION

o Check the log_archive directory that you have configured in lab 4.2. You will notice
that a directory C0000000 was created automatically for log chain 0:
ls
/db2/SAMPLE/log_archive/db2n4s/SAMPLE/NODE0000/LOGSTREAM0
000

o Run the db2ckbkp command on the latest backup image to confirm that it is usable
for recovery:
ls ltr /db2/SAMPLE/backup/
db2ckbkp /db2/SAMPLE/backup/<most recent backup filename>

IMAGE 66 CLP: DBCKBKP

o Now start the RECOVER command. Make sure to roll forward to the point in time
returned after the second update statement from the pit_recovery.clp script (the
timestamp has the format yyyy-mm-dd-hh.mm.ss.nnnnnn).
db2 "recover db sample to <timestamp taken after second
update statement>"

Page 68/92
o Once the RECOVER command has finished successfully, activate and connect to the
SAMPLE database:
db2 activate db sample
db2 connect to sample
When you query the EMPLOYEE table, you will notice that only the first two updates
were recovered (as intended by providing the point in time):
db2 select empno, firstnme from employee

o Check the log_archive directory again. Notice that a new log chain directory was
created:
ls
/db2/db2n4s/SAMPLE/log_archive/db2n4s/SAMPLE/NODE0000/LOG
STREAM0000

Page 69/92
Hands-On Lab 6.2 Redirected Restore

Objective:

Learn how to create a redirected restore script in DB2.

Perform a redirected restore to change the layout (location of a container) of a tablespace.

Tasks/ Questions:

(1) Use the DBA Cockpit to create a new DMS tablespace MYTS in the SAMPLE database.

(2) Create a redirected restore script for the SAMPLE database. Which tools can you use to
create this script?

(3) Change the location of the container of MYTS tablespace in the redirected restore script.
Why is MYTS the only tablespace where you can change the container layout?

(4) Perform a redirected restore using the RESTORE and ROLLFORWARD commands.

Hints:

Use the DBA Cockpit to create a new tablespace MYTS in the SAMPLE database (
Space Tablespaces Add Tablespace
Enter the tablespace name MYTS and Space Management By Database and leave the
other options unchanged.
Click on the Add Container button and enter the following information for the
tablespace container:
Name: /db2/db2n4s/SAMPLE/db2n4s/NODE0000/SAMPLE/MYTS/C0000000.LRG
Size: 4000 KB

Page 70/92
IMAGE 67 DBA COCKPIT: ADD TABLESPACE MYTS

Now, log on as user db2n4s on a Linux Terminal and create a redirected restore script
using the brdb6brt command:
brdb6brt -s SAMPLE -bm RETRIEVE

o The brdb6brt command will write an output file called SAMPLE_NODE0000.scr in


the current directory.

o Open the SAMPLE_NODE0000.scr file using vi (or any other editor) and look at the
different options. Search for the line containing the information for tablespace
MYTS. Change the container path from
/db2/db2n4s/SAMPLE/db2n4s/NODE0000/SAMPLE/MYTS/C0000000.LRG to
/db2/db2n4s/SAMPLE/db2n4s/NODE0000/SAMPLE/NEWTS/C0000000.LRG

Page 71/92
IMAGE 68 EDITING THE REDIRECTED RESTORE SCRIPT

o After saving the change, start the redirected restore:


db2 tvf SAMPLE_NODE0000.scr

o Once the RESTORE has finished, perform a ROLLFORWARD to end of logs and stop
the rollforward operation afterwards:
db2 rollforward db sample to end of logs and complete

o Now you can activate the database SAMPLE again


db2 activate db sample

o Run the db2pd command to verify the new location of tablespace MYTS:
db2pd d sample tab[lespaces]

o Now you can uncatalog the database SAMPLE from the DBA Cockpit in the System
Landscape (you have to disconnect from SAMPLE first, otherwise the Delete
System Entry will not work):

Page 72/92
IMAGE 69 DBA COCKPIT: UNCATALOG SAMPLE DATABASE

o Also, uncatalog the SAMPLE database from the database directory:


db2 terminate
db2 deactivate db sample
db2 uncatalog db sample

Page 73/92
Unit 7 Performance Monitoring and Tuning

Hands-On Lab 7.1 Health Check

Objective:

Learn how to perform a quick health check of your SAP database.

Use the DBA Cockpit to monitor key performance indicators in DB2 SAP environments.

Questions:

(1) How good is the quality of the buffer pool similar values for index and data?

(2) Which I/O times are reported for asynchronous I/O operations?

(3) Are the package cache and catalog cache sized sufficiently?

(4) Is the lock list large enough for the workload?

(5) How about the sort quality?

(6) Does the database have enough log space available? How about logging I/O?

Hints:

Use the DBA Cockpit for this exercise ( Performance Snapshots Database).
Choose Since DB Start as the Time Frame. Go through the different tabs to check
the KPIs of database N4S.

Page 74/92
Page 75/92
Hands-On Lab 7.2 SQL Cache Analysis

Objective:

Learn how to use the SQL analysis in the DBA Cockpit.

Understand how to use the EXPLAIN facility to see SQL access plans.

See how you can use the index advisor to get recommendations on additional indexes.

Tasks/ Questions:

(1) What is the most expensive statement in the SQL cache of the N4S database in terms of
overall runtime (Coord. Statement Exec. Time)?

(2) Which statement is the most expensive in average (Avg. Coord. Stmt. Exec. Time)? Is
this statement executed often?

(3) Highlight a query that is not a DB2 system catalog query and explain the statement.

(4) Run the Index Advisor for a single statement.

Hints:

Use the DBA Cockpit ( Performance Snapshots SQL Cache) for this exercise.

o By default, the statements are sorted by the Coord. Statement Exec. Time (overall
execution time for the statement). By clicking on the column Avg. Coord. Stmt.
Exec. Time) you can find the most expensive statement per execution.

Page 76/92
IMAGE 70 DBA COCKPIT: SQL CACHE SNAPSHOT

o Highlight a query that is not a DB2 system catalog query and use the Explain to
see the access plan.

IMAGE 71 DBA COCKPIT: EXPLAIN

o A pop-up window opens with the access plan.

Page 77/92
IMAGE 72 EXPLAIN ACCESS PLAN

o Run the Index Advisor for the statement.

Page 78/92
IMAGE 73 INDEX ADVISOR

o The index advisor will return with a list of recommended indexes. You can run
another EXPLAIN to see the influence of recommended indexes.

Page 79/92
Hands-On Lab 7.3 ST05 Trace

Objective:

Learn how to execute a SQL Trace from ST05, and identify inefficient application design.

Tasks/ Questions:

(1) Run ABAP reports ZH9_QUERY_ANALYSIS in transaction SA38 while a ST05 trace is
active. Why is the statement so expensive? What is the ABAP source for this report?

(2) Trace ABAP report ZH9_QUERY_ANALYSIS_2 using ST05. What change to the ABAP
makes this report so much faster?

Hints:

Open transaction SA38 and execute ZH9_QUERY_ANALYSIS once to initialize the


database.

Page 80/92
IMAGE 74 TRANSACTION SA38

Open a second SAP window with transaction ST05 (/ost05). Check SQL Trace and then
click the Activate Trace with Filter. Enter ZH9_QUERY_ANALYSIS in the Program Name
text box and click the green check mark button.

Page 81/92
IMAGE 75 ST05 TRACE WITH FILTER

Go back to the window with transaction SA38 to re-execute ABAP report


ZH9_QUERY_ANALYSIS. Once the report has returned the results go back to the window
with the ST05 trace.

o Deactivate the trace (F6)

o Click on Display Trace (F7). In the next window Display Performance Trace leave
everything and execute (F8). Now the trace is displayed. We are interested in
summary of the SQL statements in the report. Choose Trace List
Summarize Trace by SQL Statement (Shift+F8):

IMAGE 76 ST05 - DISPLAY TRACE

Page 82/92
o In the summary view we see one query gets run several thousand times, each time
with a different ZH9_TRC1.TRCID literal predicate value.

IMAGE 77 ST05 - SUMMARIZED SQL TRACE

IMAGE 78 ST05 - TRACE LIST

o Click to highlight one of the select statements and hit F5 to view the ABAP source
code calling this query.

Page 83/92
IMAGE 79 ABAP SOURCE FOR ZH9_QUERY_ANALYSIS

o The cursor is placed at the location of the selected query. Note that the query is
within a while loop in the program, and that this could be replaced by a single SQL
statement containing a MOD function.

In one SAPGUI window, return to transaction SA38, and in a second window, return to
transaction ST05. Activate another SQL Trace for the program
ZH9_QUERY_ANALYSIS_2, and then run ZH9_QUERY_ANALYSIS_2 in transaction SA38.

o When the program finishes, deactivate and display the trace. How many SQL
statements are executed now?

IMAGE 80 ST05 TRACE FOR ZH9_QUERY_ANALYSIS_2

o How does the ABAP source look like now? Note that the loop has been removed
and replaced with one single SQL statement.

We are now going to optimize the access for this statement by adding a new index. Go
back to the DBA Cockpit.

o In the DBA Cockpit, click Performance SQL Cache. In the selection screen
choose Custom. Now enter SELECT ZH9_TRC1*MOD* in the field SQL Statement
Text. This will return the query from the second ABAP report that we wish to tune.

Page 84/92
o Highlight the query and click the Explain button to display the optimizer access
plan in a new window. Note the types of scans and the cost estimate (measured in
timerons). You have to click Detailed Graph to get the cost estimate.

o Now run the Index Advisor for this statement. You will see that three indexes are
being recommend by the advisor. Explain the statement again, by choosing
including existing and recommended indexes. How is the access plan different
from the original plan? Did the cost estimation change as well?

Page 85/92
Unit 8 Problem Analysis

Hands-On Lab 8.1 db2look, db2top, INSPECT, db2support

Objective:

Learn how to run db2look.

Use db2top to monitor the DB2 system.

Run the DB2 INSPECT command to verify the consistency of a single table.

Use the db2support tool to collect diagnostic data.

Tasks/ Questions:

(1) Use db2look to find the page and extent sizes defined for the SAP tablespaces.

(2) Run db2top in interactive mode for the N4S database. Can you see the quality of the
IBMDEFAULTBP buffer pool? Do you see any utility in progress?

(3) Use the DB2 INSPECT command to verify the integrity of table REPOSRC.

(4) Run command db2support to collect diagnostic data for the system. Which file is
created by db2support? Can you open this file? What does it contain?

Hints:

Log on as user db2n4s on a Terminal window.

o The command options for the db2look to get information about the database layout
and write the output to a file are:
db2look d n4s l o db2look.out

Page 86/92
o Start db2top. In db2top, use b (Bufferpools) to get information about the
bufferpools of the database, including the quality. Use u (Utilities) to see if, for
example, RUNSTATS is running.

o Use INSPECT against table REPOSRC. The output file is in binary format and needs to
be transformed by using the db2inspf command:
db2 connect to n4s
db2 inspect check table name reposrc schema sapn4s
results keep inspect.dmp
cd /db2/N4S/db2dump
db2inspf inspect.dmp inspect.out
vi inspect.out

o To collect diagnostic information, use the db2support command:


cd /db2/N4S/db2dump
db2support . d n4s c f
This will create an archive called db2support.zip that can be transferred to SAP
support.

Page 87/92
Hands-On Lab 8.2 Lock-wait Scenario

Objective:

Learn how to monitor a lock-wait scenario in DB2.

Task/ Question:

(1) Create a lock-wait situation on the database and use the DBA Cockpit to monitor it. Is
there another tool available to get similar information?

Hints:

Open a second SAPGUI window with transaction SA38. Run the report ZH9_LOCKWAIT.

In the DBA Cockpit, go to Diagnostics Lock Wait Events. You will see the lock wait
created by the ABAP report:

Page 88/92
IMAGE 81 DBA COCKPIT - LOCK WAIT EVENTS

Alternatively, you can run db6util sl as user n4sadm in a Terminal window:

Page 89/92
IMAGE 82 DB6UTIL

Page 90/92
Copyrights, Trademarks & Disclaimer
Copyright IBM Corporation, 2013 All Rights Reserved.

IBM, the IBM logo, and ibm.com 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.

SAP, mySAP, SAP NetWeaver, SAP NetWeaver BI, SAP NetWeaver BW, SAP BW, SAP R/3,
SAP SCM, SAP SEM and other SAP products and services mentioned herein are trademarks or
registered trademarks of SAP AG in Germany and in several other countries.
More about SAP trademarks at.
http://www.sap.com/company/legal/copyright/trademark.asp

Microsoft, Windows, Windows NT and the Windows logo are registered trademarks of Microsoft
Corporation in the United States and/ or other countries.
UNIX is a registered trademark in the United States and other countries licensed exclusively
through The Open Group.
LINUX is a registered trademark of Linus Torvalds.
Intel and Pentium are registered trademarks and MMX, Itanium, Pentium II Xeon and Pentium III
Xeon are trademarks of Intel Corporation in the United States and/ or other countries.
Java and all Java- based trademarks and logos are trademarks of Sun Microsystems, Inc. in the
United States and/ or other countries.

Other company, product and service names may be trademarks or service marks of others.

REFERENCES IN THIS PUBLICATION TO IBM PRODUCTS, PROGRAMS, OR SERVICES DO


NOT IMPLY THAT IBM INTENDS TO MAKE THESE AVAILABLE IN ALL COUNTRIES IN
WHICH IBM OPERATES.
IBM MAY HAVE PATENTS OR PENDING PATENT APPLICATIONS COVERING SUBJECT
MATTER IN THIS DOCUMENT.
THE FURNISHING OF THIS DOCUMENT DOES NOT IMPLY GIVING LICENSE TO THESE
PATENTS.
INFORMATION IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND.
THE INFORMATION IN THIS DOCUMENT MAY CONCERN NEW PRODUCTS THAT IBM MAY
OR MAY NOT ANNOUNCE.

Any discussion of OEM products is based upon information which has been publicly available and
is subject to change. The specification of some of the features described in this presentation may
change before the General Availability date of these products.
Information concerning non-IBM products was obtained from a supplier of these products,
published announcement material, or other publicly available sources and does not constitute an
endorsement of such products by IBM. Sources for non-IBM list prices and performance numbers
are taken from publicly available information, including vendor announcements and vendor
worldwide homepages.

Page 91/92
IBM has not tested these products and cannot confirm the accuracy of performance, capability, or
any other claims related to non-IBM products. Questions on the capability of non-IBM products
should be addressed to the supplier of those products.

Page 92/92

You might also like