In literal terms, data Corruption appears to be something that no one really wants within their organization. But every now and then, you might have witnessed some customers run into this, and any such issues always becomes the result of disk or SAN (Storage Area Network) level issues, as one will witness errors more often like this

Thus, the options to get to a logical state are very intricate and involve a very lengthy process, and according to the Db2 experts, they often compare data recovery from Db2 data corruption with building your own ladder and climbing one step at a time versus taking an elevator (backup and restore).

Anyways, here is what this whole process involves,

  • First, one need to run a regular Db2 inspection to find out which objects are in fact corrupted within a particular database. The code are as follows,

  • Secondly, the result or the output, from this will be written to wherever your db2dump is to that location. The code is as follows

  • Then use the db2instpf to analyze this and use the basic awk code, you can choose to do this however you like

  • On the other hand, it provides you a unique set of results with a particular object ID’s that seemed corrupted, and then one can use the following Db2 select statement to find the names of those objects as a whole. The Codes associated with it are as follows

  • Once you have completed this for all the object ID’s that are found on the inspect output, you will have a list of what you are working with here. If you found out that you are working with 12 tables and considered yourselves fortunate that it was just that. Now all you need to use is db2dart, in order to export data from these objects as a whole.

The code for the following execution is as follows

Table object data formatting end.

  • Always, keep in mind that any data that db2dart will dump will exclude the pages where the corruption actually existed, so there will likely be missing data.
  • The very next step involves that one should take a db2look output for all the objects that are initially identified, and one should make sure you use all the options to grab all the associated grants etc.

Here’s what is generally used by the experts are as follows

  • Immediately, after this, one need to drop these objects one at a time, recreate empty tables and load with the data from the db2dart dumps. After getting to this point and being confident, you can quickly get to a point where the application can be brought back up with no issue.

The code of this incident is as follow

You might have tried to do a load from /dev/null to truncate it, so you can load, but that often doesn’t work out for some time. Then you may try to rename the table and leave it alone and create an empty table so you can seamlessly load it with the db2dart dump. But that can’t be done as well. The problem with doing anything with this table is that if the table header and such is corrupted, Db2 does not know how to drop it.

  • In order to get rid of this problem, you should contact IBM experts from All Blue Solutions, as they have a solution for this kind of issue. At times, IBM experts will definitely get back quickly, if you raise an issue, and proposed to you to perform this activity as follows

  • Always, know that in order to able to do this, you will have to contact the IBM experts of All Blue Solutions, so they can create a service password for you. At the same time, they will need db2level info to be able to do this.

As a result, the following command essentially puts the table in drop pending state:

  • As you can witness, this is a special command which is used with a service password that the IBM experts of All Blue Solutions, creates for you, in order to be able to access this. The password appears to be valid only for 7 days, and anyways, you may drop the PGMFILE table, recreate it and load it with the db2dart dump that you may had. That’s it, and when you are done with this process for all the corrupt objects that you have identified for so long gets removed at once. As a result, your database appears to be in good shape.

In conclusion, it can be said that as a workaround, you may also create an empty database, named as samplenew, then use the db2move utility to export the entire original database and then load the new database using db2move. The tables that are corrupted will not be loaded, since db2move most likely wasn’t able to export them. You will need the db2dart dumps to load those tables.

Do you want to recover your Db2 database from data corruption? Reach out to us!