Home » RDBMS Server » Server Administration » Log in time to database
Log in time to database [message #62812] Tue, 17 August 2004 01:32 Go to next message
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 Go to previous messageGo to next message
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 #62816 is a reply to message #62814] Tue, 17 August 2004 04:32 Go to previous messageGo to next message
kjl
Messages: 48
Registered: June 2003
Member
Hi Vivek,

Where can I read logon-logoff times?

Thanks, Karri
Re: Log in time to database [message #62817 is a reply to message #62816] Tue, 17 August 2004 06:00 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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
Re: Log in time to database [message #62841 is a reply to message #62812] Wed, 18 August 2004 23:15 Go to previous message
Thomas
Messages: 67
Registered: September 1999
Member
Make sure audit_trail = true in init<sid>.ora
and then:

SQL> audit connect whenever successful

There are various dba_audit views available to report on the connects.

Hope that helps,

clio_usa - OCP DBA 8/8i/9i

Oracle DBA Resources
Oracle DBA Forums
USENET Oracle newsgroups
Previous Topic: How to Export/Zip and Split simultaneously ?
Next Topic: query that blocks db processes
Goto Forum:
  


Current Time: Thu Jan 09 14:12:23 CST 2025