濮阳杆衣贸易有限公司

主頁 > 知識庫 > Oracle 刪除用戶和表空間詳細(xì)介紹

Oracle 刪除用戶和表空間詳細(xì)介紹

熱門標(biāo)簽:電話機(jī)器人怎么代理商 電銷需要外呼系統(tǒng)嗎 我要地圖標(biāo)注數(shù)量有限制嗎 千呼電話機(jī)器人可以試用嗎 400電話辦理泰安 零成本地圖標(biāo)注賺錢 安卡拉地圖標(biāo)注app 互聯(lián)網(wǎng)電話外呼系統(tǒng) 家庭農(nóng)場地圖標(biāo)注名稱怎樣起名

Oracle 刪除用戶和表空間

Oracle 使用時(shí)間長了, 新增了許多user 和tablespace. 需要清理一下

對于單個(gè)user和tablespace 來說, 可以使用如下命令來完成。

 步驟一:  刪除user

drop user ×× cascade

說明: 刪除了user,只是刪除了該user下的schema objects,是不會刪除相應(yīng)的tablespace的。

步驟二: 刪除tablespace

DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;

但是,因?yàn)槭枪╅_發(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.

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;

執(zhí)行后會報(bào)如下錯(cuò)誤

ORA-06550: 第 10 行, 第 5 列: 
PLS-00103: 出現(xiàn)符號 "DROP"在需要下列之一時(shí):
 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:

好像是被鎖了。。

沒辦法,例程不能寫,就只能組出語句執(zhí)行了。

把需要?jiǎng)h除的user, tablespace 導(dǎo)出到Excel. 使用CONCATENATE 組出SQL.

貼到SQLdevelop 批量執(zhí)行。

整個(gè)刪除會比較耗時(shí)間, 100多個(gè)user.  用了12個(gè)小時(shí)左右。

如要找datafile的具體位置,可以使用

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;

--刪除空表空間,包含物理文件

drop tablespace tablespace_name including datafiles;

--刪除非空表空間,包含物理文件

drop tablespace tablespace_name including contents and datafiles;

--如果其他表空間中的表有外鍵等約束關(guān)聯(lián)到了本表空間中的表的字段,就要加上CASCADE CONSTRAINTS

drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

您可能感興趣的文章:
  • 使用sqlplus命令行工具為oracle創(chuàng)建用戶和表空間
  • oracle創(chuàng)建表空間、授權(quán)、創(chuàng)建用戶、導(dǎo)入dmp文件
  • Linux下Oracle刪除用戶和表空間的方法
  • shell腳本操作oracle刪除表空間、創(chuàng)建表空間、刪除用戶
  • Oracle新建用戶、角色,授權(quán),建表空間的sql語句
  • Oracle數(shù)據(jù)庫的實(shí)例/表空間/用戶/表之間關(guān)系簡單講解

標(biāo)簽:黃山 來賓 東營 濱州 新鄉(xiāng) 大同 池州 文山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle 刪除用戶和表空間詳細(xì)介紹》,本文關(guān)鍵詞  Oracle,刪除,用戶,和,表,空間,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Oracle 刪除用戶和表空間詳細(xì)介紹》相關(guān)的同類信息!
  • 本頁收集關(guān)于Oracle 刪除用戶和表空間詳細(xì)介紹的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    滕州市| 德钦县| 盐亭县| 临安市| 汶上县| 永年县| 安义县| 富阳市| 乌兰浩特市| 苍南县| 郓城县| 万州区| 陆河县| 五大连池市| 三穗县| 德阳市| 稷山县| 丹巴县| 门源| 容城县| 柘荣县| 阿巴嘎旗| 仙居县| 贡觉县| 白城市| 丽水市| 宁海县| 上高县| 定安县| 咸宁市| 黄梅县| 呼玛县| 梁山县| 平果县| 松阳县| 平陆县| 九江县| 双流县| 会东县| 会同县| 乐陵市|