Skip to Main Content
  • Questions
  • remove user who have not logged in for 3 months..

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Carine .

Asked: May 02, 2000 - 1:20 pm UTC

Last updated: February 18, 2004 - 9:52 pm UTC

Version:

Viewed 1000+ times

You Asked

I work on Oracle 7.3.4 and want to clean up users who
haven't logged on for more than 3 months. How to...?
Thanks very much in advance.




and Tom said...



Well, we will have to wait 3 months to drop the first user however -- the process you follow is:

o enable AUDITING in your database. You do this by setting "audit_trail=true" in your init.ora and restarting

o directing the system to audit connections, it might look like this:

SVRMGR> audit session by access;
Statement processed.


Then, to monitor logins, you can:

SVRMGR> select username, to_char( timestamp, 'dd-mon-yyyy hh24:mi:ss' ), priv_used from dba_audit_trail;

USERNAME TO_CHAR(TIMESTAMP,'DD-MON-YYYYHH24:MI:SS') PRIV_USED
--------------- -------------------------------------------- --------------------
SCOTT 16-feb-2000 08:30:09 CREATE SESSION
1 row selected.


beware -- watch the size of your sys.aud$ table!!! you might have to copy it to another place and delete from it periodically to avoid having your system tablespace grow and grow over time. SYS is not audited (so if system fills up and no one can log in due to system being full and no room for audit entries, SYS can still log in and clean up).


Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Can I selectively delete from sys.aud$ table ???

Alan Rosenthal, February 17, 2004 - 7:15 pm UTC

Hi,

I want to do the samething. However, my aud$ table is growing very fast and I only care about who logs in - not how many times they log in. Therefore, I would like to purge this table.

Is it safe, sane and kosher to delete all records for each userid except for the one with the max sessionid (I just want to keep one record for each user and max sessionid seemed like a good enough way to pick the survivors):

-- create a list of what I want to keep.
create table aud_list as
select userid, max( sessionid ) sessionid
from sys.aud$
group by userid ;

-- Delete everything not in the list.
delete from sys.aud$
where sessionid not in
select sessionid
from aud_index ;

-- get rid of list.
drop table aud_list ;

Thanks,

Alan

Tom Kyte
February 17, 2004 - 7:39 pm UTC

what version do you have?

Version

alan rosenthal, February 18, 2004 - 1:07 pm UTC

Hi,

Sorry I forgot to include the versions. One DB is 9.2.0.4 and the other one is 8.1.7.3

Tom Kyte
February 18, 2004 - 9:29 pm UTC

use a logon trigger instead. just update a row by user name and if sql%rowcount = 0, insert it.

(eg: don't use auditing in this particular case)

Another similar article

eric givler, February 18, 2004 - 9:52 pm UTC

That's exactly what we ended up with, as alluded to in:

</code> http://asktom.oracle.com/pls/ask/f?p=4950:61:3076181060304310743::::P61_ID:1830072957439 <code>