Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2007
    Posts
    265

    Unanswered: '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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Try to deactivate the database prior to dropping it - in case it was activated explicitly.

  3. #3
    Join Date
    Nov 2007
    Posts
    265
    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 --

  4. #4
    Join Date
    Nov 2007
    Posts
    265
    also, do you think db2stop force is a bad idea?

  5. #5
    Join Date
    Sep 2008
    Location
    Toronto,Canada
    Posts
    655
    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

  6. #6
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,368
    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.

  7. #7
    Join Date
    Nov 2007
    Posts
    265
    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!!

  8. #8
    Join Date
    Nov 2007
    Posts
    265
    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 )

  9. #9
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  10. #10
    Join Date
    Nov 2007
    Posts
    265
    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 )

  11. #11
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  12. #12
    Join Date
    Nov 2007
    Posts
    265
    thanks, appreciate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •