您好,登錄后才能下訂單哦!
[db2inst1@localhost ~]$ db2 list db directory
$ db2 create database test
$ db2 connect to test
l 列出激活的庫
$ db2 list active databases
l 查看表空間
$ db2 list tablespaces
l 列出庫中的表
$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
0 record(s) selected.
l 創建表
$ db2 "create table student(id int,fname varchar(30),age int)"
l 賦予用戶權限
db2 "grant use of tablespace TABLESPACE_TEST to user XXX"
l 向表中插入數據
$ db2 "insert into student values (1,'Tom',22)"
l 查詢表內容
備份指定庫
$ db2 backup db TEST online to /opt/dbbak include logs
如果報:
SQL2413N Online backup is not allowed because the database is not recoverable
or a backup pending condition is in effect.
原因:數據庫在線備份需要啟用歸檔日志功能,剛裝的數據庫是沒有啟用的
備份到null
db2 backup db idsldap online to /dev/null
Backup successful. The timestamp for this backup image is : 20161228092925
增量備份:
/usr/bin/su - db2inst1 -c "db2 backup db FDBKDB61 online incremental use tsm >>/IBM/tsm/db2inst1/FDBKDB61_incbk.log 2>&1"
l 查看歸檔設置
$ db2 get db cfg for test|grep -i LOGARCHMETH
l 設置歸檔路徑
$ db2 update db cfg using logarchmeth2 disk:/opt/dbbak/arch
如果報
SQL1024N A database connection does not exist. SQLSTATE=08003
原因:需要備份數據庫一次,然后在修改主日志文件和此日志文件的歸檔路徑
解決方法:要連接數據庫時要備份一下。
解決方法:(需要離線備份一次,再連接數據庫)
l 顯示應用狀態
$ db2 list applications
l 停掉數據庫應用
$ db2 force applications all
l 再查看應用狀態,無輸出
$ db2 list applications
SQL1611W No data was returned by Database System Monitor.
l 做離線備份
$ db2 backup db TEST to /opt/dbbak
l 生成備份文件和歸檔日志
l 查看備份記錄
> db2adutl query //該命令是TSM集成命令,無TSM環境不能執行
$ db2 list history backup all for test
l 啟動進入庫
$ db2 connect to test
l 再做在線備份,可以進行
$ db2 backup db TEST online to /opt/dbbak include logs
$ db2 drop db test
$ db2 connect to test
SQL1013N The database alias name or database name "TEST" could not be found.
SQLSTATE=42705
$ db2 restore db TEST from /opt/bak taken at 20170123152954
$ db2 restore db test taken at 20160513020408
這時候,連接數據庫,提示:
SQL1117N A connection to or activation of database "TEST" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
在前滾已經過大于或等于 這個 的時間點之前,數據庫 "XXX"
不能脫離前滾暫掛狀態,因為節點 "0" 中包含比指定時間更新的信息
解決辦法:前滾日志
$ db2 rollforward database test to end of logs and complete
如果報:
SQL4970N Rollforward recovery stopped on the database named "TEST" because
the rollforward utility cannot reach the specified stop point (end-of-log or
point-in-time) on the following database partitions: "0".
解決辦法:恢復日志
$ db2 restore db test logs from /opt/dbbak/ taken at 20160513020408 logtarget /opt/dbbak/
復制恢復的歸檔文件
$ cp /opt/dbbak/S0000000.LOG /home/db2inst1/db2inst1/NODE0000/SQL00002/LOGSTREAM0000/LOGSTREAM0000
l 啟動進入數據庫
l 查詢表和數據
數據恢復回來
l 關閉應用和庫
$ db2 force applications all
$ db2stop force
SQL1064N DB2STOP processing was successful.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。