oracle分区表彻底删除的办法

更新时间:2023-07-16 20:25:52 阅读: 评论:0

oracle分区表彻底删除的办法
当对一个不再使用的分区表进行drop后,查询ur_tab_partitions视图发现出现如下不规则的分区表表名:
SQL> lect distinct table_name圣诞节英语资料 from ur_tab_partitions;
BIN$l+Pv5l1jCMXgQKjAyQFA0A==$0
这样很容易导致自己写的"自动增加表的分区"的存过发生错误,因此为了避免再修改存过,只能把这些不规则的表名删除才行.现提供如下方法彻底删除这些不规则的表名.
六级分数分布
其实当我们执行drop table tablename的时候,不是直接把表删除掉,而是放在了回收站里,可以通过查询ur_recyclebin查看被删除的表信息.这样,回收站里的表信息就可以被恢复或彻底清除。
通过查询回收站ur_recyclebin获取被删除的表信息,如果想恢复被drop掉的表,可以使用如下语句进行恢复
flashback table <ur_recyclebin.object_name or iginal_name> to before drop;
上面的语句是将回收站里的表恢复为原表名称
flashback table <ur_recyclebin.object_name or iginal_name> to before drop rename to <new_table_name>;
将回收站里的表恢复为指定的新表名称,表中数据不会丢失。
若要彻底删除表,则使用语句:drop table <table_name> purge;这样drop后的表就不被放入回收站
如果是清除回收站中指定的表,可以使用语句purge table <table_name>;
如果是清除当前用户回收站所有的表,可以使用语句purge recyclebin;
如果是清除所有用户的回收站:purge dba_recyclebin;
到此,按上面的方法清除回收站的数据后,再查询ur_tab_partitions视图,发现不规则表名已经没有了
SQL> lect distinct table_name from ur_tab_partitions;
no rows lected
在此顺便再提一下truncate操作后不释放空间的解决办法
Truncate不支持回滚,并且不能truncate一个带有外键的表,如果要删除首先要取消外键,
然后再删除。
truncate table 后,有可能表空间仍没有释放,可以使用如下语句:
alter table 表名称 deallocate UNUSED KEEP 0;
注意如果不加KEEP 0的话,表空间是不会释放的。
例如:
alter table tablename deallocate UNUSED KEEP 0;
或者:
TRUNCATE TABLE tablename DROP STORAGE才能释放表空间。
例如: truncate table tablename DROP STORAGE;
查看各表空间空置率:
老师英文lect英语四级报名官网入口 a.tablespace_name,a.free_al_space, a.free_al_space free_ratio
from营养师培训学校
aquila
(lect tablespace_name,医务室sum(bytes)/1024/1024 free_space from dba_free_space group by tablespace_name) a,
(lect tablespace_name,sum(bytes)/1024/1024 total_space from dba_data_files group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by free_ratio desc
查看表占用空间的大小
lect gment_name,sum(bytes)/1024/1024 from Ur_Extents group by gment_name;
查看带分区的表
lect distinct table_name from ur_tab_partitions
查看分区表空间大小
lect gment_name, sum(bytes) / 1024 / 1024eoe
    just so sofrom Ur_Extents
vntwhere gment_name in (lect distinct table_name from ur_tab_partitions)
group by gment_name; 
查看某个表的分区:
lect t.partition_name
    from ur_tab_partitions t
where t.table_name = ' ODW_SDP_DPAMT_NP'
order by t.partition_name
批量删除分区表:
declare
  v_date date;
  v_part_name varchar(50);
begin
  v_date :=date'2015-01-30';
  while v_date >=date '2013-06-03' LOOP
    v_part_name :='P' || to_char(v_date,'yyyymmdd');
    dbms_output.put_line(v_part_name);
    execute immediate 'ALTER TABLE ODW_SDP_DPAMT_NP DROP PARTITION ' || v_part_name;
    v_date :=v_date -1;
    END LOOP;
END;
删除一个分区alter table  ODW_LOAN_AR_SMY  drop partition P2*******
删除一个分区的数据alter table ODW_LOAN_AR_SMY truncate partition P2*******
释放表空间
alter table 表名称 deallocate UNUSED KEEP 0
释放磁盘空间:
lect a.file#,a.name,a.bytes/1024/1024 CurrentMB,        ceil(HWM * a.block_size)/1024/1024 ResizeTo,        (a.bytes - HWM * a.block_size)/1024/1024 ReleaMB,        'alter databa datafile '''||a.name||''' resize '||        ceil(HWM * a.block_size/1024/1024) || 'M;' ResizeCMD from v$datafile a,      (lect file_id,max(block_id+blocks-1) HWM        from dba_extents        group by file_id) b where a.file# = b.file_id(+) and (a.bytes - HWM *block_size)>0 order by 5
1、 lect distinct table_name from ur_tab_partitions
2、 清除回收站中指定的表purge table <table_name>;
3、 清除当前用户回收站所有的表purge recyclebin
4、 清除所有用户的回收站purge dba_recyclebin
5、 lect distinct table_name from ur_tab_partitions;
6、 alter table 表名称 deallocate UNUSED KEEP 0
7、 truncate table tablename DROP STORAGE

本文发布于:2023-07-16 20:25:52,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1100202.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:删除   回收站   空间   释放   清除   分区
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图