Вы находитесь на странице: 1из 1

DB2 Commands

a Cheat Sheet by Graeson Lewis

DB2 Software

DB2 Objects

DB2 Recovery

db2setup
db2_install
installFixPack -b db2dir
db2rspgn -i db2inst1
db2setup -r file.rsp
db2licm -l show detail
db2licm -a file.lic
db2level
db2ls
db2ls -q -b db2dir -a

db2 create db db1


db2 "activate db db1"
db2 "deactivate db db1"
db2 "upgrade db db1"
db2 create tablespace ts1
db2 create schema s1
db2 create table t1 (c1 int) in ts1
db2 create index i1 on t1(c1)
db2 "list db partition groups"
db2 "list tablespaces show detail"
db2 "list tablespace containers for 0"
db2 "list tables show detail"
db2 "list packages"
db2 "list utilities show detail"
db2 "describe table t1"
db2 "describe indexes for table t1"
db2 "describe output select * from t1"
db2look -d db1 -e -l -x -o file.sql
db2advis -d db1 -s select * from t1
db2advis -d db1 -i file.sql

db2 update db cfg for db1 using trackmod yes


db2 update db cfg for db1 using logarchmeth1 recovery
db2 update db cfg for db1 using logarchmeth2 userexit
db2adutl query
db2adutl delete full taken at timestamp db db1
db2ckbkp file
db2 "quiesce db immediate"
db2 "unquiesce db"
db2 "backup db db1"
db2 backup db db1 online include logs
db2 backup db db1 use tsm compress
db2 backup db db1 on all dbpartitionnums
db2 backup db db1 online incremental
db2 backup db db1 online incremental delta
db2 list history backup all for db1
db2 list history since timestamp for db db1
db2 restore db db1 from /path
db2 restore db db1 into d1 taken at timestamp
db2 restore db db1 replace existing redirect
db2 set tablespace containers for 5 using (file /data/c1 8192)
db2 restore db db1 continue
db2 restore db db1 incremental automatic
db2 "rollforward db db1 to end of logs"
db2 rollforward db db1 to isotime
db2 rollforward db db1 complete
db2 "recover db db1"
db2 "recover db db1 to isotime"
db2 "prune history 20091231"

DB2 Instance
db2start
db2stop
db2icrt -u db2fenc1 db2inst1
db2idrop db2inst1
db2iupdt db2inst1
db2iupgrade -u db2fenc1 db2inst1
db2ilist

DB2 Configuration
DB2 Connectivity
db2 "connect to db1"
db2 connect to db1 user u using p
db2 "connect reset"
db2 "list node directory"
db2 "catalog tcpip node n1 remote r1
server 50000"
db2 "uncatalog node n1"
db2 "list db directory"
db2 "catalog db db1 at node n1"
db2 "uncatalog db db1"
db2 "terminate"

db2iauto -on db2inst1


db2set -all
db2set -lr
db2set db2options=+c
db2set DB2COMM=tcpip
db2set -null DB2COMM
db2 "get dbm cfg show detail"
db2 update dbm cfg using
intra_parallel no
db2 "get db cfg for db1 show detail"
db2 update db cfg for db1 using self_tuning_mem on
db2 "autoconfigure using mem_percent 80 apply db
and dbm

DB2 SQL & DML


db2 "select * from t1 where c1 = 1"
db2 "insert into t1 (id, name) values (1, 'abc')"
db2 "update t1 set c1 = 'xyz' where id = 1"
db2 "delete from t1 where c1 = 1"
db2 commit
db2 rollback

DB2 Maintenance
db2 "reorgchk update statistics on table all"
db2 reorgchk update statistics on schema s1
db2 reorgchk update statistics on table system
db2 "reorg table t1"
db2 reorg table t1 inplace
db2 reorg index i1 for table t1
db2 reorg indexes all for t1
db2pd -d db1 -reorgs
db2 runstats on table t1 and indexes all
db2 "runstats on table t1 with distribution and detailed indexes all"
db2 runstats on table t1 with distribution on key columns
and sampled detailed indexes all
db2pd -runstats
db2look -d db1 -m -o file.sql
db2 "bind @db2ubind.lst blocking all grant public"
db2 "bind @db2cli.lst blocking all grant public"
db2rbind db1 -l logfile all

DB2 High Availability

DB2 Monitoring & Tuning

DB2 Security

db2 "start hadr on db db1 as primary"


db2 "start hadr on db db1 as standby"
db2 "stop hadr on db db1"
db2 "takeover hadr on db db1"
db2 update db cfg for db1 using logindexbuild on
db2 update db cfg for db1 using hadr_sync_mode
nearsync
db2pd -db db1 -hadr
db2set DB2_HADR_BUF_SIZE = 65536
db2 update db cfg for db1 using logfilsiz 65536
db2 update alternate server for db db1 using
hostname h1 port 50000

db2 "list applications show detail"


db2mtrk -i -d -a -v -r 10
db2top -d db1
db2pd -db db1 -database
db2pd -db db1 -bufferpools
db2pd -db db1 -tablespaces
db2 get dbm monitor switches
db2 update monitor switches using bufferpool on
db2 reset monitors all
db2 get snapshot for database manager
db2 get snapshot for database on db1
db2 get snapshot for bufferpools on db1
db2 get snapshot for tablespaces on db db1
db2 get snapshot for tables on db db1
db2 get snapshot for applications on db1
db2 get snapshot for dynamic sql on db1
db2 get snapshot for locks on db1
db2 call sysproc.am_get_lock_chns(15,?)
db2batch -d db1 -f file.sql

db2 create database db1 restrictive


db2 update dbm cfg using authentication server_encrypt
db2 update dbm cfg using sysadm_group g1
db2 update dbm cfg using sysctrl_group g2
db2 update dbm cfg using sysmaint_group g3
db2 grant dbadm on database to g4
db2 grant load on database to g5
db2 grant select on table t1 to user user1
db2 revoke connect on database from public
db2 revoke use of tablespace ts1 from public
db2 revoke select on table syscat.dbauth from public
db2 update dbm cfg using audit_buf_sz 8192
db2audit describe
db2audit configure scope checking status failure
errortype normal
db2audit start
db2audit extract delasc delimiter , category checking
database db1 status failure
db2audit prune data yyyymmddhh

DB2 Troubleshooting
db2 "force applications all"
db2 "force application (12345)"
db2diag -g -d db1 -l severe
db2diag -lastrecords 5
db2diag -rc
db2support . -d db1 -c
db2dart db1 /ts
db2dart db1 /t
db2dart db1 /ddel
db2 "inspect check table name t1 schema s1
indexdata results keep t1.out"
db2 inspect rowcompestimate table name t1
schema foo results f1.out

DB2 Data Movement


db2move db1 export
db2move db1 import
db2move db1 copy -sn s1 -co target_db db1
db2 "export to t1.del of del select * from t1
db2 import from t1.del of del insert into t1
db2 "load from t1.del of del replace into t1

DB2 Development
db2 -td@ -svf file.sql
create procedure sp1(in p1 int) language sql begin select * from t1 where c1 = p1; end@
create trigger g1 after insert on t1 for each row update t2 set c1 = c1 + 1@
create function f1 (x double) returns double language sql return sin(x)/cos(x)@
create table t1 (id int, c1 char(1), c2 char(1)) organize by (c1, c2)@

Notes
System commands used for installing, managing, and updating software are
path dependant (i.e. /cdrom/db2setup, /opt/ibm/db2/V9.7/instance/db2icrt)
Before issuing DB2 commands or invoking the Command Line Processor, you
must source a db2profile (i.e. . /home/db2inst1/sqllib/db2profile)
DB2 commands can be grouped into scripts and executed from the command
line using db2 -tvf filename.clp -o filename.log

Copyright 2011 Graeson Lewis

GRAESON LEWIS
graeson@gmail.com
ceevee.com/graeson
linkedin.com/in/graeson
graeson.wordpress.com