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;

相关推荐
悟道书生4 小时前
Kingbase数据库使用命令来执行init.sql(包含建库建表语句)
数据库·oracle
晴天¥4 小时前
记一次Oracle 归档进程卡死怎么去有效排查
数据库·oracle
梦幻通灵5 小时前
MybatisPlus使用数据库递增ID实现方案【持续更新】
数据库·oracle
海鸥-w1 天前
数据库冗余字段设计笔记
java·数据库·笔记·oracle
实泽有之,无泽虚之1 天前
ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务问题原因及解决办法
数据库·oracle
程序员塔塔喵1 天前
【MySQL篇|第十篇】深分页问题
数据库·oracle·深分页问题
qq_452396231 天前
第八篇:《VACUUM、自动清理与膨胀治理》
jvm·数据库·oracle
晴天¥1 天前
记录Oracle11g数据库OGG同步实验
oracle·oracle ogg·oracle高可用架构
晴天¥1 天前
Oracle集群中是该如何管理控制文件和日志文件组?
数据库·oracle
云策数链1 天前
用友 T+Cloud / U8 项目交接时的账套健康度核查清单
数据库·oracle·erp·用友·云策数链