Friday, December 19, 2008

How to recover accidentally dropped Table by Getting DBID, PSID, OBID from table backup with help of DSN1PRNT

You can act as recovery expert: Read on...

Case: Suppose you have dropped a table accidentally. As soon as the table dropped all information regarding this table will be dropped from DB2 catalog. If you have DDL you can create the table but you can't load the previously taken image copies to new table as DBID, PSID and OBID will definitely mismatch.

Here is the procedure to follow in case of such scenario.

For the data set that contains the dropped table, run DSN1PRNT with the FORMAT and NODATA options.
Record the HPGOBID field in the header page and the PGSOBD field from the data records in the data pages.
For the auxiliary table of a LOB table space, record the HPGROID field in the header page instead of the PGSOBD field in the data pages.

Field HPGOBID is 4 bytes long and contains the DBID in the first 2 bytes and the PSID in the last 2 bytes.

Field HPGROID (for LOB table spaces) contains the OBID of the table.
A LOB table space can contain only one table.

Field PGSOBD (for non-LOB table spaces) is 2 bytes long and contains the OBID of the table.
If your table space contains more than one table, check for all OBIDs. By searching for all different PGSOBD fields. You need to specify all OBIDs from the data set as input for the
DSN1COPY utility.

Convert the hex values in the identifier fields to decimal so that they can be used as input for the DSN1COPY utility.

Run the DSN1PRNT utility with the PARM=(FORMAT, NODATA) option on all data sets that might contain user table spaces.

The NODATA option suppresses all row data, which reduces the output volume that you receive.

Print(0) is the header page which contains the PSID and DBID.
Most probably you need to print at least 3 pages i.e. PRINT(0,2) to get OBID.


//TSG10PNT JOB ,'DSN1COPY ',NOTIFY=TSG10,CLASS=S,MSGCLASS=O,
// MSGLEVEL=(1,1),COND=(7,LT)
//*
//*=========================================================
//* DISPLAY FOR TABLESPACE SIHCY
//*=========================================================
//DISPAGE EXEC PGM=DSN1PRNT,
// PARM='PRINT(0,2),FORMAT,NODATA'
//SYSUT1 DD DSN=CF1M.DHGDG.DCMORGU1.SIHCY.F001.G7449V00,
// DISP=OLD
//SYSUT2 DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*

From SYSPRINT we can get
HPGOBID='018F0099'X
First 2 bytes gives us x'018F' which is equal to decimal 399 which is DBID.
Last 2 bytes gives us x'0099' which is equal to decimal 153 which is PSID.
You can only find the OBID which refers to PGSOBD in subsequent pages
if more than one tables are there.
Here we can see PGSOBD='009A'X which is decimal equivalent as 154.

I am pasting the first 3 pages of DSN1PRNT SYSPRINT output
at last section of the blog.

Note: This information can be also obtained by DSN1COPY utility with
print option. But this is not recommended.

After getting all the information you can restore the same data
to the target tablespace by mapping to the respective IDs..
Please see my other blog "DSN1COPY" to more how to map these ids.

You can code your DSN1COPY as below:
//*=========================================================
//* IBM DSN1COPY FOR TABLESPACE SIHCY
//*=========================================================
//SIHCY EXEC PGM=DSN1COPY,
// PARM='FULLCOPY,OBIDXLAT,RESET'
//SYSUT1 DD DSN=CF1M.DHGDG.DCMORGU1.SIHCY.F001.G7451V00,
// DISP=OLD
//SYSUT2 DD DSN=DSN2.DSNDBD.DSPS02.SIHCY.I0001.A001,
// DISP=OLD
//SYSPRINT DD SYSOUT=*
//SYSXLAT DD *
399,475 -- DBID info
153,734 -- PSID info
154,4493 -- OBID info
/*


Note: As a prevention measure, every table in production should be defined with "RESTRICT ON DROP" clause.


*******************************************
SYSPRINT output from DSN1PRNT
*******************************************
1
***********************************************************************************************************************************
1DSN1999I START OF DSN1PRNT FOR JOB TSG10PN1 DISPAGE
DSN1998I INPUT DSNAME = CF1M.DHGDG.DCMORGU1.SIHCY.F001.G7449V00 , SEQ
DSN1989I DSN1PRNT IS PROCESSED WITH THE FOLLOWING OPTIONS:
4K/NO IMAGECOPY/NUMPARTS = 0/ FORMAT/NO EXPAND/NO SWONLY/ PRINT/NO VALUE/ / /PIECESIZ= /NODATA
DSSIZE=


PAGE: # 00000000 ----------------------------------------------------------------------------------------------------------------
HEADER PAGE: PGCOMB='10'X PGLOGRBA='0B0BF46E3539'X PGNUM='00000000'X PGFLAGS='38'X
HPGOBID='018F0099'X HPGHPREF='0000092D'X HPGCATRL='00'X HPGREL='D2'X HPGZLD='00'X
HPGTORBA='000000000000'X HPGTSTMP='00010101000000000000'X HPGSSNM='DSN1'
HPGFOID='0098'X HPGPGSZ='1000'X HPGSGSZ='0040'X HPGPARTN='0000'X
HPGZ3PNO='000000'X HPGZNUMP='00'X HPGTBLC='0001'X HPGROID='009A'X
HPGZ4PNO='00000000'X HPGMAXL='018D'X HPGNUMCO='001C'X HPGFLAGS='0000'X
HPGCONTM='20081206185850843175'X HPGSGNAM='GDSN1 ' HPGVCATN='DSN1 '
HPGRBRBA='0B0BCA98C7D0'X HPGLEVEL='0B0BCA98C7D0'X HPGPLEVL='0B087E0E732E'X
HPGCLRSN='0B0BF46E3539'X HPGSCCSI='0000'X HPGDCCSI='0000'X HPGMCCSI='0000'X
HPGFLAG2='00'X HPGEPOCH='0031'X HPGCATV='00'X FOEND='N'


PAGE: # 00000001 ----------------------------------------------------------------------------------------------------------------
SEGMENTED SPACEMAP PAGE: PGCOMB='00'X PGLOGRBA='0B0BCA98B972'X PGNUM='00000001'X PGFLAGS='30'X
SEGNUM='0056'X SEGFREE='0031'X SEGENT='0026'X SEGSIZE='0040'X
SEGLENT='0000092B'X FOEND='E'
FIRST PART OF SEGMENTED SPACE MAP:
SEG 0001 00000002009AC0 3333333333333333333333333333333333333333333333333333333333333333
SEG 0002 00000003009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0003 00000004009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0004 00000005009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0005 00000006009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0006 00000007009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0007 00000008009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0008 00000009009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0009 0000000A009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000A 0000000B009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000B 0000000C009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000C 0000000D009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000D 0000000E009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000E 0000000F009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 000F 00000010009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0010 00000011009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0011 00000012009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0012 00000013009A80 33333333333333333333333333333333333333333333F3333333333333333333
SEG 0013 00000014009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0014 00000015009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0015 00000016009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0016 00000017009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0017 00000018009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0018 00000019009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0019 0000001A009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 001A 0000001B009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 001B 0000001C009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 001C 0000001D009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 001D 0000001E009A80 3333333333333333333333333333333333333333333333333333333333333333
1SEG 001E 0000001F009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 001F 00000020009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0020 00000021009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0021 00000022009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0022 00000023009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0023 00000024009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0024 00000025009A80 3333333333333333333333333333333333333333333333333333333333333333
SEG 0025 00000000009A80 3333333333333333333333333333333333333333333000000000000000000000

SECOND PART OF SEGMENTED SPACE MAP:
RELPG 00 20 40 60 80 A0 C0 E0
0000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0002 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0003 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0004 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0005 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0006 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0008 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

RELPG 00 20 40 60 80 A0 C0 E0
0009 00000000 00000000


PAGE: # 00000002 ----------------------------------------------------------------------------------------------------------------
DATA PAGE: PGCOMB='00'X PGLOGRBA='000000000000'X PGNUM='00000002'X PGFLAGS='00'X PGFREE=429
PGFREE='01AD'X PGFREEP=3647 PGFREEP='0E3F'X PGHOLE1='0000'X PGMAXID='09'X PGNANCH=0
PGTAIL: PGIDFREE='00'X PGEND='E'
ID-MAP FOLLOWS:
01 0014 01A7 033A 04CD 0660 07F3 0986 0B19
09 0CAC

RECORD: XOFFSET='0014'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='01'X
RECORD: XOFFSET='01A7'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='02'X
RECORD: XOFFSET='033A'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='03'X
RECORD: XOFFSET='04CD'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='04'X
RECORD: XOFFSET='0660'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='05'X
RECORD: XOFFSET='07F3'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='06'X
1RECORD: XOFFSET='0986'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='07'X
RECORD: XOFFSET='0B19'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='08'X
RECORD: XOFFSET='0CAC'X PGSFLAGS='00'X PGSLTH=403 PGSLTH='0193'X PGSOBD='009A'X PGSBID='09'X
0DSN1994I DSN1PRNT COMPLETED SUCCESSFULLY, 00000003 PAGES PROCESSED


Cheers...
Prakash C. Singh
IBM Certified DB2 DBA

2 comments:

Anonymous said...

Hi, the above post was very informative and interesting. appreciate ur way of steb by step explanation.keep posting

Unknown said...

Wonderful Blog Sir...

I am an IBMer.. my id is jajayara@in.ibm.com