IBM Maximo: Cleanup WOGEN table

From Wiki

WOGEN table data growing exponentially. Is very important to cleanup this table

Details here: WOGEN table data growing exponentially

Create an Automation Script

1) Navigate to the System Configuration > Platform Configuration > Automation Scripts application. 2) From the Select Action menu, choose the Create > Script option. 3) Populate the fields:

  • Script: MAX_CLEANUP_WOGEN
  • Description: Automation Script to cleanup WOGEN table
  • Script Language: python
  • Log Level: ERROR
  • Source: <put source code below>

4) Click the Create button to create the new script


Create a Crontask

1) Navigate to the System Configuration > Platform Configuration > ron Task Setup application. 2) From the Common Actions menu, choose the Create > New Cron Task Definition option. 3) Populate the fields:

  • Cron Task: MAX_CLEANUP_WOGEN
  • Description: Maximo Maintanance Cleanup WOGEN table
  • Class: com.ibm.tivoli.maximo.script.ScriptCrontask

Click the Save button

4) Click the New Row button under the Cron Task Instances table

5) Populate the fields:

  • Cron Task Instance Name: MAX_CLEANUP_WOGEN01
  • Description: Cron Task to cleanup WOGEN table
  • Schedule: 1M,0,0,0,1,*,*,*,*,*
  • Run as User: MAXADMIN
  • Active: Yes
  • Keep History: Yes
  • Max Number of History Records: 100

Click the Save button

6) In Cron Task Parameters table at the bottom of the page. Populate

  • SCRIPTARG: DAYS=5,NUMROWS=1000
  • SCRIPTNAME: MAX_CLEANUP_WOGEN

Click the Save button

Automation Script - Source Code

#
# MAX_CLEANUP_WOGEN Automation Script called from a Cron Task
# this script cleanup WOGEN table
#
from java.lang import System
from psdi.server import MXServer
from psdi.util.logging import MXLoggerFactory

mxserver = MXServer.getMXServer()
logger = MXLoggerFactory.getLogger("maximo.maximodev")

def string_to_dict(input_string):
    res_dict = {}
    pairs = input_string.split(',')
    
    for pair in pairs:
        key, value = pair.split('=')
        if value is not None:
            res_dict[key.lower()] = value
    
    return res_dict

# Execute delete statement
def execDelete(days, numrows):
    logger.debug("MAX_CLEANUP_WOGEN - execDelete - start")
    
    sql = 'delete from WOGEN where rundate < (sysdate-' + days + ') and rownum <= ' + numrows
    conKey = mxserver.getSystemUserInfo().getConnectionKey()
    con = mxserver.getDBManager().getConnection(conKey)
    try:
        stmt= con.createStatement()
        stmt.executeUpdate(sql)
        stmt.close()
        con.commit()
    except:
        print('MAX_CLEANUP_WOGEN - execDelete - exception')
    finally:
        mxserver.getDBManager().freeConnection(conKey)


# ======================== main ======================== 
logger.info('MAX_CLEANUP_WOGEN start script -- running')
print('MAX_CLEANUP_WOGEN start script -- running')

# Get the variables from the cron task arguments
days = '1'
numrows = '100'

if arg:
    arg_dict = string_to_dict(arg)
    if 'days' in arg_dict:
        days = arg_dict['days']
    if 'numrows' in arg_dict:
        numrows = arg_dict['numrows']

print('MAX_CLEANUP_WOGEN days = ' + days + '; numrows = ' + numrows )

execDelete(days,numrows)

logger.info('MAX_CLEANUP_WOGEN end script')

Ver também