How to get the DB2 database connection count

15 January,2015 by Jack Vamvas

How do I get  DB2 connection count ?I need this information to supply a application restart workflow. Rather than just issuing a db2stop force, I want to send a response to the workflow program , which issues the message to the Operator. The Operator can decide  on the a course of action.

For example, there may be a backup in progress or an application may not have been shut down successfully.

Answer: There are a number of methods provided by DB2 to supply the connection details.  The decision on approach  depends on specific requirements and tolerance for precision. 

In your case, you simply need a method to indicate that not only are the databases active but there are connections. You’re  requesting whether  there is a connection count greater than 0, for a database.

A problem to overcome is differentiating between an explicit and implicit database activation. For example, if a database is active , it is possible a DBA has executed a   db2 activate db .This activity would be defined as an explicit activation

 As opposed to an application requesting a connection which implicitly activates the database.

You can check all these impacts by using the list active databases command . If the database is active, it will appear in the list. If there is a connection, there will be a number greater than 0 on the Application connected currently value.

Methods to use for getting the DB2 database connection count

Explore these commands , return the information and assess how relevant it is to you’re requirement. I prefer using the db2pd methods, as they use a latch free method of accessing the data required.

 

--check how long the database is active
Db2pd –alldbs –
db2pd -alldatabases -bufferpools | grep Database
db2 list active databases
--Look at the snapshot for the database manager
db2 -v get snapshot for database manager 
db2 -v get snapshot for database manager | grep ‘Applications connected currently’


Read more on db2pd and connections

DB2 database hangs on db2 connect - use db2pd to troubleshoot

DB2 block all connections to a database - svcename - DBA DB2

Author: Jack Vamvas(http://www.dba-db2.com)

Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to get the DB2 database connection count

Comments are moderated, and will not appear until the author has approved them.


dba-db2.com | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright