首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> DB2 資料庫 >> DB2 教學

DB2 核心管理指令大全:實例、資料庫、物件、效能、維運速查

     編輯:DB2 教學

實例級管理指令

功能指令說明
啟動實例db2start啟動 DB2 資料庫管理器
停止實例db2stop [force]force 強制斷開所有連線
檢視實例配置get dbm cfg顯示所有參數當前值
檢視配置詳情 (含延遲值)get dbm cfg show detail區分當前生效值與重啟後生效值
修改實例參數update dbm cfg using <參數> <值>如 FEDERATED YES
查看當前實例名get instance返回 DB2INSTANCE 環境變數值
強制斷開所有應用force application all維護前清理連線
連接遠端實例 (實例級)attach to user using 執行實例級遠端操作
列出本地節點目錄list node directory
編目 TCP/IP 節點catalog tcpip node remote server ostype
取消節點編目uncatalog node

資料庫級管理指令

功能指令說明
連接資料庫connect to [user using ]隱式啟動資料庫
顯式啟動資料庫activate database 預熱緩衝池、避免首次連接延遲
顯式停用資料庫deactivate database 釋放資源、關閉日誌
斷開連接connect reset
檢視資料庫配置get db cfg for [show detail]
修改資料庫參數update db cfg for using <參數> <值>如 LOGFILSIZ 8000
列出資料庫目錄list database directory [on ]系統/本地目錄
編目資料庫catalog database as at node
取消資料庫編目uncatalog database
測試遠端連接connect to user using

物件與結構查詢指令

功能指令 / SQL
列出表 (含系統/所有/Schema)list tables [for all | for schema ] [show detail]
描述表結構 (欄位/類型/索引)describe table 或 describe select * from .
列出表空間list tablespaces [show detail]
列出表空間容器list tablespace containers for [show detail]
匯出 DDL (db2look)db2look -d -e -c -o
執行腳本檔db2 -tvf
查看 DB2 版本db2level 或 select * from sysibm.sysversions

效能與維運核心指令

set data type varchar()
功能指令
修改緩衝池大小alter bufferpool size [pagesize 4096]
建立緩衝池create bufferpool size [pagesize 4096]
刪除緩衝池drop bufferpool
快速清空大表 (不記日誌)alter table activate not logged initially with empty table
檢視存儲過程select * from syscat.procedures
檢視檢查約束select * from syscat.checks where tabname=''
檢視外鍵約束select * from syscat.references where tabname=''
檢視緩衝池狀態select * from syscat.bufferpools
列出當前應用/連線list applications [show detail]
資料庫一致性檢查 (db2dart)db2dart /DB
SQL 效能測試 (db2batch)db2batch -d -f -r
多欄位 IN 查詢where (colA, colB) in (values (v1,v2), (v3,v4))
修改 VARCHAR 長度 (僅增不減)alter table alter column
設定 Current Schemaset schema =
代碼頁設定 (環境變數/Registry)DB2CODEPAGE=1386 或 db2set DB2CODEPAGE=1386
低版本遷移高版本db2 migrate database (先備份還原)
含引號物件查詢select * from "Schema"."Table" (CLP 雙引號)

資料移動指令

功能指令
匯出資料export to of
匯入資料import from of [insert|insert_update|replace|create] into
載入資料 (高效能)load from of [insert|replace] into [nonrecoverable]

批次執行模式參數速查 (db2 命令選項)


-c  自動提交 (預設 ON)          -c- 關閉自動提交
-t  設定語句結束字元 (預設 ;)    -td;  明確指定分號
-v  回顯命令                    -v- 關閉回顯
-f  讀取輸入檔                  -f script.sql
-z  所有輸出導向檔案            -z output.log
-r  報告輸出導向檔案            -r report.log
-s  錯誤時停止                  -s- 繼續執行
-q  保留空白/換行               -q- 不保留
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved