<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    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]-->關(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ù)庫連接

    斷開當前數(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]-->恢復數(shù)據(jù)庫

    db2 restore db <source db name>

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

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

    <!--[if !supportLists]-->11.??? <!--[endif]-->導入數(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ù)庫為可用(默認聯(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 標準。

    調(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 必須確認路徑正確

    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ù)恢復到前滾狀態(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]-->更改緩沖池的大小

    緩沖池中,當 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è)置當前db2實例

    set db2intance=db2

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

    db2ilist

    <!--[if !supportLists]-->40.??? <!--[endif]-->恢復離線增量備份數(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 水煮三國 閱讀(629) 評論(0)  編輯  收藏 所屬分類: Database
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(4)

    隨筆分類(85)

    隨筆檔案(89)

    文章分類(14)

    文章檔案(42)

    收藏夾(37)

    java

    oracle

    Sybase

    搜索

    •  

    積分與排名

    • 積分 - 210790
    • 排名 - 266

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲第一区精品日韩在线播放| 久视频精品免费观看99| 99精品全国免费观看视频| 最新国产成人亚洲精品影院| 99久久国产热无码精品免费| 亚洲成人免费网址| 午夜一区二区免费视频| 日韩色日韩视频亚洲网站| 亚洲国产精品成人| 影音先锋在线免费观看| yellow免费网站| 久久国产精品亚洲综合| 亚洲国产精品免费在线观看| 亚洲一区二区三区四区视频| 亚洲成a人片在线观看国产| 女人18毛片a级毛片免费 | 中文字幕精品亚洲无线码二区| 日韩免费观看一区| 亚洲丰满熟女一区二区v| 亚洲一区二区三区乱码A| 2015日韩永久免费视频播放| 免费成人高清在线视频| 亚洲中文字幕无码爆乳| 亚洲综合色成在线播放| 亚洲精品黄色视频在线观看免费资源| 51精品视频免费国产专区| 国产一级淫片a免费播放口| 中文在线免费视频| 亚洲AV无码一区二区三区在线| 亚洲第一成年人网站| 亚洲国产黄在线观看| 2022中文字字幕久亚洲| 国产专区一va亚洲v天堂| 69天堂人成无码麻豆免费视频| 1000部啪啪毛片免费看| 69天堂人成无码麻豆免费视频| www.999精品视频观看免费| 国产精品免费观看调教网| 免费精品一区二区三区第35| 日韩精品内射视频免费观看| 美女免费视频一区二区|