16 July,2011 by Tom Collins
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
Force connections of a database in DB2 - DBA DB2
DB2 block all connections to a database - svcename - DBA DB2
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |