DB2 deactivate database

16 July,2011 by Jack Vamvas

Depending on the circumstances , it may be necessary to either deactivate one DB2 database or all databases in a single instance

 

To deactivate one database , the following steps will help:

 

-          Turn AUTORESTART off via the command

Db2 update cfg for using autorestart off

 

-force the users off

 Db2 force applications all

 

-          deactivate database

 

db2 deactivate db

 

 

On certain occasions this does not work. In that case do a Quiesce database

 

QUIESCE DATABASE <my_db> IMMEDIATE FORCE CONNECTIONS

 

To allow access again UNQUIESCE will be required .

  

To deactivate all databases in an instances –  follow the steps above for all databases or execute a shell script such as the one below. This will iterate through all the databases in the instance and deactivate , and creates a log file  :

 

 

 

working_dir=$PWD
logfile="DEACTIVATE__`date +%d%m%y`.log"
touch $working_dir/$logfile

>$working_dir/$logfile

echo "Current working directory $working_dir" >> $working_dir/$logfile

echo "operatation began `date`" >> $working_dir/$logfile

for i in `db2 list db directory | grep 'Database name' | awk '{print $4}'`;

do

echo "=============================="  >> $working_dir/$logfile ;

echo "beginning takeover for $i"  >> $working_dir/$logfile ;

echo "=============================="  >> $working_dir/$logfile ;

echo "checking database state"  >> $working_dir/$logfile ;

state=$(db2 get db cfg for $i | grep 'HADR database role' | awk '{print $5}');

echo "Current state is $state"  >> $working_dir/$logfile ;

 

echo "command : db2 takeover hadr on db $i"  >> $working_dir/$logfile ;

db2 deactivate db $i  >> $working_dir/$logfile ;

 

echo "=============================="  >> $working_dir/$logfile ;

echo "";

done

echo "operatation ended `date`" >> $working_dir/$logfile



 Read More

Force connections of a database in DB2 - DBA DB2

DB2 block all connections to a database - svcename - DBA DB2

DBA Interview Questions and Answers – DB2 Server Operations

Author: Jack Vamvas(http://www.dba-db2.com)

Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on DB2 deactivate database

Comments are moderated, and will not appear until the author has approved them.


dba-db2.com | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright