DBA_RECYCLEBIN purge指定日期前的表

Summary

How to purge DBA_RECYCLBIN for objects older than x days/minutes? or do we have RECYCLEBIN RETENTION feature or truncate recyclebin ?


DBA_RECYCLEBIN has a column called DROPTIME.

But we can not use the below queries to purge or delete the recyclebin objects older than 7 days

DELETE from DBA_RECYCLEBIN where droptime<sysdate-7; (wrong do not use)

PURGE DBA_RECYCLEBIN where droptime<sysdate-7; (wrong do not use)

SQL> DELETE from DBA_RECYCLEBIN where droptime<sysdate-7;

DELETE from DBA_RECYCLEBIN where droptime<sysdate-7

*

ERROR at line 1:

ORA-01752: cannot delete from view without exactly one key-preserved table

SQL> PURGE DBA_RECYCLEBIN where droptime<sysdate-7;

PURGE DBA_RECYCLEBIN where droptime<sysdate-7

*

ERROR at line 1:

ORA-00933: SQL command not properly ended

Solution

There is no direct command or RECYCLEBIN_RETENTION parameter to purge/delete with the droptime clause, so we have to use the workaround of identifying the objects and then drop them manually. There is an enhancement request filed through an Unpublished Bug 6694377, so the feature is still not available, but there is an easy workaround available.

Unpublished Bug 6694377 : ENHANCE PURGE COMMAND WITH TIME SPECIFIC CLAUSE

SELECT .... FROM DBA_RECYCLEBIN can have WHERE condition,

PURGE DBA_RECYCLEBIN can not have WHERE condition and throws syntax errors like ORA-00933: SQL command not properly ended

So you can workaround this by dynamically preparing sql queries to purge the recycle bin objects

Examples:

  1. Purge tables dropped before 7 days (older than 7 days)

SQL> spool purge_table_older_than_7_days.sql

SQL> select 'purge table '||owner||'."'||OBJECT_NAME||'";'

from dba_recyclebin

where type='TABLE' and to_date(droptime,'YYYY-MM-DD:HH24:MI:SS')<sysdate-7;

SQL> spool off;

  1. Purge tables dropped before 5 minutes (older than 5 minutes), use sysdate-(5/(24*60)) because 24 hours per day, 60 minutes per hour

SQL> spool purge_table_older_than_5_minutes.sql

SQL> select 'purge table '||owner||'."'||OBJECT_NAME||'";'

from dba_recyclebin

where type='TABLE' and to_date(droptime,'YYYY-MM-DD:HH24:MI:SS')<sysdate-(5/(24*60));

SQL> spool off;

SQL> spool purge_table_older_than_5_min.txt

SQL> @purge_table_older_than_5_minutes.sql

SQL> spool off;

相关推荐
淘矿人10 小时前
2026大模型API中转平台深度评测:weelinking领衔五大服务商横向实测与选型指南
开发语言·人工智能·python·oracle·数据挖掘·php·pygame
逻辑驱动的ken1 天前
Java高频面试考点场景题09
java·开发语言·数据库·算法·oracle·哈希算法·散列表
下地种菜小叶1 天前
定时任务系统怎么设计?一次讲清任务注册、分布式调度、幂等执行与失败补偿
java·开发语言·数据库·oracle·rabbitmq
-XWB-1 天前
【Oracle】Oracle诊断系列(5/6):统计信息与执行计划——优化器的“大脑”管理
数据库·oracle
大江东去浪淘尽千古风流人物1 天前
【cuVSLAM】项目解析:一套偏工程实战的 GPU 紧耦合视觉惯性 SLAM
数据库·人工智能·python·机器学习·oracle
oradh1 天前
Oracle数据库视图概述
数据库·oracle·数据库视图·oracle基础·oracle入门
爱学的小码1 天前
MySQL(进阶)--存储过程和触发器
数据库·oracle
懒铭心1 天前
RHEL 7 + Oracle 19.3.0 单实例部署指南
oracle
蜜獾云1 天前
交易系统之数据库弱依赖解决方案
数据库·oracle
林深时见鹿v1 天前
《后端开发全栈工具安装踩坑指南 & 经验沉淀手册》
java·人工智能·python·oracle