Date and time of last table access [message #236665] |
Thu, 10 May 2007 10:45 |
mc_tyner
Messages: 2 Registered: May 2007
|
Junior Member |
|
|
Hello,
Is there any way to know last time a table has been accessed (via select or insert or update or delete commands)?
Is this function present in TOAD?
THANKS
|
|
|
|
|
|
|
|
Re: Date and time of last table access [message #236679 is a reply to message #236672] |
Thu, 10 May 2007 11:06 |
saibal
Messages: 111 Registered: March 2007 Location: India
|
Senior Member |
|
|
True. I noticed that the OP wanted to note the selects on the table as well, so the trigger won't serve the purpose.
As for the second part of your answer, while auditing is the normal way to keep track of who accessed the table, triggers 'can' be written to do exactly that. There will be circumstances where one may be better than the other. It all 'depends'.
|
|
|
|
|
|
|
|
|
Re: Date and time of last table access [message #236939 is a reply to message #236903] |
Fri, 11 May 2007 06:51 |
|
Michel Cadot
Messages: 68722 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Here's a small exemple:
SQL> create table t (id integer, val char(80));
Table created.
SQL> declare
2 st pls_integer := dbms_utility.get_time;
3 begin
4 for i in 1..10000 loop
5 insert into t values(i, 'A');
6 end loop;
7 update t set val='B';
8 delete t;
9 dbms_output.put_line('No audit done in '||(dbms_utility.get_time-st)/100||'s');
10 end;
11 /
No audit done in 2.86s
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> drop table t purge;
Table dropped.
SQL> create table t (id integer, val char(80));
Table created.
SQL> audit insert, update, delete on t;
Audit succeeded.
SQL> declare
2 st pls_integer := dbms_utility.get_time;
3 begin
4 for i in 1..10000 loop
5 insert into t values(i, 'A');
6 end loop;
7 update t set val='B';
8 delete t;
9 dbms_output.put_line('Audit done in '||(dbms_utility.get_time-st)/100||'s');
10 end;
11 /
Audit done in 6.71s
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> noaudit insert, update, delete on t;
Noaudit succeeded.
SQL> drop table t purge;
Table dropped.
SQL> create table t (id integer, val char(80));
Table created.
SQL> create table a as select * from dba_audit_trail where 1=0;
Table created.
SQL> create or replace trigger trg_t
2 before insert or update or delete on t
3 begin
4 insert into a
5 (os_username, username, userhost, terminal, timestamp, owner, obj_name,
6 action, action_name, sessionid, os_process, entryid, statementid, returncode)
7 select osuser, username, machine, terminal, sysdate, user, 'T',
8 0, 'MY_ACTION', sid, process, 0, 0, 0
9 from v$session where sid = sys_context('userenv','SID');
10 end;
11 /
Trigger created.
SQL> declare
2 st pls_integer := dbms_utility.get_time;
3 begin
4 for i in 1..10000 loop
5 insert into t values(i, 'A');
6 end loop;
7 update t set val='B';
8 delete t;
9 dbms_output.put_line('With trigger done in '||(dbms_utility.get_time-st)/100||'s');
10 end;
11 /
With trigger done in 10.33s
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
No audit: 2.86s
Audit: 6.71s
Trigger: 10.33s
Note: trigger records much less data than audit.
Note: I did not display other important data: generated redo/undo, latches...
Regards
Michel
|
|
|
|
|