In my database many programs/modules uses sys/system connection to perform operations on data.
eg: sys/ as sysdba
perform dml's,ddl's or any user requirements.
I want to replace this connection string with some other user . Is there any way to identify these programs/modules/procedures/package which are run through sys/system?
My requirement is to find all the programs using sys/system connection string
Absolutely. While the standard auditing would provide you with some info, it is rather limited. You need a logon trigger that captures enriched session information and logs it. Here's an example:
Obviously you'd need to create the logging table (
sys_connection_login my example). A few notes:To prevent any chance of causing problems for background processes we check the audsid (
SYS_CONTEXT('USERENV','SESSIONID')returnsv$session.audsidwhich is 0 or 0,4294967295 for background processes) and do nothing if it's a background process. Just being extra cautious. We could have simply queriedv$sessionand looked atTYPE, but this allows us to quit without even a single query.The insert itself is wrapped in a dynamic
EXECUTE IMMEDIATEblock. While this isn't strictly necessary because there's nothing dynamic about the SQL, this is a safety measure. If anything is wrong with your SQL, or if your logging table gets dropped or anything that could cause the SQL to fail parsing, you don't want the trigger to become invalid and possibly prevent logons from happening. This way, any parsing failure will simply raise an exception within the trigger which we then handle and do nothing (WHEN OTHERS THEN NULL).We use an autonomous transaction so we can commit our insert. That may not be necessary for a logon trigger as Oracle might still have an implicit commit that will follow the trigger since it is a system event, but just to be sure, we want to ensure our record is preserved nonetheless. You cannot do a commit in a trigger without
PRAGMA AUTONOMOUS_TRANSACTION.