Python Script to check inserts per second in DB2 Databases V9
Script to check the rate per second of inserts in db2 databases
Check the related content to use PyDB2 to connect to DB2 using python
To execute the script, inform the database name and number of execution:
python <database_name> <num_execution>
Example:
python sample 50
Script:
#!/usr/bin/python
# -*- coding: 1252 -*-
"""
Author: Vinícius Rodrigues da Cunha Perallis
http://www.dbatodba.com
Script Name:check_inserts_seconds.py
Function: Check rowsinserted per seconds in DB2 Databases
Created in: 01/23/2009
"""
import sys
import DB2
import time
#Get the database name and the number of execution from command line
try:
database=sys.argv[1]
except:
print "Please inform the database name"
sys.exit(1)
try:
num_executions=int(sys.argv[2])
except:
print"Please inform the number of execution"
sys.exit(1)
#Create a database connection
try:
conn = DB2.connect(dsn=database,uid='db2inst1',pwd='db2inst1')
curs=conn.cursor()
except:
print "Connection was uncessufully"
sys.exit(1)
for i in range(num_executions):
curs.execute('select ROWS_INSERTED from sysibmadm.snapdb')
rows1 = curs.fetchone()
time.sleep(2)
curs.execute('select ROWS_INSERTED from sysibmadm.snapdb')
rows2 = curs.fetchone()
print (rows2[0] - rows1[0])/2
#Close the database connection
curs.close()
conn.close()