Thursday, April 21, 2011

db2 drop db error !

I was trying to drop database but was getting following error,

SQL1035N  The database is currently in use.  SQLSTATE=57019

So, while I logged in as instance owner, I tried following.

-- first attempt
db2 list applications global

No sessions were listed except my own local connections. Then I tried following set of statements.

-- second attempt
db2 deactivate db myDB
db2 drop database myDB

Still no luck, I kept getting the same message. Then I tried another variation

-- third attempt
db2 connect to myDB
db2 quiesce database immediate force connections
db2 connect reset
db2 terminate
db2 drop database myDB

Finally I tried this,

-- final attempt
db2 terminate
db2 drop database myDB

I was puzzled, why my third attempt did not work and the final one worked?

I thought it might be the sequence of statements. I looked into the "db2 terminate" command documentation on db2 information center, and her is what it says,

Although TERMINATE and CONNECT RESET both break the connection to a database, only TERMINATE results in termination of the back-end process.

It is recommended that TERMINATE be issued prior to executing the db2stop command. This prevents the back-end process from maintaining an attachment to a database manager instance that is no longer available.

What all this means is always use "db2 terminate" if you really want to disconnect your connections/sessions before doing db level options like db drop etc.

No comments:

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.