Skip to Main Content
  • Questions
  • Last DML Operation timestamp on Production

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Nikhil.

Asked: November 16, 2016 - 1:14 pm UTC

Last updated: November 19, 2016 - 1:56 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hi,

I need to get timestamp of last DML operation performed on table from Production.

I tried using -
SELECT SCN_TO_TIMESTAMP(MAX(ORA_ROWSCN)) from mytablename;
SELECT MAX(SCN_TO_TIMESTAMP(ORA_ROWSCN)) from mytablename;

Non of them worked -
ORA-08181 error ("specified number is not a valid system change number")

Could you please help how can I get this information from Production.

and Connor said...

We dont store the mapping from SCN to time indefinitely.

But if you can query ORA_ROWSCN, you can compare it to V$LOG_HISTORY to get an approximate idea of when the DML was performed.

SQL> select max(ora_rowscn) from test_tab;

MAX(ORA_ROWSCN)
---------------
       93058248

1 row selected.

SQL> select SCN_TO_TIMESTAMP(93058248) from dual;
select SCN_TO_TIMESTAMP(93058248) from dual
       *
ERROR at line 1:
ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1

SQL> @pt "select * from  v$log_history where 93058248 between FIRST_CHANGE# and NEXT_CHANGE#"
RECID                         : 2901
STAMP                         : 927332741
THREAD#                       : 1
SEQUENCE#                     : 2901
FIRST_CHANGE#                 : 93049120
FIRST_TIME                    : 07-nov-2016 19:00:21
NEXT_CHANGE#                  : 93110880
RESETLOGS_CHANGE#             : 2233668
RESETLOGS_TIME                : 13-nov-2015 12:21:07
CON_ID                        : 0


Rating

  (2 ratings)

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

Comments

Perfect. Thanks a lot Connor McDonald.

A reader, November 17, 2016 - 5:36 am UTC


Connor McDonald
November 18, 2016 - 4:10 am UTC

glad we could help

Some Tables Not havinf record in V$loghistory

A reader, November 18, 2016 - 6:55 am UTC

Hi Connor,

Thanks for your reply.
Some tables are not having record in v$loghistory table,
though max ORA_ROWSCN value is there in table.

Could you please help?
Connor McDonald
November 19, 2016 - 1:56 am UTC

It could be in the current log (v$log)