Oracle 刪除使用者和表格空間
Oracle 使用時間長了, 新增了許多user 和tablespace. 需要清理一下
對於單一user和tablespace 來說, 可以使用以下指令來完成。
?步驟一:? 刪除user
drop user ×× cascade
?說明: 刪除了user,只是刪除了該user下的schema objects,是不會刪除對應的tablespace的。
步驟二: 刪除tablespace
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;
但是,因為是供開發(fā)環(huán)境來使用的db, 需要清理的user 和 table space 很多。
思路:
?Export出DB中所有的user和tablespace, 篩選出系統(tǒng)的和有用的tablespace,把有用的信息load到一張表中去。然後寫程式循環(huán),把不在有用表的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) );
3.
2. ?
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;
3.
ORA-06550: 第 10 行, 第 5 列: PLS-00103: 出現(xiàn)符號 "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 pipe 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:? ?
好像是被鎖了。 。
把需要刪除的user, tablespace 匯出到Excel. 使用CONCATENATE 群組出SQL.
貼到SQLdevelop 批次執(zhí)行。
select t1.name,t2.name from v$tablespace t1, v$datafile t2 where t1.ts# = t2.ts#;? ?
SQL code
--空白表空間,但不含實體檔案
drop tablespace tablespace_name;? ?
--刪除空白表空間,包含實體檔案
drop tablespace tablespace_name including contents;??--如果其他表空間中的表有外鍵等約束關聯(lián)到了本表空間中的表的字段,希望加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including datafiles;
?感謝閱讀,希望能幫助到感謝大家,謝謝大家對大家本站的支持!
更多Oracle 刪除使用者和表空間詳細介紹相關文章請關注PHP中文網!

熱AI工具

Undress AI Tool
免費脫衣圖片

Undresser.AI Undress
人工智慧驅動的應用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網頁開發(fā)工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)