本文彙整最常用的 DB2 CLP(Command Line Processor)指令,供初學者快速查閱。語法中方括號 [ ] 表示可選參數,尖括號 < > 表示變數。任意指令前加 ? 可顯示完整語法(如 ? connect)。
| 指令 | 說明 |
|---|---|
db2start | 啟動資料庫管理器實例 |
db2stop | 停止資料庫管理器實例 |
get dbm cfg | 顯示資料庫管理器配置參數 |
get dbm cfg show detail | 顯示參數目前值與延遲值(V8 起支援) |
update dbm cfg using <p> <v> | 更新資料庫管理器配置參數 |
get instance | 顯示 DB2INSTANCE 環境變數值 |
list active databases | 列出作用中資料庫與連線數 |
list application [show detail] | 顯示目前連線應用程式資訊 |
force application (h1[,h2...]) | 依句柄號中斷特定應用程式連線 |
force application all | 中斷所有應用程式連線 |
attach to <node> user <userid> using <pwd> | 以指定用戶連線至遠端實例節點 |
| 指令 | 說明 |
|---|---|
create database <dbname> | 建立資料庫 |
activate database <dbname> | 顯式啟動資料庫 |
deactivate database <dbname> | 顯式停用資料庫 |
connect to <dbname> [user <userid> using <pwd>] | 連線至資料庫(可指定用戶/密碼) |
connect reset | 中斷目前資料庫連線 |
get db cfg for <dbname> | 顯示指定資料庫配置 |
get db cfg show detail | 顯示參數目前值與延遲值(V8) |
update db cfg for <dbname> using <p> <v> | 更新資料庫配置參數 |
list tables [for {user|all|system|schema <schema>}] [show detail] | 列出資料表(預設列出當前用戶表) |
describe table <tablename> | 顯示資料表/視圖欄位資訊 |
list tablespaces [show detail] | 顯示表空間 ID、名稱、類型、狀態 |
list tablespace containers for <id> [show detail] | 顯示指定表空間容器資訊 |
quiesce tablespaces for table <tablename> reset | 重設表空間狀態為正常 |
| 指令 | 說明 |
|---|---|
catalog [admin] <protocol> node ... | 在節點目錄建立協議項目 |
list [admin] node directory | 顯示節點目錄內容 |
catalog database <dbname> ... | 在資料庫目錄建立項目 |
list database directory [on <path>] | 顯示資料庫目錄內容 |
| 指令 | 說明 |
|---|---|
get monitor switches | 顯示監控開關狀態 |
update monitor switches using <monitor> <on|off> | 設定監控開關 |
reset monitor all | 重設效能監控計數器 |
get snapshot for dbm | 取得實例層級效能快照 |
get snapshot for all on <dbname> | 取得資料庫層級所有效能快照 |
get snapshot for dynamic sql on <dbname> | 顯示動態 SQL 快取內容 |
runstats on table <schema>.<table> | 收集資料表統計資訊(需完整限定名稱) |
reorgchk on table all | 檢查所有資料表是否需重組(自動執行 runstats) |
reorg table <tablename> | 重組資料表消除碎片 |
| 指令 | 說明 |
|---|---|
export ... | 將資料匯出為平面檔案 |
import ... | 使用 IMPORT 工具匯入資料 |
load query table <tbname> ... | 查詢 LOAD 進度 |
backup database <dbname> [to <path>] | 執行資料庫備份 |
restore database <dbname> [from <path>] | 執行資料庫還原 |
get health snapshot for dbm | 取得實例健康快照(V8) |
get health snapshot for all on <dbname> | 取得資料庫所有健康快照(V8) |
| 指令 | 說明 |
|---|---|
get admin cfg | 顯示管理伺服器配置 |
update admin cfg using <p> <v> | 更新管理伺服器參數 |
| 指令 | 說明 |
|---|---|
get routine into <file> from [specific] procedure <name> [hide body] | 將 SQL 預存程序匯出為二進位檔 |
put routine from <file> [owner <newowner> [use registers]] | 從二進位檔部署 SQL 預存程序 |
收藏地址:https://www.cncms.com.cn/db2/q372741.Html