posts - 89,  comments - 98,  trackbacks - 0

          DB2 常用命令集

          *************************************************

          *? version: V1.0

          *? author: xiedd <mailto:xiedd@icss.com.cn>

          *? update: 2006-06-14

          *? memo: 詳細命令請使用 "db2 ? <command>" 進行查看。 

          *************************************************

          <!--[if !supportLists]-->1.??????? <!--[endif]-->關閉db2

          db2stop

          db2stop force

          在腳本中一般兩個都寫上,避免使用 db2stop force 命令,如:

          db2stop

          db2stop force

          <!--[if !supportLists]-->2.??????? <!--[endif]-->啟動db2

          db2start

          <!--[if !supportLists]-->3.??????? <!--[endif]-->創建數據庫

          db2 create db <db name>

          db2 create db using codeset GBK territory CN

          <!--[if !supportLists]-->4.??????? <!--[endif]-->刪除數據庫

          執行此操作要小心。

          db2 drop db <db name>

          如果不能刪除,斷開所有數據庫連接或者重啟 db2

          <!--[if !supportLists]-->5.??????? <!--[endif]-->斷開數據庫連接

          db2 force application all

          <!--[if !supportLists]-->6.??????? <!--[endif]-->連接數據庫

          db2 connect to <db name> user <username> using <password>

          <!--[if !supportLists]-->7.??????? <!--[endif]-->斷開數據庫連接

          斷開當前數據庫連接: db2 connect reset

          或者: db2 disconnect current

          斷開所有數據庫的連接: db2 disconnect all

          <!--[if !supportLists]-->8.??????? <!--[endif]-->備份數據庫

          db2 backup db <db name>

          備注:執行以上命令之前需要斷開數據庫連接

          <!--[if !supportLists]-->9.??????? <!--[endif]-->恢復數據庫

          db2 restore db <source db name>

          <!--[if !supportLists]-->10.??? <!--[endif]-->導出數據文件

          db2move <db name> export [-sn < 模式名稱,一般為 db2admin>] [-tn ?< 表名,多個之間用逗號分隔 >]

          <!--[if !supportLists]-->11.??? <!--[endif]-->導入數據文件

          db2move <db name> import

          <!--[if !supportLists]-->12.??? <!--[endif]-->列出數據庫中所有db

          db2 list db directory

          <!--[if !supportLists]-->13.??? <!--[endif]-->進入db2命令環境

          在“運行”中執行: db2cmd

          <!--[if !supportLists]-->14.??? <!--[endif]-->獲取db2數據庫管理配置環境信息??????

          db2 get dbm cfg

          <!--[if !supportLists]-->15.??? <!--[endif]-->獲取db2某個數據庫數據庫管理配置環境信息??????

          db2 get db cfg for <db name>

          或者:連接至某個數據庫以后執行 db2 get db cfg

          <!--[if !supportLists]-->16.??? <!--[endif]-->設置聯合數據庫為可用(默認聯合數據庫不可用)

          db2 update dbm cfg using federated yes

          <!--[if !supportLists]-->17.??? <!--[endif]-->更改db2日志空間的大小

          備注:以下命令為了防止 db2 數據庫過份使用硬盤空間而設,僅用于開發者自己機器上的 db2 ,如果是服務器,則參數需要修改。

          db2 UPDATE DB CFG FOR <db name> USING logretain OFF logprimary 3 logsecond 2 logfilsiz 25600;

          如果頁大小是 4KB ,則以上命令創建 3 100M 的日志文件,占用 300MB 硬盤空間。 25600*4KB=102400KB

          <!--[if !supportLists]-->18.??? <!--[endif]-->創建臨時表空間

          DB2 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32 K MANAGED BY DATABASE USING (FILE 'D:\DB2_TAB\STMASPACE.F1' 10000) EXTENTSIZE 256

          <!--[if !supportLists]-->19.??? <!--[endif]-->獲取數據庫管理器的快照數據

          db2 –v get snapshot for dbm

          <!--[if !supportLists]-->20.??? <!--[endif]-->顯示進行程號

          db2 list applications show detail

          <!--[if !supportLists]-->21.??? <!--[endif]-->調查錯誤

          sqlcode: 產品特定錯誤碼;

          sqlstate:DB2 系列產品的公共錯誤碼,符合 ISO/ANSI 92SQL 標準。

          調查 sqlcode : db2 ? sql1403n

          調查 sqlstate: db2 ? 08004

          <!--[if !supportLists]-->22.??? <!--[endif]-->創建表空間

          rem 創建緩沖池空間 8K

          db2 connect to gather

          db2 CREATE BUFFERPOOL STMABMP IMMEDIATE? SIZE 25000 PAGESIZE 8K

          rem 創建表空間: STMA

          rem 必須確認路徑正確

          rem D:\DB2Container\Stma

          db2 drop tablespace stma

          db2 CREATE? REGULAR TABLESPACE STMA PAGESIZE 8 K? MANAGED BY SYSTEM? USING ('D:\DB2Container\Stma' ) EXTENTSIZE 8 OVERHEAD 10.5 PREFETCHSIZE 8 TRANSFERRATE 0.14 BUFFERPOOL? STMABMP? DROPPED TABLE RECOVERY OFF

          db2 connect reset

          <!--[if !supportLists]-->23.??? <!--[endif]-->?將暫掛的數據恢復到前滾狀態

          db2 ROLLFORWARD DATABASE TESTDB TO END OF LOGS AND COMPLETE NORETRIEVE

          <!--[if !supportLists]-->24.??? <!--[endif]-->備份表空間

          BACKUP DATABASE YNDC TABLESPACE ( USERSPACE1 ) TO "D:\temp" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING

          <!--[if !supportLists]-->25.??? <!--[endif]-->創建db2工具數據庫

          db2 create tools catalog systools create new database toolsdb

          <!--[if !supportLists]-->26.??? <!--[endif]-->如何進行增量/差量備份

          增量:上一次完整備份至本次備份之間增加的數據部分;

          差量 (delta) :上次備份以來(可能是完整備份、增量備份或者差量備份)至本次備份之間增加的數據部分;

          <!--[if !supportLists]-->27.??? <!--[endif]-->更新所有表的統計信息

          db2 -v connect to DB_NAME

          db2 -v "select tbname, nleaf, nlevels, stats_timefrom sysibm.sysindexes"

          db2 -v reorgchkupdate statistics on table all

          db2 -v "select tbname, nleaf, nlevels, stats_timefrom sysibm.sysindexes"

          db2 -v terminate

          <!--[if !supportLists]-->28.??? <!--[endif]-->對一張表運行統計信息

          db2 -v runstatson table TAB_NAMEand indexes all

          <!--[if !supportLists]-->29.??? <!--[endif]-->查看是否對數據庫執行了RUNSTATS

          db2 -v "select tbname, nleaf, nlevels, stats_timefrom sysibm.sysindexes"

          <!--[if !supportLists]-->30.??? <!--[endif]-->更改緩沖池的大小

          緩沖池中,當 syscat.bufferpools npages -1 時,由數據庫的配置參數 bufferpage 控制緩沖池的大小。

          npages 的值更改為 -1 的命令:

          db2 -v connect to DB_NAME

          db2 -v select * from syscat.bufferpools

          db2 -v alter bufferpoolIBMDEFAULTBP size -1

          db2 -v connect reset

          db2 -v terminate

          更改數據庫配置參數 BufferPages 的命令如下:

          db2 -v update db cfgfor dbnameusing BUFFPAGE bigger_value

          db2 -v terminate

          <!--[if !supportLists]-->31.??? <!--[endif]-->查看數據庫監視內容列表

          db2 -v get monitor switches

          <!--[if !supportLists]-->32.??? <!--[endif]-->打開某個數據庫監視內容

          db2 -v update monitor switches using bufferpoolon

          <!--[if !supportLists]-->33.??? <!--[endif]-->獲取數據庫快照

          db2 -v get snapshot for all databases > snap.out

          db2 -v get snapshot for dbm>> snap.out

          db2 -v get snapshot for all bufferpools>> snap.out

          db2 -v terminate

          <!--[if !supportLists]-->34.??? <!--[endif]-->重置數據庫快照

          db2 -v reset monitor all

          <!--[if !supportLists]-->35.??? <!--[endif]-->計算緩沖池命中率

          理想情況下緩沖池命中率在 95% 以上,計算公式如下:

          (1 -((buffer pool data physical reads + buffer pool index physical reads) /(buffer pool data logical reads + pool index logical reads))) *100%

          <!--[if !supportLists]-->36.??? <!--[endif]-->?創建db2實例

          db2icrt < 實例名稱 >

          <!--[if !supportLists]-->37.??? <!--[endif]-->刪除db2實例

          db2idrop < 實例名稱 >

          <!--[if !supportLists]-->38.??? <!--[endif]-->設置當前db2實例

          set db2intance=db2

          <!--[if !supportLists]-->39.??? <!--[endif]-->?顯示db2擁有的實例

          db2ilist

          <!--[if !supportLists]-->40.??? <!--[endif]-->恢復離線增量備份數據庫的命令

          DB2 RESTORE DATABASE YNDC INCREMENTAL AUTOMATIC FROM D:\backup\autobak\db2 TAKEN AT 20060314232015

          <!--[if !supportLists]-->41.??? <!--[endif]-->?創建樣本數據庫

          unix 平臺,使用: sqllib/bin/db2sampl <path>

          windows,os/2 平臺,使用: db2sampl e,e 是可選參數,指定將創建數據庫的驅動器;

          <!--[if !supportLists]-->42.??? <!--[endif]-->?列出數據庫中所有的表

          db2 list tables

          <!--[if !supportLists]-->43.??? <!--[endif]-->?列出某個表的數據結構

          db2 describe table v_ro_role

          <!--[if !supportLists]-->44.??? <!--[endif]-->給表增加列

          ALTER TABLE STAFF? ADD COLUMN PNHONE VARCHAR(20)

          <!--[if !supportLists]-->45.??? <!--[endif]-->數據遷移方法1

          export 腳本示例
          db2 connect to testdb user test password test
          db2 "export to aa1.ixf of ixf select * from table1"
          db2 "export to aa2.ixf of ixf select * from table2"
          db2 connect reset
          import
          腳本示例
          db2 connect to testdb user test password test
          db2 "load from aa1.ixf of ixf? replace into table1? COPY NO? without prompting "
          db2 "load from aa2.ixf of ixf? replace into table2? COPY NO? without prompting "
          db2 connect reset

          <!--[if !supportLists]-->46.??? <!--[endif]-->?

          posted on 2006-09-14 09:35 水煮三國 閱讀(631) 評論(0)  編輯  收藏 所屬分類: Database
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類(85)

          隨筆檔案(89)

          文章分類(14)

          文章檔案(42)

          收藏夾(37)

          java

          oracle

          Sybase

          搜索

          •  

          積分與排名

          • 積分 - 211178
          • 排名 - 265

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 枣强县| 屏南县| 长顺县| 包头市| 密云县| 兴城市| 武义县| 东明县| 余江县| 新昌县| 伊宁市| 仙桃市| 上蔡县| 闵行区| 丹巴县| 呼伦贝尔市| 贵德县| 玉环县| 泽库县| 铜陵市| 华亭县| 大石桥市| 牟定县| 喀喇沁旗| 田东县| 油尖旺区| 阿鲁科尔沁旗| 广东省| 红河县| 武隆县| 库车县| 赤峰市| 额尔古纳市| 高安市| 灌南县| 保德县| 格尔木市| 西畴县| 华安县| 和林格尔县| 铁力市|