Thursday, July 7, 2011

db2 merge backup - utility test

I was very excited about "db2 merge backup" tool. As per the documentation this tool is supposed to merge incremental and delta backup and merge it with the most recent full db backup prior to these incremetnal or delta backups. More details about this utility can be found here

So, if you have this tool working you take one full backup and there are after you just do delta backups and keep merging them with you full backup. Here after you never take full db backups again.

Out of excitement I decided to test this tool. Downloaded this tool and set it up on my window workstation. I did my full backup, ran couple of database transactions and took the delta backup. Below is the control file options and the command used and the output as well.

Below are the contents from "SampleMergeCtrlFile.txt" control file used in the test. I used the control file examples from the following link here

MERGE DATABASE ZZZ
PART (0)
START FROM "C:" TAKEN AT 20110707153755
END FROM "C:" TAKEN AT 20110707154108
OUTPUT TO "C:\Merged\"

Below is the my db2 merge command output.

db2mbk -i DB2INST1 -f SampleMergeCtrlFile.txt -s -p 0
MBKI445W Warning: you are still using a temporary license.
         you need to enroll DB2 Merge Backup for Linux, UNIX, and Windows within 29 days.
MBKM031I DB2 Merge Backup for Linux, UNIX, and Windows 01.01.000(110505) 32 bits 7/7/2011 (Windows)
       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----10----+----11----+----12----+----13--
000001 MERGE DATABASE ZZZ
PART (0)
START FROM "C:" TAKEN AT 20110707153755
END FROM "C:" TAKEN AT 20110707154108
OUTPUT TO "C:\Merged\"
MBKB005I MBK control step start   : 16:00:40.287.
MBKB037I Merged backups will not be registered into DB2.
MBKB005I [0] MBK control step start   : 16:00:40.302.
MBKB006I [0] MBK control step end     : 16:00:40.318.
MBKB006I MBK control step end     : 16:00:40.318.
MBKB053I MBK run step start       : 16:00:40.318.
MBKB007I [0] MBK inventory step start : 16:00:40.318.
MBKB021I [0] The partition 0 backup image taken at 20110707154108 is involved in the merge (type INCREMENTAL ONLINE DATABASE, device DISK)
MBKB008I [0] MBK inventory step end   : 16:00:40.349.
MBKB009I [0] MBK merge step start     : 16:00:40.349.
MBKB028I [0] The utility will build the partition 0 backup image taken at 20110707154109 (type FULL ONLINE DATABASE, device DISK)
MBKB021I [0] The partition 0 backup image taken at 20110707153755 is involved in the merge (type FULL ONLINE DATABASE, device DISK)
MBKB010I [0] MBK merge step end       : 16:00:41.849.
MBKB054I MBK run step end         : 16:00:41.849.
MBKI442I MBK successfully ended: real time -> 0m1.562530s


As per the output the merge was successfull. Then I attempted to restore above merged backup set to a new database. Remember merged backup image is equivalent to full backup. The attempted restore failed and db2 complained that the backup image is corrupt!!

db2 restore db zzz from C:\ taken at 20110707154109 into zzz_tmp
SQL2529W  Warning!  Restoring to an existing database that is different from
the backup image database, and the alias name "ZZZ_TMP" of the existing
database does not match the alias name "ZZZ" of the backup image, and the
database name "ZZZ_TMP" of the existing database does not match the database
name "ZZZ" of the backup image. The target database will be overwritten by the
backup version. The Roll-forward recovery logs associated with the target
database will be deleted.
Do you want to continue ? (y/n) y
SQL2530N  The backup image is corrupted.  Restore of database from this backup
image is not possible.

I felt may be my original backups (full and delta) are corrupt. I restored those backups sets instead of the merged and they work just fine. This concluded that the db2 merge utility is doing something funky.

If you find my test is not appropriate, correct me by leaving a comments.

Update: I was testing this on db2 express 9.7.0 on Window XP. Looks like this issue got resolved after I upgraded db2 to FP4. Later I also fond that if you don't want to upgrade db2 you can modify the merge utility configutaion with following file entry "vendor_object = no" in the configuration file located at "DB2TOOLS\MergeBackup11\cfg\db2mbk.cfg"

Wednesday, May 25, 2011

db2 error SQL10007N - Reason code: "3"


Have you ever encountered errors like,


SQL10007N Message "-1390" could not be retrieved.  Reason code: "3".


or


Error encountered during the Add record action: Failed to lock the registry


I usually encounter these issues when we are managing multiple instances on the same box. So, to set the db2 instance context for commands like db2stop, db2start etc. The way we set context is to change the environment variable to DB2INSTANCE, the command is


export DB2INSTANCE=db2inst1


After setting the instance context using above command, all the instance level command and all the db2 command will be directed to that instance, in our case all the commands like db2stop, db2start, db2 list db directory etc. will be directed to "db2inst1"


However instance name used in export command is case-sensitive. So accidentally if you typed


export DB2INSTANCE=DB2INST1


Then when you run any db2 commands they will complain with error message


SQL10007N Message "-1390" could not be retrieved.  Reason code: "3".


You can't even do  "db2 ? SQL10007N" to get help. For your reference here is the help text



SQL10007N  Message "" could not be retrieved. Reason code:
      "".


Explanation: 


The requested message could not be retrieved from the message
file. Reason code is one of the following: 
1. The environment variable "DB2INSTANCE" is either not set, or is set
   to an invalid instance. Correct it and try again.
2. The message file was found, but the file could not be opened because
   of permissions. Check the file permissions of the files under the
   message directory.
3. The message file could not be found. Either the file does not exist,
   or the directory the message file should be in does not exist. Check
   that either a default directory or a directory with the same name as
   the 'LANG' environment variable exists under the message directory.
4. The requested message does not exist in the message file. Either the
   message file is outdated, or it is the wrong one.
5. Either DB2CODEPAGE is set to a code page which the database does not
   support, or the client's locale is not supported by the database.
6. An unexpected system error occurred. Try execution again. If problem
   persists, contact your IBM representative.
7. Not enough memory. An attempt to get private memory failed. Try
   again.


User response: 


Reissue the command after verifying the following: 
*  ensure that the DB2INSTANCE environment variable is set to the
   correct literal string for the username attempting this command
*  ensure that correct home directory is specified for the username
   attempting this command (i.e. in the /etc/passwd file)
*  ensure that the LANG environment variable is set to the correct value
   for the installed language, or is set to 'C', on the username
   attempting this command
*  Even if the message file is outdated, you can still find up-to-date
   information about the message in the database server documentation.


If all of the above are correct and the error still occurs, reinstall
DB2.


If you do db2ilist you get the instance list along a message..


Error encountered during the Add record action: Failed to lock the registry


These are some of the side effects when you don't set the DB2INSTANCE variable correctly.

About Me

By profession I am a Database Administrator (DBA) with total 13 yrs. of experience in the field of Information Technology, out of that 9 yrs as SQL DBA and last 3 years in IBM System i/iSeries and DB2 LUW 9. I have handled Developer, plus production support roles, and I like both the roles. I love and live information technology hence the name "Techonologyyogi" Apart from that I am a small, retail investor, with small investments in India and United States in the form of Equity holdings via common stocks. Don't ask me if I have made money, I have been loosing money in stocks.