重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1105|回复: 0
打印 上一主题 下一主题

[Oracle] 确认oracle中表被truncate的具体时间

[复制链接]
跳转到指定楼层
楼主
发表于 2023-1-5 11:11:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
文档课题:确认oracle中表被truncate的具体时间.
数据库:oracle11.2.0.4
1、场景准备
SYS@orcl>create table leo.tspitr_emp tablespace leo_ts as select * from scott.emp;
Tablecreated.
SYS@orcl10:19:45> select * from v$log;
    GROUP#   THREAD#  SEQUENCE#      BYTES BLOCKSIZE    MEMBERS ARCSTATUS           FIRST_CHANGE# FIRST_TINEXT_CHANGE# NEXT_TIM
-------------------- ---------- ---------- ---------- ---------- --- ----------------------------- -------- ------------ --------
         1          1         74  52428800        512          1 YES ACTIVE                 3234061 09:45:08      3235739 10:19:30
         2          1         72  52428800        512          1 YES INACTIVE               3229699 09:19:29      3234056 09:44:59
         3          1         73  52428800        512          1 YES INACTIVE               3234056 09:44:59      3234061 09:45:08
        11          1         75  52428800        512          2 NO CURRENT                323573910:19:30   2.8147E+14
        12          1         68  52428800        512          2 YES INACTIVE               3193114 11:27:02      3200620 14:51:46
        13          1         69  52428800        512          2 YES INACTIVE               3200620 14:51:46      3206240 17:16:24
        14          1         70  52428800        512          2 YES INACTIVE               3206240 17:16:24      3206704 17:29:54
        15          1         71  52428800        512          2 YES INACTIVE               3206704 17:29:54      3229699 09:19:29
8 rowsselected.
SYS@orcl10:19:55> truncate table leo.tspitr_emp;
Tabletruncated.
2truncate时间确认2.1logminer方案
说明:由于测试库redo较少,从v$log判断truncate操作在75号日志中.此处采用logminer找回truncate误操作的具体时间.生产环境恢复时需确认到准确的时间点,以减少数据的丢失.
--确认该时间段的归档日志,其实此处可以直接分析redo日志,并不一定非要分析归档日志.
SYS@orcl10:47:57> select sequence#,to_char(first_time,'yyyy-mm-dd hh24:mi:ss') asTIME,round(sum(blocks*block_size)/1024/1024) as "Size(M)",NAME fromv$archived_log where first_time between to_date('2022-12-24 10','yyyy-mm-ddhh24') and to_date('2022-12-24 11','yyyy-mm-dd hh24') and dest_id=1 group byfirst_time,name,sequence# order by 1 desc;
no rowsselected
SYS@orcl10:56:34> alter system switch logfile;
Systemaltered.
SYS@orcl10:57:03> col name for a60
SYS@orcl10:57:28> select sequence#,to_char(first_time,'yyyy-mm-dd hh24:mi:ss') asTIME,round(sum(blocks*block_size)/1024/1024) as "Size(M)",NAME fromv$archived_log where first_time between to_date('2022-12-24 10','yyyy-mm-ddhh24') and to_date('2022-12-24 11','yyyy-mm-dd hh24') and dest_id=1 group byfirst_time,name,sequence# order by 1 desc;
SEQUENCE# TIME                   Size(M) NAME
----------------------------- ----------------------------------------------------------------------
        75 2022-12-24 10:19:30          1/u01/app/oracle/oradata/archivelog/1_75_1122831323.dbf
--进行归档日志分析.
SYS@orcl10:57:29> executedbms_logmnr.add_logfile('/u01/app/oracle/oradata/archivelog/1_75_1122831323.dbf',dbms_logmnr.new);
PL/SQLprocedure successfully completed.
SYS@orcl11:03:41> execdbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);
PL/SQLprocedure successfully completed.
SYS@orcl11:06:57> col sql_redo for a50
SYS@orcl11:07:12> select a.scn,a.timestamp,a.sql_redo from v$logmnr_contents a wheretable_name='TSPITR_EMP' and operation='DDL' order by a.scn;
       SCN TIMESTAM SQL_REDO
------------------ --------------------------------------------------
   3235800 10:20:54 truncate tableleo.tspitr_emp;
说明:由此确认到执行truncate的时间为10:20:54.
2.2dba_objects方案
也可以通过视图dba_objects中的LAST_DDL_TIME字段来确认truncate时间,如下所示:
SYS@orcl10:39:07> select owner,object_name,object_type,to_char(created,'yyyy-mm-ddhh24:mi:ss'),to_char(last_ddl_time,'yyyy-mm-dd hh24:mi:ss') from dba_objectswhere object_name='TSPITR_EMP';
OWNER      OBJECT_NAME     OBJECT_TYPE         TO_CHAR(CREATED,'YYTO_CHAR(LAST_DDL_TI
------------------------- ------------------- ------------------- -------------------
LEO        TSPITR_EMP      TABLE               2022-12-24 09:51:32 2022-12-2410:20:54
2.3trace日志
--也可以在trace日志中查看到具体的truncate时间.
Sat Dec24 10:20:54 2022
truncatetable leo.tspitr_emp
相关视图:
dba_tab_modificationstimestamp字段.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-6-3 17:19 , Processed in 0.097985 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表