dbTalk Databases Forums  

Script to remove user sessions from a DB

comp.databases.ingres comp.databases.ingres


Discuss Script to remove user sessions from a DB in the comp.databases.ingres forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Steve McElhinney
 
Posts: n/a

Default Script to remove user sessions from a DB - 09-13-2005 , 05:23 AM






Part of our batch work requires exclusive access to a livedb, so
we need a UNIX script to remove all user sessions from the database.

We currently have a script that runs iinamu to get the server id's
then iimonitor to get the session id's,
then runs 'remove session' in iimonitor.

This all works swimmingly, but the code is quite complicated...
I was wondering if there is a better, simpler way to remove user
sessions?

Env is Ingres 2.5 & 2.6 on AIX 5.2

TIA Steve


Reply With Quote
  #2  
Old   
Roy Hann
 
Posts: n/a

Default Re: Script to remove user sessions from a DB - 09-13-2005 , 06:24 AM






"Steve McElhinney" <stevem (AT) 141 (DOT) com> wrote

Quote:
Part of our batch work requires exclusive access to a livedb, so
we need a UNIX script to remove all user sessions from the database.

We currently have a script that runs iinamu to get the server id's
then iimonitor to get the session id's,
then runs 'remove session' in iimonitor.

This all works swimmingly, but the code is quite complicated...
I was wondering if there is a better, simpler way to remove user
sessions?
Connect to imadb then EXECUTE PROCEDURE IMA_DROP_SESSIONS;

Roy Hann (rhann at rationalcommerce dot com)
Rational Commerce Ltd.
www.rationalcommerce.com
"Ingres development, tuning, and training experts"




Reply With Quote
  #3  
Old   
Gerhard Hofmann
 
Posts: n/a

Default Re: Script to remove user sessions from a DB - 09-14-2005 , 02:48 AM



Roy Hann wrote:
Quote:
Connect to imadb then EXECUTE PROCEDURE IMA_DROP_SESSIONS;

Roy Hann (rhann at rationalcommerce dot com)
Rational Commerce Ltd.
www.rationalcommerce.com
"Ingres development, tuning, and training experts"


Hi,

I have an Ingres report to produce the needed execute statements.

This report must be loaeded into imadb with sreport:
---snip---
..name removesessions
..output removesessions.sql
..query
select server, session_id from
ima_server_sessions
where db_name = 'fepa404'
..header report
.noff
.nl

.print "set autocommit on \\g" .nl
.print "\\sql" .nl
..detail
.print "execute procedure" .nl
.print "ima_remove_session(server_id = '" .print server .print "'," .nl
.print "session_id = '" .print session_id .print "')" .nl
.print "\\p\\g" .nl
---snip---

You will have to tweak the line line "where db_name..." to match your
environment.


A batch file removesessions.bat can be used to run it as a daily
scheduled task:
---snip---
report imadb removesessions > logfile.log
sql imadb < removesessions.sql >> logfile.log
---snip---

Regards
Gerhard


Reply With Quote
  #4  
Old   
stéphane lepeltier
 
Posts: n/a

Default Re: Script to remove user sessions from a DB - 09-27-2005 , 12:30 PM



Hi

Like you, i need to remove all user sessions from the database.
I make a UNIX script but it also shuts down the DBMS server.

Please, could you give me your script or look at mine and correct it.

Thanks.

Stephane



Reply With Quote
  #5  
Old   
Jean-Pierre Zuate
 
Posts: n/a

Default Re: [Info-ingres] Re: Script to remove user sessions from a DB - 09-28-2005 , 05:31 AM



Hi Stephane (and all the others),
I send you 2 examples :
- via a query on imadb (you can get the list of session_ptr by querying the
ima_server_sessions table in imadb)
- via iimonitor (sorry for english people, script comments are in french)
Perhaps you need to customize the following :
- path of grep and awk (I usualy use egrep and nawk)
- path of ksh (1st line of each shell)
- ensure those scripts are running with Ingres env variables
It should work "has it" on windows with cygwin interface.
Hope this help,
Jean-Pierre
Here is an example with IMADB :
*** SCRIPT BEGIN ***
#!/usr/bin/ksh
#
# Remove sessions from IMA

CONNECT_ID=${1:?"Give DBMS connect_id"}
SESSION_PTR=${2:?"Give a session ptr"}

export II_DBMS_SERVER=${CONNECT_ID}

echo "\
UPDATE
ima_mib_objects
SET
value = '1'
WHERE
server = dbmsinfo('ima_server')
AND
classid = 'exp.scf.scs.scb_remove_session'
AND
instance = '${SESSION_PTR}'
\p\g" | sql imadb

unset II_DBMS_SERVER
*** SCRIPT END ***
Here is the script with iimonitor
*** SCRIPT BEGIN ***
#!/usr/bin/ksh

#
# Obtenir la liste des PID des DBMS
LISTE_DBMS=$(ps -fuingres \
Quote:
grep "iidbms dbms" \
grep "$(ingprenv II_INSTALLATION)" \
grep -v grep \
awk '{ print $2 }')
#
# Pour chaque PID de DBMS
for DBMS_PID in ${LISTE_DBMS}
do
#
# On recherche le connect_id
CONNECT_ID=$(csreport | grep ${DBMS_PID} | awk '{ print $7 }' | sed 's/,//')

#
# On liste les sessions (echo show sessions)
# Du dbms CONNECT_ID
# Et on isole le numero de session
# Que l'on ajoute a la chaine remove
# Que l'on repasse au meme DBMS (meme CONNECT_ID)
# ce qui permet de les detruires ... (et voila !!! ;-)
echo show sessions \
Quote:
iimonitor ${CONNECT_ID} \
sed 's/IIMONITOR> //g' \
grep -i session \
awk '{ printf "remove %s\n", $2}' \
iimonitor ${CONNECT_ID}
echo "Les sessions du DBMS ${CONNECT_ID}/${DBMS_PID} ont ete detruites."

done
*** SCRIPT END ***
2005/9/27, stéphane lepeltier <lepeltier.stephane (AT) free (DOT) fr>:
Quote:
Hi

Like you, i need to remove all user sessions from the database.
I make a UNIX script but it also shuts down the DBMS server.

Please, could you give me your script or look at mine and correct it.

Thanks.

Stephane


_______________________________________________
Info-ingres mailing list
Info-ingres (AT) cariboulake (DOT) com
http://mailman.cariboulake.com/mailm...py/info-ingres



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.