国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > Oracle > 正文

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

2024-08-29 13:59:33
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Oracle 刪除用戶和表空間

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

對(duì)于單個(gè)user和tablespace 來(lái)說(shuō), 可以使用如下命令來(lái)完成。

 步驟一:  刪除user

drop user ×× cascade

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

步驟二: 刪除tablespace

DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;

但是,因?yàn)槭枪╅_(kāi)發(fā)環(huán)境來(lái)使用的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í)行后會(huì)報(bào)如下錯(cuò)誤

ORA-06550: 第 10 行, 第 5 列: PLS-00103: 出現(xiàn)符號(hào) "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 pipe06550. 00000 - "line %s, column %s:/n%s"*Cause:  Usually a PL/SQL compilation error.*Action:

好像是被鎖了。。

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

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

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

整個(gè)刪除會(huì)比較耗時(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;

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


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到oracle教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 九江县| 朝阳市| 芮城县| 疏附县| 浮梁县| 福建省| 甘南县| 昌江| 乐陵市| 临漳县| 新巴尔虎左旗| 澄江县| 齐河县| 揭西县| 易门县| 仁布县| 宜春市| 绵竹市| 汤阴县| 集安市| 金塔县| 梁河县| 信宜市| 集安市| 东阳市| 保靖县| 乌拉特后旗| 延津县| 屏东市| 偃师市| 神木县| 平罗县| 石棉县| 剑河县| 德安县| 会泽县| 张家口市| 沁阳市| 宁都县| 竹溪县| 秀山|