⑴ 資料庫突然當了,重啟提示db2nodes.cfg line number"1",Reason code"3"
1、打開命令行窗口#db2cmd2、打開控制中心#db2cmddb2cc3、打開命令編輯器db2cmddb2ce=====操作資料庫命令=====4、啟動資料庫實例#db2start5、停止資料庫實例#db2stop如果你不能停止資料庫由於激活的連接,在運行db2stop前執行db2forceapplicationall就可以了/db2stopforce6、創建資料庫#db2createdb[dbname]7、連接到資料庫#db2connectto[dbname]user[username]using[password]8、斷開資料庫連接#db2connectreset9、列出所有資料庫#db2listdbdirectory10、列出所有激活的資料庫#db2listactivedatabases11、列出所有資料庫配置#db2getdbcfg12、刪除資料庫#db2dropdatabase[dbname](執行此操作要小心)如果不能刪除,斷開所有資料庫連接或者重啟db2=========操作數據表命令==========13、列出所有用戶表#db2listtables14、列出所有系統表#db2listtablesforsystem15、列出所有表#db2listtablesforall16、列出系統表#db2listtablesforsystem17、列出用戶表#db2listtablesforuser18、列出特定用戶表#db2listtablesforschema[user]19、創建一個與資料庫中某個表(t2)結構相同的新表(t1)#db2createtablet1liket220、將一個表t1的數據導入到另一個表t2#db2"insertintot1select*fromt2"21、查詢表#db2"select*fromtablenamewhere"22、顯示表結構#db2describetabletablename23、修改列#db2altertable[tablename]altercolumn[columname]setdatatypevarchar(24)======腳本文件操作命令=======24、執行腳本文件#db2-tvfscripts.sql25、幫助命令*查看命令幫助#db2?db2start*查看錯誤碼信息#db2?22001*memo:詳細命令請使用"db2?"進行查看。=========================26、備份資料庫#db2backupdb備註:執行以上命令之前需要斷開資料庫連接27、在線備份資料庫#db2-v"G"28、恢復資料庫#db2restoredb29、在線恢復資料庫#db2""#db2""30、導出數據文件#db2moveexport[-sn][-tn]31、導入數據文件#db2moveimport32、獲取db2資料庫管理配置環境信息#db2getdbmcfg33、.獲取db2某個資料庫資料庫管理配置環境信息#db2getdbcfgfor或者:連接至某個資料庫以後執行db2getdbcfg34、更改db2日誌空間的大小備註:以下命令為了防止db2資料庫過份使用硬碟空間而設,僅用於開發者自己機器上的db2,如果是伺服器,則參數需要修改。#;如果頁大小是4KB,則以上命令創建3個100M的日誌文件,佔用300MB硬碟空間。25600*4KB=102400KB。35、創建臨時表空間#SING(FILE'D:\DB2_TAB\STMASPACE.F1'10000)EXTENTSIZE25636、獲取資料庫管理器的快照數據#db2–vgetsnapshotfordbm37、顯示進行程號#db2listapplicationsshowdetail===================================================一、載入數據:1、以默認分隔符載入,默認為「,」號db2"importfrombtpoper.txtofdelinsertintobtpoper"2、以指定分隔符「|」載入db2"importfrombtpoper.txtofdelmodifiedbycoldel|insertintobtpoper"二、卸載數據:1、卸載一個表中全部數據db2"exporttobtpoper.txtofdelselect*frombtpoper"db2"exporttobtpoper.txtofdelmodifiedbycoldel|select*frombtpoper"2、帶條件卸載一個表中數據db2"exporttobtpoper.txtofdelselect*frombtpoperwherebrhid='907020000'"db2"exporttocmmcode.txtofdelselect*fromcmmcodewherecodtp='01'"db2"exporttocmmcode.txtofdelmodifiedbycoldel|select*fromcmmcodewherecodtp='01'"三、查詢數據結構及數據:db2"select*frombtpoper"db2"select*frombtpoperwherebrhid='907020000'andoprid='0001'"db2"selectoprid,oprnm,brhid,passwdfrombtpoper"四、刪除表中數據:db2"deletefrombtpoper"db2"deletefrombtpoperwherebrhid='907020000'orbrhid='907010000'"五、修改表中數據:db2"updatesvmmstsetprtlines=0wherebrhid='907010000'andjobtp='02'"db2"updatesvmmstsetprtlines=0wherejobtp='02'orjobtp='03'"六、聯接資料庫db2connecttobtpdbs七、清除資料庫聯接db2connectreset斷開資料庫連接db2terminate斷開資料庫連接db2forceapplicationsall斷開所有資料庫連接八、備份資料庫1、db2backupdbbtpdbs2、db2movebtpdbsexportdb2look-dbtpdbs-e-x[-a]-ocrttbl.sql九、恢復資料庫1、、db2-tvfcrtdb.sqlcrtdb.sql文件內容:createdbbtpdbson/db2catalogdb2-stvfcrttbl.sqldb2movebtpdbsimport十、DB2幫助命令:db2?db2?restroedb2?sqlcode(例:db2?sql0803)註:code必須為4位數,不夠4位,前面補0十一、bind命令:將應用程序與資料庫作一捆綁,每次恢復資料庫後,建議都要做一次bind(1)db2bindbr8200.bnd(2)/btp/bin/bndall/btp/bnd/btp/bin/bndall/btp/tran/bnd十二、查看資料庫參數:十三、修改資料庫參數:ILSIZ5120改完後,應執行以下命令使其生效:db2stopdb2start補充:db2setschemabtp修改當前模式為"btp"db2listtablespacesshowdetail查看當前資料庫表空間分配狀況查看tablespaceid=2使用容器所在目錄列出所有資料庫db2listactivedatabases列出所有活動的資料庫db2listtablesforall列出當前資料庫下所有的表db2listtablesforschemabtp列出當前資料庫中schema為btp的表db2listtablespacesshowdetail顯示資料庫空間使用情況db2listpackagesforalldb2"importfromtab76."db2"createtableachact_tlikeachact"db2"renametableachact_ttoachact"db2"insertintoachact_tselect*fromachactwheretxndt>=(=achact.actno)"刪除一個實例:#cd/usr/lpp/db2_07_01/instance#./db2idropInstName列出所有DB2實例:#cd/usr/lpp/db2_07_01/bin#./db2ilist為資料庫建立編目$db2catalogdbbtpdbson/db2catalog取消已編目的資料庫btpdbs$db2uncatalogdbbtpdbs查看版本#db2level顯示當前資料庫管理實例$db2getinstance設置實例系統啟動時是否自動啟動。$db2iauto-on自動啟動$db2iauto-off不自動啟動資料庫優化命令:reorg、runstats當資料庫經過一段時間使用,數據空間會變得越來越龐大。一些delete掉的數據仍存放在資料庫中,佔用數據空間,影響系統性能。因此需要定期運行reorg、runstats命令,清除已delete的數據,優化數據結構。db2reorgtable表名db2runstatsontable表名withdistributionandindexesall因為要優化的表比較多,所以在/btp/bin目錄下提供了一個sh程序runsall,可在當天業務結束後,運行runsall,對資料庫進行優化在DB2的開發過程中,貫穿整個開發過程還有很重要的一部分工作就是資料庫的維護;對於維護一個龐大信息系統來說是非常必要的;留一份簡易的維護手冊,以備不時之需;以下收集到的部分維護命令,以饗我們的維護工程師和項目經理。=================================================================38、更改db2日誌空間的大小備註:以下命令為了防止db2資料庫過份使用硬碟空間而設,僅用於開發者自己機器上的db2,如果是伺服器,則參數需要修改。#;如果頁大小是4KB,則以上命令創建3個100M的日誌文件,佔用300MB硬碟空間。25600*4KB=102400KB。39、創建臨時表空間#SING(FILE'D:\DB2_TAB\STMASPACE.F1'10000)EXTENTSIZE25640、創建表空間rem創建緩沖池空間8K#db2connecttogather#創建表空間:STMArem必須確認路徑正確remD:\DB2Container\Stma#db2droptablespacestma#('D:\DB2Container\Stma')EXTENTSIZE8OVERHEAD10.5PREFETCHSIZE8TRANSFERRATE0.#db2connectreset41、將暫掛的數據恢復到前滾狀態#、備份表空間#BACKUPDATABASEYNDCTABLESPACE(USERSPACE1)TO"D:\temp"、創建db2工具資料庫#、如何進行增量/差量備份增量:上一次完整備份至本次備份之間增加的數據部分;差量(delta):上次備份以來(可能是完整備份、增量備份或者差量備份)至本次備份之間增加的數據部分;45、更新所有表的統計信息#db2-vconnecttoDB_NAME#db2-v"selecttbname,nleaf,nlevels,stats_timefromsysibm.sysindexes"#db2-#db2-v"selecttbname,nleaf,nlevels,stats_timefromsysibm.sysindexes"#db2-vterminate46、對一張表運行統計信息#db2-vrunstatsontableTAB_NAMEandindexesall47、查看是否對資料庫執行了RUNSTATS#db2-v"selecttbname,nleaf,nlevels,stats_timefromsysibm.sysindexes"48、更改緩沖池的大小緩沖池中,當syscat.bufferpools的npages是-1時,由資料庫的配置參數bufferpage控制緩沖池的大小。將npages的值更改為-1的命令:#db2-vconnecttoDB_NAME#db2-vselect*fromsyscat.bufferpools#db2--1#db2-vconnectreset#db2-vterminate更改資料庫配置參數BufferPages的命令如下:#db2-_value#db2-vterminate49、看資料庫監視內容列表#db2-vgetmonitorswitches50、打開某個資料庫監視內容#db2-、獲取資料庫快照#db2-vgetsnapshotforalldatabases>snap.out#db2-vgetsnapshotfordbm>>snap.out#db2-vgetsnapshotforallbufferpools>>snap.out#db2-vterminate52、重置資料庫快照#db2-vresetmonitorall53、計算緩沖池命中率理想情況下緩沖池命中率在95%以上,計算公式如下:(1-((bufferpooldataphysicalreads+bufferpoolindexphysicalreads)/(bufferpooldatalogicalreads+poolindexlogicalreads)))*100%=========資料庫實例========================54、創建db2實例#db2icrt55、刪除db2實例#db2idrop56、設置當前db2實例#setdb2intance=db257、顯示db2擁有的實例#db2ilist58、恢復離線增量備份資料庫的命令#:\backup\autobak\db2TAKENAT2006031423201559、創建樣本資料庫在unix平台,使用:#sqllib/bin/db2sampl在windows,os/2平台,使用:db2sample,e是可選參數,指定將創建資料庫的驅動器60、設置聯合資料庫為可用(默認聯合資料庫不可用)#、列出資料庫中所有的表#db2listtables62、數據遷移方法1export腳本示例##db2"exporttoaa1.ixfofixfselect*fromtable1"#db2"exporttoaa2.ixfofixfselect*fromtable2"#db2connectresetimport腳本示例##db2"loadfromaa1."#db2"loadfromaa2."#db2connectreset
⑵ 想從事銀行方面的c語言開發,他上面還要了解db2資料庫的常用操作
1、 打開命令行窗口
#db2cmd
2、 打開控制中心
# db2cmd db2cc
3、 打開命令編輯器
db2cmd db2ce
=====操作資料庫命令=====
4、 啟動資料庫實例
#db2start
5、 停止資料庫實例
#db2stop
如果你不能停止資料庫由於激活的連接,在運行db2stop前執行db2 force application all就可以了 /db2stop force
6、 創建資料庫
#db2 create db [dbname]
7、 連接到資料庫
#db2 connect to [dbname] user [username] using [password]
8、 斷開資料庫連接
#db2 connect reset
9、 列出所有資料庫
#db2 list db directory
10、 列出所有激活的資料庫
#db2 list active databases
11、 列出所有資料庫配置
#db2 get db cfg
12、 刪除資料庫
#db2 drop database [dbname]
(執行此操作要小心)
如果不能刪除,斷開所有資料庫連接或者重啟db2
=========操作數據表命令==========
13、 列出所有用戶表
#db2 list tables
14、列出所有系統表
#db2 list tables for system
15、列出所有表
#db2 list tables for all
16、 列出系統表
#db2 list tables for system
17、列出用戶表
#db2 list tables for user
18、 列出特定用戶表
#db2 list tables for schema [user]
19、 創建一個與資料庫中某個表(t2)結構相同的新表(t1)
#db2 create table t1 like t2
20、 將一個表t1的數據導入到另一個表t2
#db2 "insert into t1 select * from t2"
21、 查詢表
#db2 "select * from table name where ..."
22、 顯示表結構
#db2 describe table tablename
23、 修改列
#db2 alter table [tablename] alter column [columname] set data type varchar(24)
======腳本文件操作命令=======
24、 執行腳本文件
#db2 -tvf scripts.sql
25、幫助命令
* 查看命令幫助
#db2 ? db2start
* 查看錯誤碼信息
#db2 ? 22001
* memo: 詳細命令請使用"db2 ? <command>"進行查看。
=========================
26、備份資料庫
#db2 backup db <db name>
備註:執行以上命令之前需要斷開資料庫連接
27、在線備份資料庫
#db2 -v "BACKUP DATABASE <database name> ONLINE TO <path> WITH 2 BUFFERS BUFFER 1024 INCLUDE LOGS WITHOUT PROMPTING"
28、恢復資料庫
#db2 restore db <source db name>
29、在線恢復資料庫
#db2 "RESTORE DB <database name> TO <db path> LOGTARGET <logpath> WITHOUT PROMPTING"
#db2 "ROLLFORWARD DB <database name> TO END OF LOGS AND STOP" ...
30、導出數據文件
#db2move <db name> export
[-sn <模式名稱,一般為db2admin>]
[-tn <表名,多個之間用逗號分隔>]
31、導入數據文件
#db2move <db name> import
32、獲取db2資料庫管理配置環境信息
#db2 get dbm cfg
33、.獲取db2某個資料庫資料庫管理配置環境信息
#db2 get db cfg for <db name>
或者:連接至某個資料庫以後執行db2 get db cfg
34、更改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。
35、創建臨時表空間
#DB2 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32 K MANAGED BY DATABASE USING (FILE 'D:\DB2_TAB\STMASPACE.F1' 10000)
EXTENTSIZE 256
36、獲取資料庫管理器的快照數據
#db2 –v get snapshot for dbm
37、顯示進行程號
#db2 list applications show detail
===================================================
一、載入數據:
1、 以默認分隔符載入,默認為「,」號
db2 "import from btpoper.txt of del insert into btpoper"
2、 以指定分隔符「|」載入
db2 "import from btpoper.txt of del modified by coldel| insert into btpoper"
二、卸載數據:
1、 卸載一個表中全部數據
db2 "export to btpoper.txt of del select * from btpoper"
db2 "export to btpoper.txt of del modified by coldel| select * from btpoper"
2、 帶條件卸載一個表中數據
db2 "export to btpoper.txt of del select * from btpoper where brhid='907020000'"
db2 "export to cmmcode.txt of del select * from cmmcode where codtp='01'"
db2 "export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp='01'"
三、查詢數據結構及數據:
db2 "select * from btpoper"
db2 "select * from btpoper where brhid='907020000' and oprid='0001'"
db2 "select oprid,oprnm,brhid,passwd from btpoper"
四、刪除表中數據:
db2 "delete from btpoper"
db2 "delete from btpoper where brhid='907020000' or brhid='907010000'"
五、修改表中數據:
db2 "update svmmst set prtlines=0 where brhid='907010000' and jobtp='02'"
db2 "update svmmst set prtlines=0 where jobtp='02' or jobtp='03'"
六、聯接資料庫
db2 connect to btpdbs
七、清除資料庫聯接
db2 connect reset 斷開資料庫連接
db2 terminate 斷開資料庫連接
db2 force applications all 斷開所有資料庫連接
八、備份資料庫
1、 db2 backup db btpdbs
2、 db2move btpdbs export
db2look -d btpdbs -e -x [-a] -o crttbl.sql
九、恢復資料庫
1、 db2 restore db btpdbs without rolling forward
2、 db2 -tvf crtdb.sql
crtdb.sql文件內容:create db btpdbs on /db2catalog
db2 -stvf crttbl.sql
db2move btpdbs import
十、DB2幫助命令:
db2 ?
db2 ? restroe
db2 ? sqlcode (例:db2 ? sql0803) 註:code必須為4位數,不夠4位,前面補0
十一、bind命令:將應用程序與資料庫作一捆綁,每次恢復資料庫後,建議都要做一次bind
(1) db2 bind br8200.bnd
(2) /btp/bin/bndall /btp/bnd
/btp/bin/bndall /btp/tran/bnd
十二、查看資料庫參數:
db2 get dbm cfg
db2 get db cfg for btpdbs
十三、修改資料庫參數:
db2 update db cfg for btpdbs using LOGBUFSZ 20
db2 update db cfg for btpdbs using LOGFILSIZ 5120
改完後,應執行以下命令使其生效:
db2 stop
db2 start
補充:
db2 set schema btp 修改當前模式為"btp"
db2 list tablespaces show detail 查看當前資料庫表空間分配狀況
db2 list tablespace containers for 2 show detail 查看tablespace id=2使用容器所在目錄
db2 list application
db2 list db directory 列出所有資料庫
db2 list active databases 列出所有活動的資料庫
db2 list tables for all 列出當前資料庫下所有的表
db2 list tables for schema btp 列出當前資料庫中schema為btp的表
db2 list tablespaces show detail 顯示資料庫空間使用情況
db2 list packages for all
db2 "import from tab76.ixf of ixf commitcount 5000 insert into achact"
db2 "create table achact_t like achact"
db2 "rename table achact_t to achact"
db2 "insert into achact_t select * from achact where txndt>=(select lstpgdt from
acmact where actno=achact.actno)"
db2 get snapshot for dynaimic sql on jining
刪除一個實例:
# cd /usr/lpp/db2_07_01/instance
# ./db2idrop InstName
列出所有DB2實例:
# cd /usr/lpp/db2_07_01/bin
# ./db2ilist
為資料庫建立編目
$ db2 catalog db btpdbs on /db2catalog
取消已編目的資料庫btpdbs
$ db2 uncatalog db btpdbs
查看版本
# db2level
顯示當前資料庫管理實例
$ db2 get instance
設置實例系統啟動時是否自動啟動。
$ db2iauto -on 自動啟動
$ db2iauto -off 不自動啟動
資料庫優化命令:
reorg、runstats
當資料庫經過一段時間使用,數據空間會變得越來越龐大。一些delete掉
的數據仍存放在資料庫中,佔用數據空間,影響系統性能。因此需要定期
運行reorg、runstats命令,清除已delete的數據,優化數據結構。
db2 reorg table 表名
db2 runstats on table 表名 with distribution and indexes all
因為要優化的表比較多,所以在/btp/bin目錄下提供了一個sh程序runsall,
可在當天業務結束後,運行runsall,對資料庫進行優化
在DB2的開發過程中,貫穿整個開發過程還有很重要的一部分工作就是資料庫的維護;對於維護一個龐大信息系統來說是非常必要的;留一份簡易的維護手冊,以備不時之需;以下收集到的部分維護命令,以饗我們的維護工程師和項目經理。
=================================================================
38、更改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。
39、創建臨時表空間
#DB2 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32 K MANAGED BY DATABASE USING (FILE 'D:\DB2_TAB\STMASPACE.F1' 10000) EXTENTSIZE 256
40、創建表空間
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
41、將暫掛的數據恢復到前滾狀態
#db2 ROLLFORWARD DATABASE TESTDB TO END OF LOGS AND COMPLETE NORETRIEVE
42、備份表空間
#BACKUP DATABASE YNDC TABLESPACE ( USERSPACE1 ) TO "D:\temp" WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING
43、創建db2工具資料庫
#db2 create tools catalog systools create new database toolsdb
44、如何進行增量/差量備份
增量:上一次完整備份至本次備份之間增加的數據部分;
差量(delta):上次備份以來(可能是完整備份、增量備份或者差量備份)至本次備份之間增加的數據部分;
45、更新所有表的統計信息
#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
46、對一張表運行統計信息
#db2 -v runstatson table TAB_NAMEand indexes all
47、查看是否對資料庫執行了RUNSTATS
#db2 -v "select tbname, nleaf, nlevels,stats_timefrom sysibm.sysindexes"
48、更改緩沖池的大小
緩沖池中,當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
49、看資料庫監視內容列表
#db2 -v get monitor switches
50、打開某個資料庫監視內容
#db2 -v update monitor switches using bufferpoolon
51、獲取資料庫快照
#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
52、重置資料庫快照
#db2 -v reset monitor all
53、計算緩沖池命中率
理想情況下緩沖池命中率在95%以上,計算公式如下:
(1 -((buffer pool data physical reads + buffer pool index physical reads)
/(buffer pool data logical reads + pool index logical reads))) *100%
=========資料庫實例========================
54、創建db2實例
#db2icrt <實例名稱>
55、刪除db2實例
#db2idrop <實例名稱>
56、設置當前db2實例
#set db2intance=db2
57、顯示db2擁有的實例
#db2ilist
58、恢復離線增量備份資料庫的命令
#DB2 RESTORE DATABASE YNDC INCREMENTAL AUTOMATIC FROM D:\backup\autobak\db2 TAKEN AT 20060314232015
59、創建樣本資料庫
在unix平台,使用:
#sqllib/bin/db2sampl <path>
在windows,os/2平台,使用:db2sampl e,e是可選參數,指定將創建資料庫的驅動器
60、設置聯合資料庫為可用(默認聯合資料庫不可用)
#db2 update dbm cfg using federated yes
61、列出資料庫中所有的表
#db2 list tables
62、數據遷移方法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
⑶ DB2資料庫在linux操作系統的指令有哪些
DB2資料庫命令簡介 1.啟動資料庫 DB2start 2.停止資料庫 DB2stop DB2資料庫在linux相關指令之3.連接資料庫 DB2 connect to o_yd user DB2 using pwd 4.讀資料庫管理程序配置 DB2 get dbm cfg 5.寫資料庫管理程序配置 DB2 update dbm cfg using 參數名 參數值 6.讀資料庫的配置 DB2 connect to o_yd user DB2 using pwd DB2 get db cfg for o_yd 7.寫資料庫的配置 DB2 connect to o_yd user DB2 using pwd DB2 update db cfg for o_yd using 參數名 參數值 8.關閉所有應用連接 DB2 force application all DB2 force application ID1,ID2,,,Idn MODE ASYNC (DB2 list application for db o_yd show detail) 9.備份資料庫 DB2 force application all DB2 backup db o_yd to d: (DB2 initialize tape on \.tape0) (DB2 rewind tape on \.tape0) DB2 backup db o_yd to \.tape0 10.恢復資料庫 DB2 restore db o_yd from d: to d: DB2 restore db o_yd from \.tape0 to d: DB2資料庫在linux相關指令之11.綁定存儲過程 DB2 connect to o_yd user DB2 using pwd DB2 bind c:dfplus.bnd 拷貝存儲過程到伺服器上的C:sqllibfunction目錄中 12.整理表 DB2 connect to o_yd user DB2 using pwd DB2 reorg table ydd DB2 runstats on table ydd with distribution and indexes all 13.導出表數據 DB2 export to c:dftz.txt of del select * from dftz DB2 export to c:dftz.ixf of ixf select * from dftz 14.導入表數據 import from c:123.txt of del insert into ylbx.czyxx DB2 import to c:dftz.txt of del commitcount 5000 messages c:dftz.msg insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 messages c:dftz.msg insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 insert_update into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 replace into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 create into dftz (僅IXF) DB2 import to c:dftz.ixf of ixf commitcount 5000 replace_create into dftz (僅IXF) 15.執行一個批處理文件 DB2 -tf 批處理文件名 (文件中每一條命令用 ;結束) 16.自動生成批處理文件 建文本文件:temp.sql select 'runstats on table DB2.' || tabname || ' with distribution and detailed indexes all;' from syscat.tables where tabschema='DB2' and type='T'; DB2 -tf temp.sql>runstats.sql 17.自動生成建表(視圖)語句 在伺服器上:C:sqllibmisc目錄中 DB2 connect to o_yd user DB2 using pwd DB2look -d o_yd -u DB2 -e -p -c c:o_yd.txt DB2資料庫在linux相關指令之18.其他命令 grant dbadm on database to user bb 19select * from czyxx fetch first 1 rows only 20DB2look -d ylbx -u DB2admin -w -asd -a -e -o a.txt21. 顯示當前用戶所有表 list tables 22.列出所有的系統表 list tables for system 23.查看錶結構 DB2 describe select * from user.tables (實習編輯:HJ)
⑷ db2 版本9,建立索引能否指定表空間
這個要看是非分區索引,還是分區索引了。
如果是非分區索引:表索引建的時候是可以指定其表空間的,可以使用「 CREATE INDEX … ON … IN <tablespace> 」語法將索引放到不同的表空間中。若未指定索引表空間默認和表所在表空間一致。想修改要重建索引了。
如果是分區索引:對於分區索引,不允許在創建索引時指定「 IN <tablespace> 」子句,這是因為分區索引的特性,每個索引分區的存放位置取決於創建分區表時分區級「 INDEX IN <tablespace> 」子句,如果某個數據分區沒有指定該字句,則相應的索引分區將存放在與數據分區相同的表空間中。想修改要重新定義分區表的索引表空間。
⑸ db2的sqc文件里怎麼連接資料庫
1.首先把自己編輯好的SQC文件(如:test.sqc)放在指定的目錄下。
2.正式開始編譯前,需要和DB2資料庫(如:TESTDB)建立連接。
以linux環境為例,在命令行狀態下,輸入:db2
connect
to
TESTDB
3.調用DB2的prep命令對SQC文件進行預編譯,用來生成C文件。
在命令行狀態下,輸入:db2
prep
test.sqc
BINDFILE
package
using
bindtest
說明:
上述命令中的「BINDFILE」是用來指定在做預編譯的同時生成bind文件的(如:bindtest.bnd)
上述命令中的「package
using
bindtest」是用來指定將要寫入到DB2的系統表中的package信息的名稱(如:bindtest)。
bind文件里記載的是用來寫入到package信息的數據。
4.調用DB2的bind
命令從上一步生成的bind文件中讀出必要的數據寫入到上一步指定名稱的package信息中。
並可以給這條信息指定訪問許可權。
以linux環境為例,在命令行狀態下,輸入:db2
bind
ConnTEST.bnd
GRANT
PUBLIC
5.到目前為止可以說與DB2相關的所有預編譯就基本完成了,我們需要的C文件(如:test.c)也整成生成了,那個bind文件後邊暫時不會用到了。
下來就可以調用CC或GCC之類的C代碼編譯器對這個C文件進行編譯,基本的過程是test.c→test.o→test。這樣我們就可以執行這個最終的可實行程序了。
⑹ IBM DB2的編譯過程
先進行預編譯,將COBOL程序與DB2程序分開然後編譯COBOL,和DB2程序,生成DBRM與正常的COBOL的OBJECT。最後鏈接COBOL與生成DB2的plan
⑺ 怎麼在linux上咱裝DB2
我網上復制來的,可以稍微看下,其實DB2也有安裝腳本的
安裝DB2
DB2的安裝可以算是再各個資料庫裡面最簡單的了。除了sqlite。
下載安裝包,解壓
[root@Enterprise tmp]# tar xvf DB2_V82_PE_LNX_32_NLV.tar
解開以後的文件都被放置在當前目錄下的pe文件夾中。
開始安裝:
[root@Enterprise tmp]# cd pe
[root@Enterprise pe]# ls
db2 db2_deinstall db2_install db2setup doc
[root@Enterprise pe]# ./db2_install
Specify one or more of the following keywords,
separated by spaces, to install DB2 procts.
選擇自己要安裝的產品,輸入名字後回車。等待安裝完成。
我們現在需要做的是,對資料庫的初始化工作。包括安裝授權文件和創建一個實例並運行它。
首先,我們安裝授權文件。
不安裝授權文件的話,則是評估版,九十天後就要過期。授權文件,在安裝包已經有了。我們用下面的命令安裝它:
[root@Enterprise pe]# /opt/IBM/db2/V8.2/adm/db2licm -a /tmp/pe/db2/lic
ense/db2pe.lic
如果沒有db2pe.lic 文件。可以去網上找找。
我們需要創建一個用戶。
[root@Enterprise pe]# useradd db2inst1
[root@Enterprise pe]# passwd db2inst1
開始創建實例:
[root@Enterprise pe]# /opt/IBM/db2/V8.2/instance/db2icrt -u db2inst1 db2inst1
這樣,我們就創建了一個實例db2ins1。
[root@Enterprise pe]# su db2inst1
[db2inst1@Enterprise pe]$ db2start
07/26/2007 16:45:10 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
這樣我們資料庫就啟動成功。
[db2inst1@Enterprise pe]$ db2
(c) Copyright IBM Corporation 1993,2002
Command Line Processor for DB2 SDK 8.2.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 =>
創建一個最簡單的資料庫
db2 => create database testdb
DB20000I The CREATE DATABASE command completed successfully.
查看本instance下有哪些database
db2 => list database directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = TESTDB
Database name = TESTDB
Local database directory = /home/db2inst1
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = OMNIDB
Database name = OMNIDB
Local database directory = /home/db2inst1/data
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
⑻ DB2批量更新報錯: 找不到程序包 "NULLID.SYSLH203 0X5359534C564C3031"
今天所做的程序最後封版,封版前覺得程序有一個地方讓我很不爽,於是就進行了一下修改,改動其實很小,只是在if裡面增加了一個判斷條件,結果程序運行的時候開始報資料庫系統錯誤,錯誤內容如下:
[DB2/NT] SQL0805N 找不到程序包 "NULLID.SYSLH203 0X5359534C564C3031"。 SQLSTATE=51002
到網上查找錯誤的原因,結果關於這方面的內容少之又少,Google中只找到兩個網頁,裡面倒是提供了解決方案,不過原因不是很詳細。繼續搜索,最後在IBM官方網站上找到一個還算清楚的解釋:
Solution
Depending on the type of statement you are executing, DB2 will use a particular package on the server. By default, DB2 creates three packages for each type of package. In this case NULLID.SYSLH2yy is reserved for statements with CURSORHOLD on and isolation level Cursor Stability. The package SYSLH203 means that DB2 is looking for the 4th package (200 is first, 201 is second, etc) of this type, but it does not exist. You can create more packages on the server by connecting to the database and issuing the following bind command from the /sqllib/bnd directory:
db2 bind @db2cli.lst blocking all grant public sqlerror continue CLIPKG 5
Note: CLIPKG 5 will create 5 large packages, and will give you the package that your application is looking for, as well as one more in this case.
源文檔 <http://www-1.ibm.com/support/docview.wss?uid=swg21208123>
大致的意思是說DB2在執行SQL語句的時候會使用內部定義的包(package)來保持不同級別的游標的穩定性,包的名字就是「NULLID.SYSLH2XX」。DB2裡面默認的時候會創建3個這樣的包即SYSLH200, SYSLH201, SYSLH202,而當你的程序報「找不到程序包」的錯誤,並且程序包的名字的序號大於SYSLH202,也就說明DB2默認的包不夠用了,DB2要求使用更多的包,但是這些包在DB2中並沒有創建,因此DB2拋出了異常。
要解決這個錯誤有兩種方法:一是執行上面的英文段中的粗體部分的命令,把DB2的包的個數擴大到5個,這樣DB2就可以找到它需要的包;二是調整你的程序,優化結構,使得DB2不會用到多於3個的包,當然,這將會使你經歷一個非常艱難的調試時刻。
至於我嗎,由於是在封版時刻,自然選擇最簡單的處理方式——把錯誤的地方再改回來,雖然有點取巧,但是至少不會產生對資料庫修改的需求 :-)
⑼ C語言db2嵌入式SQL編程,編譯問題 undefined reference to `sqlastrt'
1、要有類似的定義:
……
EXEC SQL INCLUDE SQLDA; /* or #include <sqlda.h> */
2、編譯環境要有db2的許可權和sqllib的路徑
3、我已經上傳了一份相關的文檔,預計明後天審核通過就可以看到了
《DB2開發基礎》
http://passport..com/?business&aid=6&un=chinacmouse#7
補充一個程序:
#include <time.h>
#include "stdio.h"
EXEC SQL INCLUDE SQLCA;
int main()
{
int i=0;
struct tm *pt;
time_t t1;
t1 = time(NULL);
pt = localtime(&t1);
printf("%4d%02d%02d", pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday);
printf("%02d:%02d:%02d\n",pt->tm_hour,pt->tm_min,pt->tm_sec);
EXEC SQL CONNECT TO db;
i=0;
while (i<3000)
{
int j=0;
while (j<1000)
{
EXEC SQL update cc.fund set cc_code='095' where cc_no='0950031359';
j++;
}
i++;
}
EXEC SQL COMMIT;
t1 = time(NULL);
pt = localtime(&t1);
printf("%4d%02d%02d", pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday);
printf("%02d:%02d:%02d\n",pt->tm_hour,pt->tm_min,pt->tm_sec);
EXEC SQL CONNECT RESET;
return 1;
}
編譯腳本:
db2 prep testdb.sqc target cplusplus bindfile using testdb.bnd package using testdb
db2 bind testdb.bnd
db2 grant execute on package testdb to public
gcc -I/app/db2inst1/sqllib/include -I./ -c -g testdb.C
gcc -L/app/db2inst1/sqllib/lib -ldb2 -L/usr/lib -lm -o testdb testdb.o
⑽ db2存儲過程中調用sysproc.admin_cmd('reorg table xx.tb ')時報錯
幫一下包試試?
db2 terminate
db2 CONNECT TO dbname user USERID using PASSWORD
db2 BIND path\db2schema.bnd BLOCKING ALL GRANT PUBLIC SQLERROR CONTINUE
db2 BIND path\@db2ubind.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 BIND path\@db2cli.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 terminate
where dbname represents the name of a database to which the files should be bound, and where path is the full path name of the directory where the bind files are located, such as INSTHOME\sqllib\bnd where INSTHOME represents the home directory of the DB2 instance. db2ubind.lst and db2cli.lst contain lists of required bind files used by DB2 database procts. Packages that are already bound will return an SQL0719N error. This is expected.