RE: Detailed Status of Locks ?
Posted in 1997
I have got a script to show all the locks of each database and the
object locked in the instance. Hope this will be useful. But this uses
dbaccess to connect to the database and obtain the information about the
objects so it is a little bit slow.
I have tested it in sequent Dynix PTX. It works fine.
NOTE: This scripts uses a command called "listusers" (I do not know
whether it is sequent specific. but if it is not you can get the
username from /etc/passwd.). I will try to amend this script to work
globally.
just type lockrep in the command line. Please let me know you have.
here is the script.
#!/bin/sh
########################################################################
########
#
# Shell Script: lockrep
#
# Description: Program to find out tables which is locked by users.
#
# Author: Jayakumar George Date: 12/08/97
#
#
########################################################################
########
onstat -u | nawk ' BEGIN { getline;getline;getline;getline;getline;ctr =
1 }
{ if ( $2 == "active,")
{
while(getline)
}
else
{
if ($8 > 1)
{
username[ctr]=$4
sessionid[ctr]=$3
useraddr[ctr]=$1
ctr++
}
}
tmpctr=1
while("onstat -g sql"|getline)
{
if(tmpctr > 5)
databases[$1]=substr($0,22,18)
tmpctr++
}
}
END {
if (ctr == 1)
{ print "No User(s) Has a lock"
exit 1
}
print "The following User(s) has lock(s)"
print "User ID User Name Sess. ID
Database Table(s)"
print "------- --------- --------
-------- -------"
for(forctr=1;forctr< ctr;forctr++)
{
"listusers | grep " username[forctr] | getline
printf "%-36s%8d %-15s",$0
,sessionid[forctr],substr(databases[sessionid[forctr]],1,15)
selstr = " select tabname from systables where
partnum in \\("
inclse=""
cmd = "onstat -k | grep " useraddr[forctr]
while(cmd | getline)
{
if($4 != 0)
{
hextoint($6)
tabnum[res]=res
}
}
inctr=1
for (tabnumvar in tabnum)
{
if (inctr > 1)
inclse = inclse ",";
inclse = inclse tabnumvar
delete tabnum[tabnumvar]
inctr++
}
inclse = inclse "\\)"
selstr= selstr inclse
cmd= "echo \\"" selstr "\\" | dbaccess "
databases[sessionid[forctr]] "2>/dev/null | grep -v \\"^$\\" | grep -v
tabname"
ctrcmd2=1
while(cmd | getline)
{
if(ctrcmd2 == 1)
printf "%-18s",$0
else
printf "%60c%-18s",32,$0
ctrcmd2++
printf "\\n"
}
}
}
function hextoint(a)
{
res=0
base=16
expn=0
for(i=length(a);i>0;i--)
{
val1=substr(a,i,1)
if(match(val1,"[Aa]"))
val1 = 10
if(match(val1,"[Bb]"))
val1 = 11
if(match(val1,"[Cc]"))
val1 = 12
if(match(val1,"[Dd]"))
val1 = 13
if(match(val1,"[Ee]"))
val1 = 14
if(match(val1,"[Ff]"))
val1 = 15
res=res + (val1 * (base^expn))
expn++;
}
}
'
> -----Original Message-----
> From: Bill Ennis [SMTP:ennis@ssax.com]
> Sent: Monday, August 25, 1997 3:09 PM
> To: ebert@mail.ppp.net
> Cc: informix-list@rmy.emory.edu
> Subject: Re: Detailed Status of Locks ?
>
> onstat -k is pretty comprehensive.>
> I also have a script below that you can use to monitor locks
> of a specific user. Just type: user_locks <userid> and read the
> output. Use the reference manual to interpret the lock modes.
>
>
> -Bill
>
> ---------------------------------------------------------------
> #!/bin/ksh
>
> # this script outputs all locks held by a particular user in the
> # Informix Online system
> onstat -u | grep $1 | awk {'print $1'} > session_addresses>
> echo ""
> echo ""
> echo "Locks held by user $1:"
> echo
> "---------------------------------------------------------------------
> -"
> onstat -k | head -5> cat session_addresses | while read sess_addr
> do
> onstat -k | grep "$sess_addr"> done
>
> >
> > Hi,
> >
> > does someone has or knows abour a nice tool to show all the
> > locks set on certain objects in a Onlien database?
> >
> > I would like to see who owns the locks and what kind of locks
> > they are.
> >
> > Thank You,
> > Jens
> > ebert@mail.ppp.net
> >
>
>
> --
> Bill Ennis Voice: 312-474-7516
> SSA Fax: 312-474-7460
> 500 W. Madison email: ennis@ssax.com ennis@accesschicago.net