新聞中心
在數(shù)據(jù)庫(kù)管理和維護(hù)過(guò)程中,回滾命令是一種非常重要的指令。在數(shù)據(jù)出現(xiàn)異常時(shí),回滾命令可以將數(shù)據(jù)庫(kù)恢復(fù)到之前的有效狀態(tài)。這樣就能夠保證數(shù)據(jù)的完整性和可靠性。DB2作為一款流行的數(shù)據(jù)庫(kù)管理系統(tǒng),在數(shù)據(jù)備份和維護(hù)方面也非常實(shí)用,下面介紹如何使用db2查看數(shù)據(jù)庫(kù)回滾命令。

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的牟平網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
一、什么是DB2數(shù)據(jù)庫(kù)回滾命令?
DB2數(shù)據(jù)庫(kù)回滾命令是一種事務(wù)控制命令,它用于撤消之前提交的事務(wù)并將數(shù)據(jù)庫(kù)恢復(fù)到之前的狀態(tài)。當(dāng)數(shù)據(jù)操作錯(cuò)誤時(shí),可以使用回滾命令抵消彼此之間的影響,回滾命令主要用于以下方面:
1.恢復(fù)到錯(cuò)誤操作之前的狀態(tài)。
2.回滾由于錯(cuò)誤操作引起的數(shù)據(jù)鎖定。
3.在修改較大數(shù)據(jù)時(shí),避免出現(xiàn)錯(cuò)誤或異常導(dǎo)致丟失數(shù)據(jù)。
二、DB2數(shù)據(jù)庫(kù)回滾命令的語(yǔ)法格式
根據(jù)不同的場(chǎng)景,DB2數(shù)據(jù)庫(kù)回滾命令也有不同的語(yǔ)法格式,以下展示了回滾命令的三種不同方式:
1. 回滾到保存點(diǎn):
ROLLBACK TO SAVEPOINT ;
2. 回滾到之前的事務(wù):
ROLLBACK WORK;
3. 回滾到指定時(shí)間點(diǎn):
ROLLBACK TO TIMESTAMP ;
三、使用DB2查看數(shù)據(jù)庫(kù)的回滾命令
使用DB2查看數(shù)據(jù)庫(kù)回滾命令可以快速定位到回滾的時(shí)間點(diǎn),以此進(jìn)行相應(yīng)的恢復(fù)操作。這里介紹兩種常見(jiàn)的查看命令。
1. 通過(guò)命令行查看數(shù)據(jù)庫(kù)的恢復(fù)記錄
首先需要進(jìn)入命令行模式,使用以下命令進(jìn)入:
db2 connect to ;
然后可以使用以下命令查看應(yīng)用程序處理的恢復(fù)記錄。
db2 list history backup all for database ;
該命令可以列出與數(shù)據(jù)庫(kù)相關(guān)的所有恢復(fù)記錄,包括備份,修復(fù)和回滾到指定時(shí)間點(diǎn)。
2. 通過(guò)DB2控制中心查看數(shù)據(jù)庫(kù)回滾命令
DB2控制中心是一款方便的GUI工具,可以方便地通過(guò)圖形化界面來(lái)查看數(shù)據(jù)庫(kù)回滾命令。首先要打開(kāi)DB2控制中心,進(jìn)入數(shù)據(jù)庫(kù)管理界面,然后選擇需要查看的數(shù)據(jù)庫(kù),找到“恢復(fù)歷史記錄”選項(xiàng),并選擇“全部恢復(fù)歷史記錄”以查看所有回滾命令。
四、
相關(guān)問(wèn)題拓展閱讀:
- 如何在Windows CMD里面用命令行操作DB2數(shù)據(jù)庫(kù)
- 關(guān)于數(shù)據(jù)庫(kù)的回滾
- DB數(shù)據(jù)庫(kù)在linux操作系統(tǒng)的指令有哪些?
如何在Windows CMD里面用命令行操作DB2數(shù)據(jù)庫(kù)
db2 cmd命令操作
1、 打開(kāi)命令行窗口
#db2cmd
2、 打開(kāi)控制中心
www.2cto.com
# db2cmd db2cc
3、 打開(kāi)命令編輯器
db2cmd db2ce
=====操作數(shù)據(jù)庫(kù)命令=====
4、 啟動(dòng)數(shù)據(jù)庫(kù)實(shí)例
#db2start
5、 停止數(shù)據(jù)庫(kù)實(shí)例
#db2stop
如果你不能停止數(shù)據(jù)庫(kù)由于激活的連接,在運(yùn)行db2stop前執(zhí)行db2 force application all就可以了 /db2stop force
6、 創(chuàng)建數(shù)據(jù)庫(kù)
#db2 create db
7、 連接到數(shù)據(jù)庫(kù)
www.2cto.com
#db2 connect to user using
8、 斷開(kāi)數(shù)據(jù)庫(kù)連接
#db2 connect reset
9、 列出所有數(shù)據(jù)庫(kù)
#db2 list db directory
10、 列出所有激活的數(shù)據(jù)庫(kù)
#db2 list active databases
11、 列出所有數(shù)據(jù)庫(kù)配置
#db2 get db cfg
12、 刪除數(shù)據(jù)庫(kù)
#db2 drop database
(執(zhí)行此操作要小心)
如果不能刪除,斷開(kāi)所有數(shù)據(jù)庫(kù)連接或者重啟db2
=========操作數(shù)據(jù)表命令==========
13、 列出所有用戶表
#db2 list tables
14、列出所有系統(tǒng)表
#db2 list tables for system
15、列出所有表
#db2 list tables for all
16、 列出系統(tǒng)表
#db2 list tables for system
17、列出用戶表
#db2 list tables for user
18、 列出特定用戶表
#db2 list tables for schema
19、 創(chuàng)建一個(gè)與數(shù)據(jù)庫(kù)中某個(gè)表(t2)結(jié)構(gòu)相同的新表(t1)
#db2 create table t1 like t2
20、 將一個(gè)表t1的數(shù)據(jù)導(dǎo)入到另一個(gè)表t2
#db2 “insert into t1 select * from t2”
21、 查詢表
#db2 “select * from table name where …”
22、 顯示表結(jié)構(gòu)
#db2 describe table tablename
23、 修改列
#db2 alter table alter column set data type varchar(24)
======腳本文件操作命令=======
24、 執(zhí)行腳本文件
#db2 -tvf scripts.sql
25、幫助命令
* 查看命令幫助
#db2 ? db2start
* 查看錯(cuò)誤碼信息
#db2 ?
* memo: 詳細(xì)命令請(qǐng)使用”db2 ? “進(jìn)行查看?!?
=========================
26、備份數(shù)據(jù)庫(kù)
#db2 backup db
備注:執(zhí)行以上命令之前需要斷開(kāi)數(shù)據(jù)庫(kù)連接
27、在線備份數(shù)據(jù)庫(kù)
#db2 -v “BACKUP DATABASE ONLINE TO WITH 2 BUFFERS BUFFER 1024 INCLUDE LOGS WITHOUT PROMPTING”
28、恢復(fù)數(shù)據(jù)庫(kù)
#db2 restore db
29、在線恢復(fù)數(shù)據(jù)庫(kù)
#db2 “RESTORE DB TO LOGTARGET WITHOUT PROMPTING”
#db2 “ROLLFORWARD DB TO END OF LOGS AND STOP” …
30、導(dǎo)出數(shù)據(jù)文件
#db2move export
31、導(dǎo)入數(shù)據(jù)文件
#db2move import
32、獲取db2數(shù)據(jù)庫(kù)管理配置環(huán)境信息
#db2 get dbm cfg
33、.獲取db2某個(gè)數(shù)據(jù)庫(kù)數(shù)據(jù)庫(kù)管理配置環(huán)境信息
#db2 get db cfg for
或者:連接至某個(gè)數(shù)據(jù)庫(kù)以后執(zhí)行db2 get db cfg
34、更改db2日志空間的大小
備注:以下命令為了防止db2數(shù)據(jù)庫(kù)過(guò)份使用硬盤(pán)空間而設(shè),僅用于開(kāi)發(fā)者自己機(jī)器上的db2,如果是服務(wù)器,則參數(shù)需要修改。
#db2 UPDATE DB CFG FOR USING logretain OFF logprimary 3 logsecond 2 logfilsiz 25600;
如果頁(yè)大小是4KB,則以上命令創(chuàng)建3個(gè)100M的日志文件,占用300MB硬盤(pán)空間。25600*4KB=102400KB。
35、創(chuàng)建臨時(shí)表空間
#DB2 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32 K MANAGED BY DATABASE USING (FILE ‘D:\DB2_TAB\STMASPACE.F1’ 10000)
EXTENTSIZE 256
36、獲取數(shù)據(jù)庫(kù)管理器的快照數(shù)據(jù)
#db2 –v get snapshot for dbm
37、顯示進(jìn)行程號(hào)
#db2 list applications show detail
===================================================
一、加載數(shù)據(jù):
1、 以默認(rèn)分隔符加載,默認(rèn)為“,”號(hào)
db2 “import from btpoper.txt of del insert into btpoper”
2、 以指定分隔符“|”加載
db2 “import from btpoper.txt of del modified by coldel| insert into btpoper”
二、卸載數(shù)據(jù):
1、 卸載一個(gè)表中全部數(shù)據(jù)
db2 “export to btpoper.txt of del select * from btpoper”
db2 “export to btpoper.txt of del modified by coldel| select * from btpoper”
2、 帶條件卸載一個(gè)表中數(shù)據(jù)
db2 “export to btpoper.txt of del select * from btpoper where brhid=””
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′”
三、查詢數(shù)據(jù)結(jié)構(gòu)及數(shù)據(jù):
db2 “select * from btpoper”
db2 “select * from btpoper where brhid=” and oprid=’0001′”
db2 “select oprid,oprnm,brhid,passwd from btpoper”
四、刪除表中數(shù)據(jù):
db2 “delete from btpoper”
db2 “delete from btpoper where brhid=” or brhid=””
五、修改表中數(shù)據(jù):
db2 “update svmmst set prtlines=0 where brhid=” and jobtp=’02′”
db2 “update svmmst set prtlines=0 where jobtp=’02’ or jobtp=’03′”
六、聯(lián)接數(shù)據(jù)庫(kù)
db2 connect to btpdbs
七、清除數(shù)據(jù)庫(kù)聯(lián)接
db2 connect reset 斷開(kāi)數(shù)據(jù)庫(kù)連接
db2 terminate 斷開(kāi)數(shù)據(jù)庫(kù)連接
db2 force applications all 斷開(kāi)所有數(shù)據(jù)庫(kù)連接
八、備份數(shù)據(jù)庫(kù)
1、 db2 backup db btpdbs
2、 db2move btpdbs export
db2look -d btpdbs -e -x -o crttbl.sql
九、恢復(fù)數(shù)據(jù)庫(kù)
1、 db2 restore db btpdbs without rolling forward
2、 db2 -tvf crtdb.sql
crtdb.sql文件內(nèi)容:create db btpdbs on /db2catalog
db2 -stvf crttbl.sql
db2move btpdbs import
十、DB2幫助命令:
db2 ?
db2 ? restroe
關(guān)于數(shù)據(jù)庫(kù)的回滾
你要保證在一個(gè)事務(wù)中執(zhí)行,才可以回滾。
你每個(gè)命令帶一個(gè)事務(wù),其實(shí)跟沒(méi)有事務(wù)是一樣的,不成功是沒(méi)有回滾的。
START TRANSACTION;
INSERT INTO `guwitest`.`cdn` (`id`, `operatorId`, `type`, `distributionTarget`, `distributionName`, `distributionDomain`, `status`) VALUES (‘1’枝首, ‘猛慎數(shù)孝敏1’, ‘cloudfront’, ‘metadata’, ‘1’, ‘1’, ‘0’);
create table guwitest.aa(id int(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id));
ROLLBACK;
DB數(shù)據(jù)庫(kù)在linux操作系統(tǒng)的指令有哪些?
DB2數(shù)據(jù)庫(kù)命令簡(jiǎn)介 1.啟動(dòng)數(shù)據(jù)庫(kù) DB2start 2.停止數(shù)據(jù)庫(kù) DB2stop DB2數(shù)據(jù)庫(kù)在linux相關(guān)指令之3.連接數(shù)據(jù)庫(kù) DB2 connect to o_yd user DB2 using pwd 4.讀數(shù)據(jù)庫(kù)管理程序配置 DB2 get dbm cfg 5.寫(xiě)數(shù)據(jù)庫(kù)管理程序配置 DB2 update dbm cfg using 參數(shù)名 參數(shù)值 6.讀數(shù)據(jù)庫(kù)的配置 DB2 connect to o_yd user DB2 using pwd DB2 get db cfg for o_yd 7.寫(xiě)數(shù)據(jù)攔旁庫(kù)的配置 DB2 connect to o_yd user DB2 using pwd DB2 update db cfg for o_yd using 參數(shù)名 參數(shù)值 8.關(guān)閉所有應(yīng)用連接 DB2 force application all DB2 force application ID1,ID2,,,Idn MODE ASYNC (DB2 list application for db o_yd show detail) 9.備份數(shù)據(jù)庫(kù) 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.恢復(fù)數(shù)據(jù)庫(kù) DB2 restore db o_yd from d: to d: DB2 restore db o_yd from \.tape0 to d: DB2數(shù)據(jù)庫(kù)在linux相關(guān)指令之11.綁定存儲(chǔ)過(guò)程 DB2 connect to o_yd user DB2 using pwd DB2 bind c:dfplus.bnd 拷貝存儲(chǔ)過(guò)程到服務(wù)器上的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.導(dǎo)出表數(shù)據(jù) DB2 export to c:dftz.txt of del select * from dftz DB2 export to c:dftz.ixf of ixf select * from dftz 14.導(dǎo)入表數(shù)據(jù) 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.執(zhí)行一個(gè)批處理文件 DB2 -tf 批處理文件名 (文件中每一條命令用 ;結(jié)束) 16.自動(dòng)生成批處前衡彎理文件 建文本文件: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.自動(dòng)生成建表(視圖)語(yǔ)句 在服務(wù)器上: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數(shù)據(jù)庫(kù)在linux相關(guān)指令之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. 顯示當(dāng)前用戶所有表 list tables 22.列出所有的系統(tǒng)表 list tables for system 23.查看表結(jié)構(gòu) DB2 describe select * from user.tables (實(shí)習(xí)編輯:HJ)
DB2數(shù)據(jù)庫(kù)命令簡(jiǎn)介
1.啟動(dòng)數(shù)據(jù)庫(kù)
DB2start
2.停止數(shù)據(jù)庫(kù)
DB2stop
DB2數(shù)據(jù)庫(kù)在linux相關(guān)指令之3.連接數(shù)據(jù)庫(kù)
DB2 connect to o_yd user DB2 using pwd
4.讀數(shù)據(jù)庫(kù)管理程序配置
DB2 get dbm cfg
5.寫(xiě)數(shù)據(jù)庫(kù)管理程序配置
DB2 update dbm cfg using 參數(shù)名 參數(shù)值
6.讀數(shù)據(jù)庫(kù)的配置
DB2 connect to o_yd user DB2 using pwd
DB2 get db cfg for o_yd
7.寫(xiě)數(shù)據(jù)庫(kù)的配置
DB2 connect to o_yd user DB2 using pwd
DB2 update db cfg for o_yd using 參數(shù)名 參數(shù)值
8.關(guān)閉所有應(yīng)嘩虛用連接
DB2 force application all
DB2 force application ID1,ID2,,,Idn MODE ASYNC
(DB2 list application for db o_yd show detail)
9.備份數(shù)據(jù)庫(kù)
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.恢復(fù)數(shù)據(jù)庫(kù)
DB2 restore db o_yd from d: to d:
DB2 restore db o_yd from \.tape0 to d:
DB2數(shù)據(jù)庫(kù)在linux相關(guān)指令之11.綁定存儲(chǔ)過(guò)程
DB2 connect to o_yd user DB2 using pwd
DB2 bind c:dfplus.bnd
拷貝存儲(chǔ)過(guò)程到服務(wù)器上的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.導(dǎo)出表數(shù)據(jù)
DB2 export to c:dftz.txt of del select * from dftz
DB2 export to c:dftz.ixf of ixf select * from dftz
14.導(dǎo)入表數(shù)據(jù)
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.執(zhí)行一個(gè)批處理文件
DB2 -tf 批處理文件名
(文件中每一條命令用 ;結(jié)束)
16.自動(dòng)生成批處理文件
建文本文件: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.自動(dòng)生成建表(視圖)語(yǔ)句
在服務(wù)器上: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數(shù)據(jù)庫(kù)在linux相關(guān)指令之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. 顯示當(dāng)前用戶所有表
list tables
22.列出所有的系統(tǒng)表
list tables for system
23.查看表結(jié)構(gòu)
DB2 describe select * from user.tables
db2查看數(shù)據(jù)庫(kù)回滾命令的介紹就聊到這里吧,感謝你花時(shí)間閱讀本站內(nèi)容,更多關(guān)于db2查看數(shù)據(jù)庫(kù)回滾命令,如何使用db2查看數(shù)據(jù)庫(kù)回滾命令?,如何在Windows CMD里面用命令行操作DB2數(shù)據(jù)庫(kù),關(guān)于數(shù)據(jù)庫(kù)的回滾,DB數(shù)據(jù)庫(kù)在linux操作系統(tǒng)的指令有哪些?的信息別忘了在本站進(jìn)行查找喔。
香港服務(wù)器選創(chuàng)新互聯(lián),2H2G首月10元開(kāi)通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)互聯(lián)網(wǎng)服務(wù)提供商,擁有超過(guò)10年的服務(wù)器租用、服務(wù)器托管、云服務(wù)器、虛擬主機(jī)、網(wǎng)站系統(tǒng)開(kāi)發(fā)經(jīng)驗(yàn)。專業(yè)提供云主機(jī)、虛擬主機(jī)、域名注冊(cè)、VPS主機(jī)、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。
本文題目:如何使用db2查看數(shù)據(jù)庫(kù)回滾命令?(db2查看數(shù)據(jù)庫(kù)回滾命令)
鏈接分享:http://m.fisionsoft.com.cn/article/dpspghd.html


咨詢
建站咨詢
