Oracle 删除用户和表空间详细介绍
16lz
2022-01-06
Oracle 删除用户和表空间
Oracle 使用时间长了, 新增了许多user 和tablespace. 需要清理一下
对于单个user和tablespace 来说, 可以使用如下命令来完成。
步骤一: 删除user
drop user ×× cascade
步骤二: 删除tablespace
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;
思路:
Export出DB中所有的user和tablespace, 筛选出系统的和有用的tablespace,把有用的信息load到一张表中去。然后写例程循环,把不在有用表的tablespace删掉
1. select username,default_tablespace from dba_users;
2.
create table MTUSEFULSPACE( ID Number(4) NOT NULL PRIMARY KEY, USERNAME varchar2(30), TABLESPACENAME varchar2(60), OWNERNAME varchar2(30));
declare icount number(2); tempspace varchar2(60);begin for curTable in (select username as allusr,default_tablespace as alltblspace from dba_users) loop tempspace :=curTable.alltblspace; dbms_output.put_line(tempspace); select count(TABLESPACENAME) into icount from MTUSEFULSPACE where TABLESPACENAME = tempspace; if icount=0 then DROP TABLESPACE tempspace INCLUDING CONTENTS AND DATAFILES; end if; commit; end loop;end;
ORA-06550: 第 10 行, 第 5 列: PLS-00103: 出现符号 "DROP"在需要下列之一时: begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe06550. 00000 - "line %s, column %s:\n%s"*Cause: Usually a PL/SQL compilation error.*Action:
没办法,例程不能写,就只能组出语句执行了。
把需要删除的user, tablespace 导出到Excel. 使用CONCATENATE 组出SQL.
贴到SQLdevelop 批量执行。
整个删除会比较耗时间, 100多个user. 用了12个小时左右。
如要找datafile的具体位置,可以使用
select t1.name,t2.name from v$tablespace t1, v$datafile t2 where t1.ts# = t2.ts#;
--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
drop tablespace tablespace_name including contents;
drop tablespace tablespace_name including datafiles;
drop tablespace tablespace_name including contents and datafiles;
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
更多相关文章
- 保留用户自定义设置
- android用户界面之按钮(Button)教程实例汇
- Android之应用程序基础
- android用户界面-组件Widget-地图视图MapView
- android用户界面-组件Widget-画廊视图Gallery
- Android(安卓)View的介绍和使用
- Android(安卓)中文 API (27) —— SeekBar.OnSeekBarChangeListene
- android Manifest.xml选项-android:ConfigChanges
- Android入门学习笔记之人机用户界面