Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / October 2007

Tip: Looking for answers? Try searching our database.

Disconnecting all the connections to only one database in an instance

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rahul Babbar - 25 Oct 2007 00:43 GMT
Hi,

If i want to disconnect all the connections to a particular database,
what should be done....
db2 force applications all....
will not be preferred since it'l close all the connections to all the
databases....
and
db2 force applications(<app_id1>, <app_id2>......etc) .......
might be very cumbersome.....further, connections do continue coming
in.....so using
db2 force applications(<app_id1>, <app_id2>......etc)
will take a lot of time and effort if there are lots of people
connected to it....

Is there some simpler way to disconnect all the connections for a
particular database only?

Thanks

Rahul
Larry - 25 Oct 2007 02:32 GMT
You might want to look at the QUIESCE command.

Larry E.

> Hi,
>
[quoted text clipped - 17 lines]
>
> Rahul
Mark A - 25 Oct 2007 03:13 GMT
> You might want to look at the QUIESCE command.
>
> Larry E.

That works fine unless the bozos you inherited the database from used
instance owner ids to connect to the database from the application tier.
QUIESCE does not lock out instance owner id.
Lennart - 25 Oct 2007 07:22 GMT
> Hi,
>
[quoted text clipped - 13 lines]
> Is there some simpler way to disconnect all the connections for a
> particular database only?

I use a script to do what you describe. As Larry pointed out, check
out QUIESCE. My situation is pretty much what Mark described, so
QUISCE is not an option for me

~/bin]$ cat force_db.sh
#!/bin/sh

db=$1
if [ "x$db" = "x" ]; then
       echo "Usage: force_db.sh <dbname>"
       exit 1
fi

dbname=`echo $db | tr "a-z" "A-Z"`
for a in `db2 list applications | grep " $dbname " | awk '{ print
$3 }'`; do
       db2 -v "force application ($a)"
done

> Thanks
>
> Rahul
Lennart - 25 Oct 2007 07:36 GMT
[...]

> dbname=`echo $db | tr "a-z" "A-Z"`
> for a in `db2 list applications | grep " $dbname " | awk '{ print
> $3 }'`; do
>         db2 -v "force application ($a)"
> done

Oh, I should mention, awk '{ print $3 }' is far from ideal, but works
in most cases for me. A safer variant would be to get appl.id as:

awk '{ print substr($0, 24, 5) }'

not sure if substr is avalible for all awk though

/Lennart

> > Thanks
>
> > Rahul
Ian - 26 Oct 2007 05:28 GMT
> Oh, I should mention, awk '{ print $3 }' is far from ideal, but works
> in most cases for me. A safer variant would be to get appl.id as:
>
> awk '{ print substr($0, 24, 5) }'
>
> not sure if substr is avalible for all awk though

Out of curiosity, why is "print $3" bad?  And is it any worse than
using substr?

To me, substr is worse, because now you're dependent on columns lining
up properly.  Whereas using $3 will always work unless IBM changes the
columns in the list (either adds/removes or changes order).
Lennart - 26 Oct 2007 06:18 GMT
> > Oh, I should mention, awk '{ print $3 }' is far from ideal, but works
> > in most cases for me. A safer variant would be to get appl.id as:
[quoted text clipped - 5 lines]
> Out of curiosity, why is "print $3" bad?  And is it any worse than
> using substr?

Sometime the second column (Appl name) is all spaces. print $3 in
those cases will spit out Application id instead

> To me, substr is worse, because now you're dependent on columns lining
> up properly.  Whereas using $3 will always work unless IBM changes the
> columns in the list (either adds/removes or changes order).

See above. Anyhow, I just wanted to point out that print $3 might
fail. For me print $3 works frequently enough, but it might not be the
case for the OP.

/Lennart
Toralf Förster - 26 Oct 2007 08:47 GMT
> dbname=`echo $db | tr "a-z" "A-Z"`

BTW, tr "[[:lower:]]" "[[:upper:]]" is the better choice b/c it works in
other LANG environments too.

Signature

Toralf Förster
pgp key 0x7DB69DA3

4.spam@mail.ru - 26 Oct 2007 08:23 GMT
> Hi,
>
> If i want to disconnect all the connections to a particular database,
> what should be done....

Hello.
You can create a simple udf that uses force application API
(sqlefrce):
---- admin.c ----
#include <sqludf.h>
#include <sqlenv.h >

#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN force_app(
       SQLUDF_INTEGER *agentid,
       SQLUDF_INTEGER *result,
       SQLUDF_NULLIND *agentid_ind,
       SQLUDF_NULLIND *result_ind,
       SQLUDF_TRAIL_ARGS)
{
 struct sqlca sqlca;
 sqluint32 agentids[1];

 agentids[0] = *agentid;
 sqlefrce(1, &agentids[0], SQL_ASYNCH,&sqlca);
 *result_ind = 0;
 *result = sqlca.sqlcode;
}
---- admin.c end ----

Register it:
---- force_app.sql ---
CREATE FUNCTION force_app (agentid int)
RETURNS int
EXTERNAL NAME 'admin!force_app'
LANGUAGE C
PARAMETER STYLE SQL
DETERMINISTIC
FENCED
NOT NULL CALL
NO SQL
EXTERNAL ACTION
NO FINAL CALL
DISALLOW PARALLEL;
---- force_app.sql end ---

And use it while connected to desired database:
---
select count(force_app(int(agent_id)))
from table(snap_get_appl_info(cast(null as varchar(1)), -2)) s
where appl_id!=application_id()
---

Sincerely,
Mark B.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.