IBM Support

Basic Guideline on how to rebuild a Db2LUW database

Technical Blog Post


Basic Guideline on how to rebuild a Db2LUW database


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

refer :

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 :

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 :

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,

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.

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)
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.

[{"Business Unit":{"code":"BU029","label":"Data and AI"}, "Product":{"code":"SSEPGG","label":"DB2 for Linux, UNIX and Windows"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":""}]