Another note for my own convenience.
Slightly modified Oracle login/logout auditing scripts (table and triggers) I've found on net. Logon and logoff dates have been changed to timestamps, elapsed seconds now have fractional part.
First, the table:
create table user_audit_log
(
user_id varchar2(30 byte),
session_id number(8),
host varchar2(30 byte),
last_program varchar2(48 byte),
last_action varchar2(32 byte),
last_module varchar2(32 byte),
logon_ts timestamp,
logoff_ts timestamp,
elapsed_seconds number
)
Login trigger:
create or replace trigger logon_audit_trigger
after logon on database
begin
insert into user_audit_log values(
user,
sys_context('USERENV','SESSIONID'),
sys_context('USERENV','HOST'),
null,
null,
null,
current_timestamp,
null,
null
);
end;
Logout trigger:
create or replace trigger logoff_audit_trigger
before logoff on database
begin
update user_audit_log
set last_action = (select action from v$session where sys_context('USERENV','SESSIONID') = audsid)
where sys_context('USERENV','SESSIONID') = session_id;
update user_audit_log
set last_program = (select program from v$session where sys_context('USERENV','SESSIONID') = audsid)
where sys_context('USERENV','SESSIONID') = session_id;
update user_audit_log
set last_module = (select module from v$session where sys_context('USERENV','SESSIONID') = audsid)
where sys_context('USERENV','SESSIONID') = session_id;
update user_audit_log
set logoff_ts = systimestamp
where sys_context('USERENV','SESSIONID') = session_id;
update user_audit_log
set elapsed_seconds =
extract(day from (logoff_ts - logon_ts)) * 24*60*60 +
extract(hour from (logoff_ts - logon_ts)) * 60*60 +
extract(minute from (logoff_ts - logon_ts)) * 60 +
extract(second from (logoff_ts - logon_ts))
where sys_context('USERENV','SESSIONID') = session_id;
end;
Everyting as a sql file: user_audit_log.sql.