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;

相关推荐
Leon-Ning Liu4 小时前
【真实经验分享】Oracle RAC 修改 db_file_name_convert / log_file_name_convert 参数实践
数据库·oracle
Leon-Ning Liu4 小时前
【真实经验分享】Oracle RAC + ASM 下 db_recovery_file_dest 路径格式导致 ORA-01261 无法 NOMOUNT
数据库·oracle
踏月的造梦星球21 小时前
DMHS同步原理与DM8到DM8基础搭建
数据库·oracle
微三云 - 廖会灵 (私域系统开发)1 天前
电商系统监控告警体系从0到1:Prometheus+Grafana+AlertManager的全链路可观测性实践
oracle·grafana·prometheus
G.O.G.O.G1 天前
LeetCode SQL 从入门到精通(MySQL)05(下)
数据库·sql·oracle
alxraves1 天前
医院远程会诊系统:数据库模块设计与实现
数据库·oracle
苦瓜汤补钙1 天前
Oracle JDK8 环境配置-Win11
开发语言·数据库·笔记·oracle
️学习的小王1 天前
MySQL 数据库基础操作全解:从建库到增删改查
数据库·mysql·oracle
oradh1 天前
Oracle 11g单库升级至19c单库(dbua图形方式)
数据库·oracle·11g升级19c·dbua升级方式
Java面试题总结1 天前
RAG 入库实战:一份原始资料,如何变成可检索的知识
数据库·oracle