How to run DB2 commands for SAP

useful DB2 commands which needs to run to administer the DB2 Database for SAP workloads.

#To start DB2

#To connect to particular database
db2 connect to dbname

#To check DB configuration/parameters
db2 get db cfg for dbname

#To update DB configuration/parameters
db2 update db cfg for dbname using LOGARCHMETH1 DISK:/db2/TST/archivelog

This is an example, you can update any parameter as per your requirement. LOGARCHMETH1 is parameter which need to update to keep the archive logs, This parameter is visible by check DB configuration command & after updating any parameter, DB restart requires & sometimes offline DB backup requires before starting up the DB.

#Backup DB2 Database
db2 backup database dbname to /location

#Restore DB2 Database
db2 restore db dbname from /location on /db2/TST/sapdata1

The above command will restore the DB on /db2/TST/sapdata1 folder. Make sure to check the DB parameters once restore completed as it always point to old configuration. After restore many times DB can’t start & throw roll forwarding error, in this case you need to complete the roll forwarding with below command –

#To end the roll forward status
db2 rollforward db TST to end of logs & complete

#To deactivate DB before shutting down
db2 deactivate db dbname

#To shut down DB normally

#To shut down db forcefully as application connections were still exists
db2stop force

#To check all schema in DB2 DB
db2 select schemaname from syscat.schemata

#To list all the tables for all DB’s
db2 list tables for all

#To list all the tables in respective DB
db2 list tables for schema dbname

#To manually generate the archive logs
db2 archive log for database dbname

#Unlock DDIC or any other user in DB2
db2 “update SAPSID.USR02 set UFLAG=0 where BNAME=’DDIC’ and MANDT=’000′

#Check HA/DR status in DB2
db2pd -d dbname -hadr | grep -i hadr

DB2 HA/DR Cluster Stop / Start

SAP application should be shut down before stopping the DB2 cluster.

Azure SUSE Linux host running on SBD cluster – Cluster should be set on maintenance mode
(This is a mandatory step otherwise Virtual Name will switch to other host if DB get down in Primary mode. By setting up maintenance mode, it stick on the same node until maintenance mode OFF)

Shut down sequence – Primary DB & then Secondary DB
Startup sequence – Secondary DB & then Primary DB

Login to Primary DB host & verify the crm_status

#Stop the HADR
db2 stop hadr on db dbname
db2 deactivate db dbname

Login to Secondary DB host and run below commands

#Stop the HADR
db2 stop hadr on db dbname
db2 deactivate db dbname

#Start the HADR on Standby/Secondary host first
db2start hadr on db dbname as standby

#Start the HADR on Primary host
db2start hadr on db dbname as primary

#Verify the HADR status on both hosts
db2pd -d dbname -hadr | grep -i hadr

I will update the list with more commands very soon….

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × 4 =

Time limit is exhausted. Please reload CAPTCHA.