1. 程式人生 > >Oracle 表空間和使用者的維護(建立、刪除、修改)

Oracle 表空間和使用者的維護(建立、刪除、修改)


        最近為了完成資料在不同庫之間的匯入匯出,臨時建立了不少表空間和使用者,為了保持資料庫的乾淨整潔,根據需要刪除無用的使用者、表空間及物理檔案。
下面是相關的語法操作。

1.查看錶空間

select * from dba_tablespaces

2.查詢物理檔案

select * from dba_data_files

3.查看錶空間裡存放了哪些使用者的資料

select distinct owner from dba_segments where tablespace_name='MY_001'

4.檢視使用者

select * from dba_users

5.檢視使用者預設的表空間

select default_tablespace from dba_users where username='LG'

6.查詢使用者下面所有的表

select * from dba_tables  where owner='LGL'

7.刪除使用者,及級聯關係也刪除

drop user user_name cascade

8.刪除表空間,對應的表空間檔案也刪除

drop tablespace tablespace_name including contents and datafiles cascade constraint

9.建立表空間

create tablespace ****
datafile 'd:\app\oracle12c\oradata\orcl\my_0003.dbf'
size 1024m
autoextend on next 200m
maxsize unlimited

10.修改表空間----增加物理檔案

alter tablespace *** add datafile
    'd:\app\oracle12c\oradata\orcl\my_0005.dbf' size 128m
    autoextend on next 5m
    maxsize unlimited

11.建立使用者及設定預設表空間
 

---建立使用者
CREATE USER GZZL_LS IDENTIFIED BY password
DEFAULT TABLESPACE "GZZL"
TEMPORARY TABLESPACE "TEMP"
QUOTA UNLIMITED ON "GZZL";   ---設定使用者無限制使用這個表空間配額

12.檢視某個表的佔用物理空間大小

select segment_name AS TABLENAME,bytes b,bytes / 1024 kb,bytes /1024 /1024 mb,bytes /1024 /1024 /1024 GB from user_segments 
where segment_name = upper('D_DZ')