Log in time to database [message #62812] |
Tue, 17 August 2004 01:32 |
kjl
Messages: 48 Registered: June 2003
|
Member |
|
|
Hi,
I'd like to collect data for users login times and log off times.
Is it possible and if it is possible, how can I get this data.
BR Karri
|
|
|
Re: Log in time to database [message #62814 is a reply to message #62812] |
Tue, 17 August 2004 03:45 |
Vivek Vijai
Messages: 67 Registered: April 2004
|
Member |
|
|
Yes!
U can use Oracle Auditing for the same.
Set the parameter AUDIT_TRAIL=DB.
Then give the following stmt
SQL> Audit session;
This will record all the successful/unsuccessful connections/disconnections.
Vivek
|
|
|
|
Re: Log in time to database [message #62817 is a reply to message #62816] |
Tue, 17 August 2004 06:00 |
Frank Naude
Messages: 4587 Registered: April 1998
|
Senior Member |
|
|
Here's an example:
SQL> ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE;
System altered.
SQL> STARTUP FORCE
ORACLE instance started.
Total System Global Area 289406976 bytes
Fixed Size 1301536 bytes
Variable Size 262677472 bytes
Database Buffers 25165824 bytes
Redo Buffers 262144 bytes
Database mounted.
Database opened.
SQL> SHOW PARAMETER audit_trail
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_trail string DB
SQL> AUDIT SESSION;
Audit succeeded.
SQL>
SQL> conn scott/tiger
Connected.
SQL> conn crap/crap
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> conn / as sysdba
Connected.
SQL>
SQL> SELECT username, action_name, returncode, to_char(timestamp, 'DD-MON-YYYY HH24:MI:SS') time
2 FROM dba_audit_session
3 /
USERNAME ACTION_N RETURNCODE TIME
------------------------------ -------- ---------- --------------------
SCOTT LOGOFF 0 17-AUG-2004 16:00:59
CRAP LOGON 1017 17-AUG-2004 16:01:00
Best regards.
Frank
|
|
|
Re: Log in time to database [message #62827 is a reply to message #62812] |
Tue, 17 August 2004 21:20 |
Daljit Singh
Messages: 290 Registered: October 2003 Location: Texas
|
Senior Member |
|
|
Hi,
Along with DB Audit, you can also create a system level trigger on Logon/Logoff events to catch some more information in a user defined table.
For syntax of Logon/Logoff trigger refer oracle doc.
Daljit Singh
|
|
|
Re: Log in time to database [message #62829 is a reply to message #62816] |
Tue, 17 August 2004 23:01 |
Vivek Vijai
Messages: 67 Registered: April 2004
|
Member |
|
|
U can create a trigger like this...
create table myaudit (username varchar2(20),logintime date);
create trigger sys_tr after logon on database
begin
insert into myaudit values(user,sysdate);
end;
This will keep the username and its login time to any schema (including sys) in the myaudit table similarly u can create before logout trigger remember converse cannot be dun ie after logout/before login.
Vivek
|
|
|
|