Question

How to write a PL/SQL program to calculate and display the username and average session time for all database users in oracle 11g ? kindly help

Was it helpful?

Solution

By default Oracle does not audit things like user access. There are built-in options, but they are switched off by default.

To enable Oracle's audit trail, we need to set the AUDIT_TRAIL parameter. Set it to DB to have records written to a table; this is more convenient for querying than an OS file (unless your grep is better than your SQL). Find out more.

To monitor user connections and disconnections, ask a DBA to issue the following statement:

AUDIT SESSION;

Then you can write your query off the DBA_AUDIT_SESSION view. Something like:

select USERNAME
       , avg(LOGOFF_TIME - TIMESTAMP)
from DBA_AUDIT_SESSION
group by USERNAME;

Note that this is on;y going to give you meaningful information if you have an application with Old Skool named user accounts. Web applications with connection pooling will all be audited as the same user, so you will need to write a bespoke logging tool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top