If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > 'Database currently in use' error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-29-11, 17:23
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
'Database currently in use' error

Hi,

Every night on our backup server, the latest backup image is restored. There are only two programs running that are stopped and then here is what the script has --


db2 "force applications all"
sleep 2
db2 "force applications all"
sleep 1
db2 "force applications all"
sleep 1

db2 "drop database DBNAME"

db2set DB2_OVERRIDE_BPF=64000

db2 terminate
db2stop
db2start

--- db restore command --

--- db rollforward command --



--------------------------------------------------------------------------------------


The problem is that in the last two nights, the restore has failed because it complains that the database is currently in use. I'm not sure what is causing this but is there something I can add to the script that can stop the db no matter what -- should I change the db2stop command to 'db2stop force'? Or do something else? Thanks! Also, here is the current result of the above commands --



DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.

DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.

DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.

SQL1035N The database is currently in use. SQLSTATE=57019
DB20000I The TERMINATE command completed successfully.
SQL1025N The database manager was not stopped because databases are still active.
SQL1026N The database manager is already active.
SQL1035N The database is currently in use. SQLSTATE=57019
full restore failed
Reply With Quote
  #2 (permalink)  
Old 07-29-11, 17:38
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Try to deactivate the database prior to dropping it - in case it was activated explicitly.
Reply With Quote
  #3 (permalink)  
Old 07-29-11, 17:47
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
thanks, I don't have any activate / deactivate commands in the script but would it help if I changed the script to look like this ---


db2 "force applications all"
sleep 2
db2 "force applications all"
sleep 1
db2 "force applications all"
sleep 1


db2 "deactivate database DBNAME" ( ADDED THIS LINE)

db2 "drop database DBNAME"

db2set DB2_OVERRIDE_BPF=64000

db2 terminate
db2stop
db2start

--- db restore command --

--- db rollforward command --
Reply With Quote
  #4 (permalink)  
Old 07-29-11, 17:47
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
also, do you think db2stop force is a bad idea?
Reply With Quote
  #5 (permalink)  
Old 07-29-11, 20:22
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Yes it is a bad idea.

I will use this in case this is only database in the instance; same is being dropped.

This can be issued after db2stop.

db2set DB2_OVERRIDE_BPF=64000



Regards
Reply With Quote
  #6 (permalink)  
Old 07-29-11, 22:29
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Quote:
Originally Posted by db2user24 View Post
is there something I can add to the script that can stop the db no matter what
db2_kill will stop(kill) the instance no matter what, but this should really be done as a last resort.


Why do you drop the db and restart the instance prior to restore? You can capture list applications before and after force appl to see if force is working. If there is a new connection(s), you can stop them from re-connecting by quiescing the db or unsetting svcename.
Reply With Quote
  #7 (permalink)  
Old 08-19-11, 12:57
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Hi, I'm pretty sure the restore command fails unless I give the db2start command first. Also, is it a bad idea to quiesce the database no matter what ( without checking the application list, etc). Basically am wondering what is worse -- quiescing the db or db2stop force.. thanks!!
Reply With Quote
  #8 (permalink)  
Old 08-19-11, 13:06
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Would something like this work?


db2 "force applications all"
sleep 2
db2 "force applications all"
sleep 1
db2 "force applications all"
sleep 1

db2 quiesce db immediate force connections ( ADDED )

db2 "drop database DBNAME"

db2set DB2_OVERRIDE_BPF=64000

XX db2 terminate ( REMOVE)
XX db2stop ( REMOVE)
XX db2start ( REMOVE)

--- db restore command --

--- db rollforward command --

db2 unquiesce db ( ADDED )
Reply With Quote
  #9 (permalink)  
Old 08-19-11, 15:01
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quiescing the database requires that you connect to the database first. Since you are forcing all the applications off anyway, why not quiesce the instance instead.

Andy
Reply With Quote
  #10 (permalink)  
Old 08-19-11, 15:45
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Quote:
Originally Posted by ARWinner View Post
Quiescing the database requires that you connect to the database first. Since you are forcing all the applications off anyway, why not quiesce the instance instead.

Andy


Thanks, in that case.. is this correct ( all work is performed by the instance db2inst1) ? Will this solve the original problem of it not letting me drop the db? Thank you!!

db2 "force applications all"
sleep 2
db2 "force applications all"
sleep 1
db2 "force applications all"
sleep 1

db2 quiesce instance db2inst1 immediate force connections ( ADDED )

db2 "drop database DBNAME"

db2set DB2_OVERRIDE_BPF=64000

XX db2 terminate ( REMOVE)
XX db2stop ( REMOVE)
XX db2start ( REMOVE)

--- db restore command --

--- db rollforward command --

db2 unquiesce instance db2inst1 ( ADDED )
Reply With Quote
  #11 (permalink)  
Old 08-19-11, 15:51
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I cannot guarantee it, but yest it should. We had the exact same problem a few weeks ago. Our script forced the applications then tried to drop the database, but someone got in between the force and the drop. I added the quiesce instance and it solved that problem.

Andy
Reply With Quote
  #12 (permalink)  
Old 08-19-11, 16:33
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
thanks, appreciate it!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On