這幾天須要從一個備份集中恢復一個數據庫,恢復後發現問題不少,自己這個備份中可能有存在不完整的log,處理完一個個問題後發現仍是有表損壞,在db2diag中其日誌信息以下,卻是很清楚的看到損壞對象:DB2數據庫壞塊代碼
web
<code type="section" width="100%">sql
<heading refname=Listing 2" type="code">常規表的DDL語句示例</heading>數據庫
2014-04-27-05.06.42.071142-240 I36137A535 LEVEL: Severe
app
PID : 14680376 TID : 13881 PROC : db2sysc 0
INSTANCE: db2rilo NODE : 000 DB : WEB
APPHDL : 0-40 APPID: 9.32.130.62.37608.140427090600
AUTHID : DEVPRCBK
EDUID : 13881 EDUNAME: db2agent (WEB) 0
FUNCTION: DB2 UDB, data management, sqldFetchDirect, probe:4603
RETCODE : ZRC=0x87040001=-2029780991=SQLD_BADPAGE "Bad Data Page"
DIA8500C A data file error has occurred, record id is "".
2014-04-27-05.06.42.071901-240 I36673A555 LEVEL: Severe
PID : 14680376 TID : 13881 PROC : db2sysc 0
INSTANCE: db2rilo NODE : 000 DB : WEB
APPHDL : 0-40 APPID: 9.32.130.62.37608.140427090600
AUTHID : DEVPRCBK
EDUID : 13881 EDUNAME: db2agent (WEB) 0
FUNCTION: DB2 UDB, trace services, sqlt_logerr_string (secondary logging fu, probe:0
MESSAGE : TABLESPACE ATTRIBUTES:
DATA #1 : String, 73 bytes
Tablespace Seed = 5, Bufferpool ID = 7, Extent Size = 16, Page Size = 8k
2014-04-27-05.06.42.072336-240 I37229A535 LEVEL: Severe
PID : 14680376 TID : 13881 PROC : db2sysc 0
INSTANCE: db2rilo NODE : 000 DB : WEB
APPHDL : 0-40 APPID: 9.32.130.62.37608.140427090600
AUTHID : DEVPRCBK
EDUID : 13881 EDUNAME: db2agent (WEB) 0
FUNCTION: DB2 UDB, trace services, sqlt_logerr_string (secondary logging fu, probe:0
MESSAGE : PAGE OBJECT IDENTIFIERS:
DATA #1 : String, 51 bytes
Tablespace ID = 5, Object ID = 72, Object Type = 0
2014-04-27-05.06.42.072612-240 I37765A511 LEVEL: Severe
PID : 14680376 TID : 13881 PROC : db2sysc 0
INSTANCE: db2rilo NODE : 000 DB : WEB
APPHDL : 0-40 APPID: 9.32.130.62.37608.140427090600
AUTHID : DEVPRCBK
EDUID : 13881 EDUNAME: db2agent (WEB) 0
FUNCTION: DB2 UDB, trace services, sqlt_logerr_string (secondary logging fu, probe:0
MESSAGE : PAGE NUMBERS:
DATA #1 : String, 38 bytes
Obj Page = 15430, Pool Page = 1061398
2014-04-27-05.06.42.072878-240 I38277A485 LEVEL: Severe
PID : 14680376 TID : 13881 PROC : db2sysc 0
INSTANCE: db2rilo NODE : 000 DB : WEB
APPHDL : 0-40 APPID: 9.32.130.62.37608.140427090600
AUTHID : DEVPRCBK
EDUID : 13881 EDUNAME: db2agent (WEB) 0
FUNCTION: DB2 UDB, trace services, sqlt_logerr_string (secondary logging fu, probe:0
MESSAGE : lifeLSN:
DATA #1 : String, 17 bytes
000000003CA9A178
</code>ide
分析:對於DB2中數據庫出現壞塊問題,若是沒有使用該表時候,並不會影響數據庫的正常使用,一旦有訪問該表的會話,那麼會形成整個數據庫實例宕機,從而影響業務的應用,因此問題比較棘手,對於此類問題沒有很好的解決,惟獨能夠經過db2dart離線方式將表中的數據導出,而且將表mark爲unvaliable後重建便可,db2dart只開放了部分免費功能,如標記索引,導出數據,表空間高水位線處理及一些查看功能,可是對於標記表失效須要客服提供密碼纔可使用。其實根據上面提供的信息已經比較徹底了,只須要找出是那張表表便可。ui
Tablespace ID = 5, Object ID = 72, Object Type = 0
this
其中tablespace id便是壞塊所在表的表空間ID,object id對應出現壞塊的對象ID,能夠是表索引或LOB,object type表明損壞對象的類型,0表示表,1表示索引,還有其餘的LOB之類的吧,不過不多見,上面可見損壞的是表,因此因此根據信息就能夠經過syscat.tables查看損壞的表名稱:spa
db2 select tabschema,tabname from syscat.tables where tableid=72 and tbspaceid=5
TABSCHEMA TABNAME
-----------------------------------------------------------------
WWPP2 WWIDE_FNSHD_PART
日誌
而後須要停掉實例直接db2stop force便可
db2dart web /MT /tsi 5 /oi 72code
這樣將表標記爲unvaliable了,這時仍是能夠經過db2look將表結構導出來的,倒出來後直接Drop 掉這個表重建便可。
若是是索引損壞,就能夠經過object id和tablespace id在視圖syscat.indexes中查到索引的ID號,IID,不一樣的是標記索引是是個免費功能,參數使用MI,過程大體至關,標記失效後的索引不須要通過drop,根據這個參數設置狀況:
Index re-creation time and redo index build (INDEXREC) = SYSTEM (RESTART)
失效的索引會自動重建。
相似的db2dart還有離線導出表中數據的功能,也爲無償使用,相對比較簡單,經過以下SQL找到相關須要的對象
select rtrim(tabschema)||'.'||tabname,TABLEID||','||TBSPACEID||','||1||','||fpages from syscat.tables where tabschema='EBIZ1' and tabname='TEST'
而後使用ddel便可將懷錶中的數據導出格式爲DEL的數據文件
db2dart web /DDEL /OI 134 /TSI 6 /PS 1 /NP 100 /V Y /RPT /db2_backup/db2rilo/WEB/db2dart /RPTN WEB_QUOTE
固然整個過程須要交互進行。
至於各個選項表明什麼意思,能夠經過以下方式查看:
$ db2dart ____________________________________________________________________ _____ D B 2 D A R T _____ Database Analysis Tool I B M DB2 6000 The DB2DART Tool is a utility for the analysis of databases, tablespaces, and tables. DART's primary function is to examine databases for their architectural correctness, and to report any encountered errors. ____________________________________________________________________ ___________________________________________________________________________DB2 V9.7 DB2DART HELP db2dart - Database Analysis Tool The db2dart command analyses databases, table spaces and tables. The primary function of this command is to examine databases for architectural correctness, and to report any encountered errors. Requirements: db2dart must be run with no users connected to the database. Syntax: db2dart <database name> [action] [options ...] ('db2dart /H' for extended help) Command parameters: /H Displays this help. (press <enter> for more text) /H Inspect actions: /DB (default) Inspects entire database. /T Inspects one or more tables. (See notes 1, 3, 13) /TSF Inspects only the table space files and containers. /TSC Inspects the table space constructs of one or more table spaces (but does not inspect tables). /TS Inspects one or more table spaces and their tables. (/TSC and /TS require a table space ID or a list of table space IDs to be specified. See notes 1 and 2.) /ATSC Inspects constructs of all table spaces (but not their tables). Data format actions: /DD Dumps formatted table data. (See notes 1, 4, 13, 15) /DM Dumps formatted block map data. (See notes 1, 4, 13, 15) /DI Dumps formatted index data. (See notes 1, 4, 12, 15) /DXA Dumps formatted xda data in ASCII. (See notes 1, 4, 13, 15) /DXH Dumps formatted xda data in Hex. (See notes 1, 4, 13, 15) /DP Dumps pages in hex format. (See notes 1, 6, 13) /DTSF Dumps formatted table space file information. /DEMP Dumps formatted EMP information for a DMS table. (See notes 1, 3, 13) /DDEL Dumps formatted table data in delimited ASCII format. (See note 13, 15) /DHWM Dumps high water mark information. (See notes 1, 2, 14) /LHWM Suggests ways of lowering high water mark. (See notes 1, 7, 14) (press <enter> for more text) /DDEL Input value options: /OI object-id Specifies the object ID. For the /T, a comma-separated list of up to 64 object IDs can be specified. If the corresponding /TSI parameter contains more than one input ID, only the first ID is used. Duplicate IDs are skipped. Logical ID can be specified for the /T parameter. /TN table-name Specifies the table name. /TSI tablespace-id Specifies the table space ID. For the /TS and /TSC, a comma-separated list of up to 64 physical table space IDs can be specified. Duplicate IDs are skipped. /ROW sum Identifies whether L/F descriptors, LOB descriptors and control information should be checked. (1) Checks control information in rows. (2) Checks long field and LOB descriptors. (see note 8) /PS number Specifies the page number to start with. (When using the /DP action or working with a pool-relative tablespace, you may suffix the page number with 'p' for pool relative.) /NP number Specifies the number of pages. /V Y/N Specifies whether or not to use verbose option. (Y) Verbose. (N) No verbose./RPT path The path to place report output file (optional). /RPTN file-name The name of the report file (optional). /SCR Y/M/N Specifies the type of screen output, if any. (Y) Produces normal screen output. (M) Produces minimal screen output. (N) Produces no screen output. /RPTF Y/E/N Specifies the type of report file output, if any. (Y) Produces normal output. (E) Sends only error information to report file. (N) Produces no report file output. /ERR Y/N/E Specifies the type of log to produce in DART.INF, if any. (Y) Produces a normal log in DART.INF file. (default) (N) Minimizes output to log DART.INF file. (E) Minimizes DART.INF file and screen output. Only error information is logged./WHAT DBBP OFF/ON Specifies the database backup pending state. (OFF) Off state. (ON) On state. /QCK [sum] Specifies a quick option. The default /QCK value is 1, the same as when you specify /QCK 1. (see note 8) Valid values are: (1) Applies only to the /DB, /T, and /TS actions. Inspects only page 0 of the DAT objects and partially inspects the index objects (does not inspect BMP, LOB, LF objects and does not traverse the entirety of the DAT or INX objects). (2) Applies only to the /DB, /T, /TS, /DD, /DI, /DM, /DEMP, /DDEL, /DXA, and /DXH actions. Skips system catalog table look up on non-partitioned database environments and on the catalog partition of partitioned database environments. This option has no effect on non-catalog partitions of partitioned database environments. Not applies to the applicable actions above when /TN with a table name is specified, or if /OI and /TSI with logical IDs are specified. (4) Applies only to the /T, /TS, and /TSC actions. For /TS, /TSC, skips inspection of the special system catalog tables. For /T, skips inspection of the system catalog table space constructs. (8) Applies only to /T and /TS actions. For /T, skips inspection of all container files. For /TS, inspects only container files that are associated with the specified table space. /TYP Specifies the type of object. Valid values are: (DAT) Object type is DAT. (INX) Object type is INDEX. (BKM) Object type is BMP. (press <enter> for more text)