Recovering an accidentally dropped table

If you accidentally drop a table in a segmented (non-UTS) table space, you can recover it from a full image copy or a DSN1COPY file that contains the data from the dropped table.

Before you begin

This procedure applies only for tables in segmented (non-UTS) table spaces. If the accidentally dropped table resides in a universal table space (UTS), partitioned (non-UTS) table space, or LOB table space, you must recover the table space. Use the procedures described in Recovering an accidentally dropped table space.

To recover a dropped table, you need a full image copy or a DSN1COPY file that contains the data from the dropped table.

For segmented table spaces, the image copy or DSN1COPY file must contain the table when it was active (that is, created). Because of the way space is reused for segmented table spaces, this procedure cannot be used if the table was not active when the image copy or DSN1COPY was made. For simple table spaces, the image copy or DSN1COPY file can contain the table when it was active or not active.

Procedure

To recover a dropped table:

  1. If you know the DBID, the PSID, the original OBID of the dropped table, and the OBIDs of all other tables in the table space, go to step 2.
    If you do not know all of the preceding items, use the following steps to find them. For later use with DSN1COPY, record the DBID, the PSID, and the OBIDs of all the tables in the table space, not just the dropped table.
    1. Run the DSN1PRNT utility for the data set that contains the dropped table, with the FORMAT and NODATA options. Locate the following values in the HPGOBID field in the header page and the PGSOBD field from the data records in the data pages.
      DBID
      The first two bytes of the 4-byte field HPGOBID in the header page contain the DBID for the database.
      PSID
      The last two bytes of field HPGOBID in the header page contain the PSID for the table space.
      OBID
      Field SEGOBID in the space map page for the table space contains the OBIDs for each table in the table space.
    2. Convert the hex values in the identifier fields to decimal so that they can be used as input for the DSN1COPY utility.
  2. Use the SQL CREATE statement to re-create the table and any indexes on the table.
  3. To allow DSN1COPY to access the Db2 data set, stop the table space using the following command:

    Begin general-use programming interface information.

    -STOP DATABASE(database-name) SPACENAM(tablespace-name)

    End general-use programming interface information.

    Stopping the table space is necessary to ensure that all changes are written out and that no data updates occur during this procedure.

  4. Find the OBID for the table that you created in step 2 by querying the SYSIBM.SYSTABLES catalog table.

    Begin general-use programming interface information.The following statement returns the object ID (OBID) for the table:

    SELECT NAME, OBID FROM SYSIBM.SYSTABLES
      WHERE NAME='table_name'
        AND CREATOR='creator_name';

    This value is returned in decimal format, which is the format that you need for DSN1COPY. End general-use programming interface information.

  5. Run DSN1COPY with the OBIDXLAT and RESET options to perform the OBID translation and to copy data from the dropped table into the original data set. You must specify a previous full image copy data set, inline copy data set, or DSN1COPY file as the input data set SYSUT1 in the control statement. Specify each of the input records in the following order in the SYSXLAT file to perform OBID translations:
    1. The DBID that you recorded in step 1 as both the translation source and the translation target
    2. The PSID that you recorded in step 1 as both the translation source and the translation target
    3. The original OBID that you recorded in step 1 for the dropped table as the translation source and the OBID that you recorded in step 4 as the translation target
    4. OBIDs of all other tables in the table space that you recorded in step 2 as both the translation sources and translation targets

    Be sure that you have named the VSAM data sets correctly by checking messages DSN1998I and DSN1997I after DSN1COPY completes.

  6. Use DSN1COPY with the OBIDXLAT and RESET options to apply any incremental image copies. You must apply these incremental copies in sequence, and specify the same SYSXLAT records that step 5 specifies.
    Important: After you complete this step, you have essentially recovered the table space to the point in time of the last image copy. If you want to use log records to perform forward recovery on the table space, you must use the IBM® Db2 Log Analysis Tool for z/OS® at this point in the recovery procedure.
  7. Start the table space for normal use by using the following command:

    Begin general-use programming interface information.

    -START DATABASE(database-name) SPACENAM(tablespace-name)

    End general-use programming interface information.

  8. Rebuild all indexes on the table space.
  9. Execute SELECT statements on the previously dropped table to verify that you can access the table. Include all LOB columns in these queries.
  10. Make a full image copy of the table space.
  11. Re-create the objects that are dependent on the recovered table.

    When a table is dropped, objects that are dependent on that table (synonyms, views, indexes, referential constraints, and so on) are dropped. (Aliases are not dropped.) Privileges that are granted for that table are also dropped. Catalog reports or a copy of the catalog taken prior to the DROP TABLE can make this task easier.