Re: Getting exclusive access to a database]
Posted in 2001
Topics: Server Administration, Security, Permissions & Auditing, Migration, Import/Export & Data Conversion
If you have an application that reconnects to database very quickly, then
you won't get exclusive access.
In such case you need to revoke connection permission first.
Here's my version:
#!/bin/ksh
if [[ $1 == "" ]] then
print "\\n\\t USAGE: $0 <dbname> [-c] \\n";
exit 1;
fi
if [[ $2 == "-c" ]] then
dbaccess $1 - <<!
REVOKE CONNECT FROM PUBLIC;!
fi
i=1;
id=`onstat -g sql | grep $1 | awk '{print $1}'`;
for pid in $id
do
echo $i killing $pid ...
onmode -z $pid
i=$((i + 1))
done;
# ----------------------------------------
regards,
> neurologic wrote:
>
> > Brett,
> >
> > Thanks a million, that was exactly what I was looking for. I had been
> > staring at the sysmaster tables for awhile before I posted, I'm
> > suprised I missed something as obvious as "sysopendb"!
> >
> > Thanks again
> >
> > Duff
> > In article <3A57B9F4.26F67394@hotmail.com>,
> > Brett Randall <brett_s_rREMOVECAPITALS@hotmail.com> wrote:
> > > neurologic wrote:
> > > >
> > > > How can I get exclusive access to one particular database in an
> > > > instance without bouncing the engine?
> > >
> > > Kill all the sessions connecting to that database using onmode -z.
> > >
> > > >
> > > > I am attempting to export a small database on a production server,
> > and
> > > > do not want to disrupt the other, more important databases in the
> > > > instance.
> > > >
> > > > What I would really like is something similar to the Unix 'who'
> > command
> > > > that would allow me to identify sessions connected to a database,
> > then
> > > > I could shut the applications connecting to the db properly or kill
> > the
> > > > sessions.
> > > >
> > > > Any ideas?
> > >
> > > Try this script AT YOUR OWN RISK. Execute as informix with
> > environment
> > > set. Tested against IDS2000 only. Be aware that this will terminate
> > > any database session that is connected to the database selected,
> > > including those sessions connected to multiple databases.
> > >
> > > Enjoy.
> > >
> > > Brett Randall
> > >
> > > <script>
> > >
> > > #!/bin/sh
> > >
> > > [ $# -ne 1 ] && echo "usage $0 database_to_clear" && exit 1
> > >
> > > # start buliding a kill script
> > > KILLSCRIPT=/tmp/$$.sh
> > >
> > > dbaccess sysmaster <<EOF
> > >
> > > unload to $KILLSCRIPT delimiter ";"> > > select "onmode -z " || odb_sessionid from sysopendb
> > > where odb_dbname = "$1";
> > >
> > > EOF
> > >
> > > chmod 700 $KILLSCRIPT
> > > /bin/sh $KILLSCRIPT
> > > rm -f $KILLSCRIPT
> > >
> > > </script>
> > >
> > > >
> > > > duff
> > > >
> > > > Sent via Deja.com
> > > > http://www.deja.com/
> > >
> >
> > Sent via Deja.com
> > http://www.deja.com/
Related threads
- Posting from the Informix-list
- Migrating from IDS 9.40.UC6 to 11.50.UC3
- Ip for a network session
- questions onstat -g