IBM Support

How can I manually drop an instance, and/or uninstall DB2 for Linux/Unix?

Technote (troubleshooting)


Problem(Abstract)

I have an installation of DB2 Universal Database for Linux, Unix and Windows product installed on Unix/Linux, and I cannot drop the instance and/or uninstall the product due to an error. I still need to perform the action, so how can I manually drop the instance, and/or uninstall DB2?

Resolving the problem

If you need to drop an instance, and or uninstall DB2 LUW on either Unix or Linux, but are receiving an error that is preventing you from doing this, then you will need to manually drop the instance, and uninstall the DB2 product.
If you are going to manually uninstall, you will need to also drop all the instance(s) associated with that installation. If you are only manually dropping an instance, then you can just do that. Here are the steps you need to take (NOTE that the following examples are for v9.7, but are applicable to all versions from v9.5 to v10.5):

1. First you will need to get the registry entries for the instance(s) that you are going to manually drop (Section "A" below). If also manually uninstalling, then you will ALSO need to get the registry entries for the installation, as well as any registry variables that are tied to the installation (Section "B" below"). As the instance owner, run "db2greg -dump". You should save this output as a text file so you can refer to it later if needed. The instance records will start with "I", the installation records (called "Service" records) will start with an "S", and the variable records will start with a "V". You need to locate the appropriate records. As an example, you might see something like this when you run "db2greg -dump":

[db2v97@my-system ~]$ db2greg -dump
V,DB2GPRF,DB2SYSTEM,my-system,/opt/ibm/db2/V9.7,
V,DB2GPRF,DB2FCMCOMM,TCPIP4,/opt/ibm/db2/V9.7,
S,DB2,9.7.0.8,/opt/ibm/db2/V9.7,,,8,0,,1373391932,0
S,DB2,9.7.0.8,/v97fp8_install,,,8,0,,1380144089,0
V,DB2GPRF,DB2SYSTEM,my-system,/v97fp8_install,
S,DB2,9.7.0.8,/db297fp8/db2,,,8,0,,1380573119,0
V,DB2GPRF,DB2SYSTEM,my-system,/db297fp8/db2,
V,DB2GPRF,DB2FCMCOMM,TCPIP4,/db297fp8/db2,
I,DB2,9.7.0.8,db2v97,/home/db2v97/sqllib,,1,0,/opt/ibm/db2/V9.7,,
V,DB2GPRF,DB2INSTDEF,db2v97,/opt/ibm/db2/V9.7,
V,DB2GPRF,DB2SYSTEM,my-system,/opt/ibm/db2/V10.1,
I,DB2,10.1.0.3,db2v101,/home/db2v101/sqllib,,1,0,/opt/ibm/db2/V10.1,,
V,DB2GPRF,DB2INSTDEF,db2v101,/opt/ibm/db2/V10.1,
S,DB2,10.1.0.3,/opt/ibm/db2/V10.1,,,3,0,,1398537384,0
[db2v97@my-system ~]$

A. To get the instance records, look for the "I" record(s) that have the instance name(s) listed in them that you want to manually drop. If you wanted to manually drop the version 9.7 instance called "db2v97" from the sample listing above, then you would locate the following "I" record:

I,DB2,9.7.0.8,db2v97,/home/db2v97/sqllib,,1,0,/opt/ibm/db2/V9.7,,

B. If you also wanted to manually uninstall the associated DB2 installation, look for the "S" record associated with the installation that you want to uninstall. It will have the same installation path as the "I" record (listed at the end of the "I" record, and in the middle of the "S" record). For example, if you wanted to manually uninstall the installation from the sample data above, you would locate the following "S" record:

S,DB2,9.7.0.8,/opt/ibm/db2/V9.7,,,8,0,,1373391932,0

NOTE that the installation path "/opt/ibm/db2/V9.7" specified in the installation record is the same as the installation path specified in the "I" record. Make sure you have identified the correct installation associated with the instance(s), and that you have identified all the instances associated with it (See section "A" above).

Then you would look at the "V" records and find any that are associated with the same "S" record (again, look at the installation directories specified in the listing). For the above sample data, that would be "/opt/ibm/db2/V9.7". Here are the ones for the above example:

V,DB2GPRF,DB2SYSTEM,my-system,/opt/ibm/db2/V9.7,
V,DB2GPRF,DB2FCMCOMM,TCPIP4,/opt/ibm/db2/V9.7,
V,DB2GPRF,DB2INSTDEF,db2v97,/opt/ibm/db2/V9.7,


2. Next, if you have databases that you want to keep, you need to identify them, as well as their location, and which instance they are in if you are dropping multiple instances. Run the following command for each instance you are dropping:

db2 list db directory

And identify any databases that are LOCAL databases that you want to keep. For example:

[db2v97@my-system ~]$ db2 list db directory

System Database Directory

Number of entries in the directory = 2

Database 1 entry:

Database alias = TEST
Database name = TEST
Local database directory = /myDatabases/TEST
Database release level = d.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

Database 2 entry:

Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2v97
Database release level = d.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

[db2v97@my-system ~]$

NOTE that any databases that you do NOT want to keep, you should go ahead and drop them using "db2 drop database <dbname>", otherwise they will stay out there in limbo and just take up space. If you cannot drop them (IE due to an error or problem with the instance), then make note of their location so you can simply delete the directories when you are done.

In this case, there are 2 databases; TEST and SAMPLE. You need to identify their location, which is specified on the "Local database directory" line. Make note of the database name(s) and associated location(s), as well as which instance (if dropping multiple instances) they are for:

Databases for instance "db2v97":
TEST - /myDatabases/TEST
SAMPLE - /home/db2v97

3. Next, you will need to uncatalog the database(s). NOTE that this will NOT drop them, they will remain, and will be re-catalogged later on. To do that, you would run the following command for EACH database:

db2 uncatalog db <db name>

For example, to uncatalog the 2 example databases above, you would run:

db2 uncatalog db TEST
db2 uncatalog db SAMPLE

4. Stop the instance(s) (if it/they is/are not already stopped):

db2stop

5. Save off anything in the <instance home directory>/sqllib directories for the instances that you might want to keep to a new directory, if you have anything like that in there. This would only be for things that you decided to store in there. Anything that is related to DB2 will be removed.

6. Remove the sqllib directory from the instance home:

cd <instance home directory>
rm -rf sqllib

For example, for the sample information we have above, you would execute:

cd /home/db2v97
rm -rf sqllib

You need to do this for each instance you want to drop. Ensure that the the sqllib directory is gone. If anything remains, it could cause problems later on. You may need to "su -" to root to remove some things, depending on what was there.

7. As root, remove the instance "I" record(s) from the db2 registry. This is where you would use the "I" record(s) that you identified in step 1.A above. There are 4 fields that you need to identify. Using the example "I" record from above, they are:

I,DB2,9.7.0.8,db2v97,/home/db2v97/sqllib,,1,0,/opt/ibm/db2/V9.7,,

service=DB2 (second field)
version=9.7.0.8 (third field)
instancename=db2v97 (fourth field)
instancepath=/home/db2v97/sqllib (fifth field)

To remove this record from the registry, you need to use the db2greg command again. In step 6 you removed the directory where this was located, so you need to use the one in the <installation path>/bin. Execute the following:

<DB2 installation directory>/bin/db2greg -delinstrec service=<service>,version=<version>,instancename=<instancename>,instancepath=<instancepath>

NOTE that you are specifying "-delinstrec" to delete the instance record, and that there are no spaces between the comma separated field/values. For example, using the sample information above, you would execute:

/opt/ibm/db2/V9.7/bin/db2greg -delinstrec service=DB2,version=9.7.0.8,instancename=db2v97,instancepath=/home/db2v97

Repeat the above operation for each instance that you want to manually uninstall. If you are only removing instances, then skip ahead to step 12.

8. As root, remove the service "S" record (the installation record) from the db2 registry. This is where you would use the "S" record that you identified in step 1.B above. There are 3 fields that you need to identify. Using the example "S" record from above, they are:

S,DB2,9.7.0.8,/opt/ibm/db2/V9.7,,,8,0,,1373391932,0

service=DB2 (second field)
version=9.7.0.8 (third field)
installpath=/opt/ibm/db2/V9.7 (fourth field)

To remove this record from the registry, you need to use the db2greg command again. Like step 7 above, you will need to use the one located in the <installation path>/bin directory. Execute the following:

<DB2 installation directory>/bin/db2greg -delservrec service=<service>,version=<version>,installpath=<installpath>

NOTE that you are specifying "-delservrec" to delete the service record, and that there are no spaces between the comma separated field/values. For example, using the sample information from above, you would execute:

/opt/ibm/db2/V9.7/bin/db2greg -delservrec service=DB2,version=9.7.0.8,installpath=/opt/ibm/db2/V9.7

9. As root, remove the variable "V" record(s) from the db2 registry. This is where you would use the "V" record(s) that you identified in step 1.B above. There are 4 fields that you need to identify. Using one of the example "V" records from above, they are:

V,DB2GPRF,DB2INSTDEF,db2v97,/opt/ibm/db2/V9.7,

service=DB2GPRF (second field)
variable=DB2INSTDEF (third field)
value=db2v97 (fourth field)
installpath=/opt/ibm/db2/V9.7 (fifth field)

To remove this record from the registry, you need to use the db2greg command again. Like step 8 above, you will need to use the one located in the <installation path>/bin directory. Execute the following:

<DB2 installation directory>/bin/db2greg -delvarrec service=<service>,variable=<variable>,value=<value>,installpath=<installpath>

NOTE that you are specifying "-delvarrec" to delete the variable record, and that there are no spaces between the comma separated field/values. For example, using the sample information from above, you would execute:

/opt/ibm/db2/V9.7/bin/db2greg -delvarrec service=DB2GPRF,variable=DB2INSTDEF,value=db2v97,installpath=/opt/ibm/db2/V9.7

Be sure to do this for all "V" records associated with the installation (For the example "V" records from above, I would have to run it for the other 2 records:

V,DB2GPRF,DB2SYSTEM,my-system,/opt/ibm/db2/V9.7,
V,DB2GPRF,DB2FCMCOMM,TCPIP4,/opt/ibm/db2/V9.7,

Like this:

/opt/ibm/db2/V9.7/bin/db2greg -delvarrec service=DB2GPRF,variable=DB2SYSTEM,value=my-system,installpath=/opt/ibm/db2/V9.7

/opt/ibm/db2/V9.7/bin/db2greg -delvarrec
service=DB2GPRF,variable=DB2FCMCOMM,value=TCPIP4,installpath=/opt/ibm/db2/V9.7

10. Save off anything in the installation directory that you might want to keep, if you have anything in there. This would only be for things that you decided to store in there. Anything that is related to DB2 will be removed.

11. Now you can remove the installation directory. As root, run:

cd <DB2 installation directory>
rm -rf *

For example, for the sample information we have above, you would execute:

cd /opt/ibm/db2/V9.7
rm -rf *

Once this is done, ensure that nothing remains in there, or it could cause problems when you re-install.

12. The instances (and the installation and registry variables if you also removed them) are now gone. You can perform a new installation (if you uninstalled DB2), and then recreate the instance(s), using the regular procedures. While you can re-install to any location you want to (does not have to be the same as it was removed from), the instance(s) MUST be recreated with the same instance owner, and in the same instance home directory, IF you are reusing previous databases (see step 2 above). Otherwise, you can use a different instance owner and instance home directory.

13. Once you have re-installed, and recreated the instance(s), you can re-catalog your database(s). To do that, you would log in as the instance owner, and execute:

db2 catalog db <dbname> on <path>

Where <path> is the "Local database directory" from step 2 above. For example, for the sample data, we would log in as "db2v97", and execute:

db2 catalog db TEST on /myDatabases/TEST
db2 catalog db SAMPLE on /home/db2v97

You should do this for each instance that you manually dropped/recreated that had databases you wanted to keep. Make sure and catalog the correct databases with the correct instances, or they will not work. You cannot recatalog a database from one instance on another.

Related information

Displaying and altering the global registry (UNIX) usin
UNCATALOG DATABASE command
CATALOG DATABASE command

Document information

More support for: DB2 for Linux, UNIX and Windows
Install/Migrate/Upgrade - Instance

Software version: 9.5, 9.7, 9.8, 10.1, 10.5

Operating system(s): AIX, HP-UX, Linux, Solaris

Software edition: Advanced Enterprise Server, Advanced Workgroup Server, Enterprise Server, Express, Personal, Workgroup Server

Reference #: 1673848

Modified date: 02 July 2014


Translate this page: