Technical Blog Post
Abstract
Basic Guideline on how to rebuild a Db2LUW database
Body
Basic Guideline for rebuilding a Db2LUW database :
Create a temp directory to store the outputs of db rebuild and go to that directory.
Save all the DDLs for the database :
db2look -d <db-name> -a -e -m -l -x -f -o db2look.out
Save config of the database :
db2 get db config > dbCfg.out
(might also use db2cfexp)
Find all the tablespace names from,
db2pd -tablespace -db <db-name> -file tbsp_names.out
Then, for all the good tablespaces,
Create sub-dir for each tablespace to save data per tablespace or, a group of those.
Separate dirs suggested as there are some common files which will conflict between each run.
db2move <db-name> export -ts <tbsp-name>
You might also use multiple tablespace in one command syntax (example tbsp1,tbsp2,tbsp3)
Refer :
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002079.html
For the corrupted tablespaces as select will not work and might crash the instance you need to use db2dart /DDEL
to export out all the good data from all the objects from that tablespace.
Refer this :
/support/pages/node/280365
So, create a different directory for each corrupted tbsp similarly.
Stop the instance.
db2dart D15 /DDEL
It will ask for,
Table ID or name, tablespace ID, first page or logical row, num of pages or logical rows:
One example,
5,35,0,99999999
You can use following to find all table names and id in the tbsp,
db2 "select name, tid, fid from sysibm.systables where tid=<tbsp-id>"
TID = tablespace id, FID = object id
You need to repeat the db2dart /DDEL for each object.
For some of the objects in corrupted tbsp even the db2dart /DDEL might not work.
It might fail due to control data corruption or, presence of LOB or so.
For those objects you need to pull the data from any other similar db with an export from there.
Then,
Drop the database.
Create back the database,
Use your exact create database command syntax to create back db
Update the the db config from dbCfg.out
(might also use db2cfimp)
Then,
db2 -tvf db2look.out
Then, load back all the data from each saved directory of data,
db2move <db-name> load -lo INSERT
( this will pickup the names from db2move.lst from current directory you saved for each group of tbsp)
For data pulled using db2dart /DDEL you might use regular load command to load back.
Special steps might need to take for dependant object cases. Or, any add-ons of the database.
These steps here is to show just the basic steps and commands involved.
UID
ibm11139932