常用的DB2命令

來源:互聯網
上載者:User

啟動資料庫:啟動db2服務:db2start啟用資料庫執行個體:db2 activate database  <db_name>查看啟用狀態的資料庫:db2 list active databases
關閉資料庫:失效資料庫執行個體:db2 deactivate database <db_name>關閉資料庫服務:db2stop
查看資料庫:db2 list db directory
查看資料庫應用:db2 list applications查看資料庫應用和進程號:db2 list applications show detail查看資料庫資料表空間:db2pd -db <db_name> -tablespace
查看資料庫配置:db2 get db cfg for <db_name>串連資料庫:db2 connect to <db_name>                    db2 connect to <db_name> user[user_name] using [password]斷開資料庫連接:db2 connect reset/db2 terminate建立資料庫:db2 create db <db_name>刪除資料庫:db2 drop database <db_name>  (如果不能刪除,嘗試斷開啟用的串連或者重啟db2)
列出系統資料表:db2 list tables for system列出所有使用者表:db2 list tables列出所有表:db2 list tables for all列出特定使用者表:db2 list tables for schema [user]
複製一張表:db2 create table t1 like t2顯示表結構:db2 describe table tablename查詢表:db2 "select * from table tablename where ..."執行SQL指令碼:db2 -tvf scripts.sql
查看錯誤碼資訊:db2 ? 10054 停止啟用的串連:db2 force application all;\db2 force application all;\db2 force application all;\db2stop 查看死結: db2 get snapshot for locks on <db_name>                  db2 "select agent_id,tabname,lock_mode from table(snap_get_lock('<db_name>')) as aa"殺掉進程: db2 force application(NUM)  監控DB2消耗多的SQL語句:eg:(DB_NAME=CMSDB)db2top -d CMSDB  -----查看消耗資源 按照提示按 l,出現Application Handle,找到資源消耗大的Application Handle(stat)記下app handle。db2pd -d CMSDB -dyn -application > /tmp/db2pd1.txt    ----到處會話語句,準備進行調優
設定串連方式(重啟才會生效):db2set DB2COMM=tcpipdb2set DB2COMM=            

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.