posts - 89,  comments - 98,  trackbacks - 0

          DB2 常用命令集

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

          *? version: V1.0

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

          *? update: 2006-06-14

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

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

          <!--[if !supportLists]-->1.??????? <!--[endif]-->關(guān)閉db2

          db2stop

          db2stop force

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

          db2stop

          db2stop force

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

          db2start

          <!--[if !supportLists]-->3.??????? <!--[endif]-->創(chuàng)建數(shù)據(jù)庫

          db2 create db <db name>

          db2 create db using codeset GBK territory CN

          <!--[if !supportLists]-->4.??????? <!--[endif]-->刪除數(shù)據(jù)庫

          執(zhí)行此操作要小心。

          db2 drop db <db name>

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

          <!--[if !supportLists]-->5.??????? <!--[endif]-->斷開數(shù)據(jù)庫連接

          db2 force application all

          <!--[if !supportLists]-->6.??????? <!--[endif]-->連接數(shù)據(jù)庫

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

          <!--[if !supportLists]-->7.??????? <!--[endif]-->斷開數(shù)據(jù)庫連接

          斷開當(dāng)前數(shù)據(jù)庫連接: db2 connect reset

          或者: db2 disconnect current

          斷開所有數(shù)據(jù)庫的連接: db2 disconnect all

          <!--[if !supportLists]-->8.??????? <!--[endif]-->備份數(shù)據(jù)庫

          db2 backup db <db name>

          備注:執(zhí)行以上命令之前需要斷開數(shù)據(jù)庫連接

          <!--[if !supportLists]-->9.??????? <!--[endif]-->恢復(fù)數(shù)據(jù)庫

          db2 restore db <source db name>

          <!--[if !supportLists]-->10.??? <!--[endif]-->導(dǎo)出數(shù)據(jù)文件

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

          <!--[if !supportLists]-->11.??? <!--[endif]-->導(dǎo)入數(shù)據(jù)文件

          db2move <db name> import

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

          db2 list db directory

          <!--[if !supportLists]-->13.??? <!--[endif]-->進入db2命令環(huán)境

          在“運行”中執(zhí)行: db2cmd

          <!--[if !supportLists]-->14.??? <!--[endif]-->獲取db2數(shù)據(jù)庫管理配置環(huán)境信息??????

          db2 get dbm cfg

          <!--[if !supportLists]-->15.??? <!--[endif]-->獲取db2某個數(shù)據(jù)庫數(shù)據(jù)庫管理配置環(huán)境信息??????

          db2 get db cfg for <db name>

          或者:連接至某個數(shù)據(jù)庫以后執(zhí)行 db2 get db cfg

          <!--[if !supportLists]-->16.??? <!--[endif]-->設(shè)置聯(lián)合數(shù)據(jù)庫為可用(默認(rèn)聯(lián)合數(shù)據(jù)庫不可用)

          db2 update dbm cfg using federated yes

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

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

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

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

          <!--[if !supportLists]-->18.??? <!--[endif]-->創(chuàng)建臨時表空間

          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]-->獲取數(shù)據(jù)庫管理器的快照數(shù)據(jù)

          db2 –v get snapshot for dbm

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

          db2 list applications show detail

          <!--[if !supportLists]-->21.??? <!--[endif]-->調(diào)查錯誤

          sqlcode: 產(chǎn)品特定錯誤碼;

          sqlstate:DB2 系列產(chǎn)品的公共錯誤碼,符合 ISO/ANSI 92SQL 標(biāo)準(zhǔn)。

          調(diào)查 sqlcode : db2 ? sql1403n

          調(diào)查 sqlstate: db2 ? 08004

          <!--[if !supportLists]-->22.??? <!--[endif]-->創(chuàng)建表空間

          rem 創(chuàng)建緩沖池空間 8K

          db2 connect to gather

          db2 CREATE BUFFERPOOL STMABMP IMMEDIATE? SIZE 25000 PAGESIZE 8K

          rem 創(chuàng)建表空間: STMA

          rem 必須確認(rèn)路徑正確

          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]-->?將暫掛的數(shù)據(jù)恢復(fù)到前滾狀態(tài)

          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]-->創(chuàng)建db2工具數(shù)據(jù)庫

          db2 create tools catalog systools create new database toolsdb

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

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

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

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

          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]-->對一張表運行統(tǒng)計信息

          db2 -v runstatson table TAB_NAMEand indexes all

          <!--[if !supportLists]-->29.??? <!--[endif]-->查看是否對數(shù)據(jù)庫執(zhí)行了RUNSTATS

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

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

          緩沖池中,當(dāng) syscat.bufferpools npages -1 時,由數(shù)據(jù)庫的配置參數(shù) 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

          更改數(shù)據(jù)庫配置參數(shù) BufferPages 的命令如下:

          db2 -v update db cfgfor dbnameusing BUFFPAGE bigger_value

          db2 -v terminate

          <!--[if !supportLists]-->31.??? <!--[endif]-->查看數(shù)據(jù)庫監(jiān)視內(nèi)容列表

          db2 -v get monitor switches

          <!--[if !supportLists]-->32.??? <!--[endif]-->打開某個數(shù)據(jù)庫監(jiān)視內(nèi)容

          db2 -v update monitor switches using bufferpoolon

          <!--[if !supportLists]-->33.??? <!--[endif]-->獲取數(shù)據(jù)庫快照

          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]-->重置數(shù)據(jù)庫快照

          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]-->?創(chuàng)建db2實例

          db2icrt < 實例名稱 >

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

          db2idrop < 實例名稱 >

          <!--[if !supportLists]-->38.??? <!--[endif]-->設(shè)置當(dāng)前db2實例

          set db2intance=db2

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

          db2ilist

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

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

          <!--[if !supportLists]-->41.??? <!--[endif]-->?創(chuàng)建樣本數(shù)據(jù)庫

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

          windows,os/2 平臺,使用: db2sampl e,e 是可選參數(shù),指定將創(chuàng)建數(shù)據(jù)庫的驅(qū)動器;

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

          db2 list tables

          <!--[if !supportLists]-->43.??? <!--[endif]-->?列出某個表的數(shù)據(jù)結(jié)構(gòu)

          db2 describe table v_ro_role

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

          ALTER TABLE STAFF? ADD COLUMN PNHONE VARCHAR(20)

          <!--[if !supportLists]-->45.??? <!--[endif]-->數(shù)據(jù)遷移方法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 水煮三國 閱讀(634) 評論(0)  編輯  收藏 所屬分類: Database
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(4)

          隨筆分類(85)

          隨筆檔案(89)

          文章分類(14)

          文章檔案(42)

          收藏夾(37)

          java

          oracle

          Sybase

          搜索

          •  

          積分與排名

          • 積分 - 211634
          • 排名 - 266

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 望奎县| 绿春县| 莱西市| 长白| 凤山市| 恭城| 汨罗市| 库伦旗| 安陆市| 都匀市| 环江| 新民市| 利川市| 聂拉木县| 馆陶县| 修水县| 霍邱县| 新绛县| 梁山县| 蒙城县| 柏乡县| 福泉市| 修武县| 江都市| 屏边| 文山县| 都昌县| 宜兰市| 鄢陵县| 姚安县| 吉首市| 图木舒克市| 安丘市| 游戏| 泽库县| 政和县| 屏山县| 镇原县| 乌拉特后旗| 子长县| 丰镇市|