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;

相关推荐
oradh9 小时前
Oracle固定执行计划的方法---SQL Plan Baseline
数据库·sql·oracle
杨云龙UP12 小时前
Oracle 19c ADG 实时同步故障排查与修复:Standby Redo Log(SRL)文件缺失导致备库仅在主库归档后同步
数据库·oracle·adg·data guard·srl·ora-00313·ora-27037
SmartSoftHelp开发辅助优化13 小时前
SmartSoftHelp DeepCore XSuite Pro Global Eco AIAgent 2026.V29 专业国际版
数据库·oracle
zxcvb15314 小时前
规定备份信息的备份方式:从策略制定到自动化落地的实践思考
运维·oracle·自动化
杨云龙UP2 天前
Oracle 19c 单机到单机 Active Data Guard 搭建与巡检操作手册
数据库·oracle·adg·操作指南·data guard·dg搭建
我科绝伦(Huanhuan Zhou)2 天前
oracle坏块导致备份不了
数据库·oracle·ffmpeg
杨云龙UP2 天前
Oracle 19c RAC到RAC Active Data Guard标准搭建与巡检指南
运维·服务器·数据库·oracle·adg·data guard·rac到rac
许彰午2 天前
06-Oracle卸载与重装完整流程
数据库·oracle
我的xiaodoujiao2 天前
Django 基础知识详细图文教程 13-Django 模型定义与使用 3
数据库·后端·python·测试工具·oracle·django
我科绝伦(Huanhuan Zhou)2 天前
oracle RAC共享存储换盘操作指南
数据库·oracle