I’ve got a bad code duplication problem where we cannot tell which versions of packages/procedures are being used. i.e. I have different packages with procedures of the same name and I need to be sure which packages are not actually being called.
I’m trying to eliminate procedures/packages of the same name which are no longer being called. I’d like to run the trace for a few weeks, combine the data and query the metadata against it and find candidates for further investigation and deactivation.
I’m looking for the equivalent of SQL Server’s sp_trace_create with sp_trace_setevent 42 to track the SP:Starting event – this would allow me to see all the stored procedures being called and then compare that to the entire inventory of stored procedures to see which ones should be investigated first for obsolescence. I have used DBMS_MONITOR.DATABASE_TRACE_ENABLE to generate trace files, but I haven’t found anything which explains how to use TKPROF to parse those files for anything but performance – nor do I even care about the statements themselves, just which routines are being used.
Dont think ILO will help (does it do more than just set the module and action and log the time somewhere ?) as Cade Roux would have to modify every package and function in the database.
One option is to switch on tracing at the database,
and use a script command to get a unique list of all the package names executed although WARNING – this will generate a lot of output and fill up disk space very rapidly – you may want to create a file of the procedures run each day and then remove the trc files and then combine the results all together to identify which ones are used.
Also you need to ensure there is no limit on the trace file size which could prevent it logging everything and also ensure you have plenty of disk space and as you are not interested in the runtimes, you can also turn timed_statistics off to reduce the amount of logging.
If i look at the raw trace files created from Oracle tracing, each application specific package call procedure call appears like this
so you can grep for the list of package calls like this in the directory (you might have to tweak the output a little depending on the OS you are using in case the tkprof output is different)
This doesnt work with functions as they can be called in the middle of SQL statements but i think for procedures, it should be ok. This will produce a file in your home directory containing the unique list of procedure calls that have run since you turned on tracing.
I did a run of this on a directory containing 9818 trace files totalling 19GB of diskspace and it took 10 minutes on a test box running Oracle enterprise Linux 5 with 2 cores and 12GB memory – these trace files are just from repeated test runs of one program so you can imagine how quickly these will be created if you are generating for everything in a production machine.
Then you can get a list of all pacakges/procedures in the database from sqlplus for the particular schema you are interested in
and finally do a diff of the two to get a list of candidates
Dont forget to switch off tracing when you are done
Also, you need to be careful about procedures which may only be run at certain periods like month end or year end – they may appear not to be being used but you cant be sure unless every business process is completed during the time you are monitoring.
Hope that helps.