Oracle對錶空間、使用者、使用者權限的操作

來源:互聯網
上載者:User

標籤:session   許可權管理   dbf   撤銷   引入   pdb   maxsize   資料表   const   

一、對錶空間的操作1、建立資料表空間(create tablespace)
-- ‘hpdb_tablespace‘ 指定資料表空間名稱-- ‘e:\hpdb.dbf‘ 指定資料表空間資料檔案名稱-- size 指定資料表空間的初始化大小-- autoextend on next 30M 指定當資料表空間不足時,自動擴增的空間大小
-- autoextend off 停止自動擴充資料表空間
-- maxsize unlimited 資料表空間的最大空間不設定上限
create tablespace hpdb_tablespace datafile ‘e:\hpdb.dbf‘ size 100M autoextend on next 30M maxsize unlimited;
create tablespace table datafile ‘e:\aa.dbf‘ size 10M;
2、修改資料表空間的大小
alter database datafile ‘e:\hpdb.dbf‘ resize 30M;
3、為資料表空間設定自動擴充
alter database datafile ‘e:\hpdb.dbf‘ autoextend on next 30M maxsize unlimited;
4、關閉資料表空間自動擴充
alter database datafile ‘e:\hpdb.dbf‘ autoextend off
 5、為資料表空間添加一個資料檔案
alter tablespace hpdb_tablespace add datafile ‘e:\22.dbf‘ size 100m;
6、刪除資料表空間中的一個資料檔案
alter tablespace hpdb_tablespace drop datafile ‘e:\\22.dbf‘ 
7、 刪除資料表空間
-- 只刪除資料表空間,對應的資料檔案並沒有刪除drop tablespace hpdb_tablespace;-- 同時刪除資料表空間和資料檔案-- (1)先將資料表空間offlinealter tablespace hpdb_tablespace offline;-- (2)刪除資料表空間和資料檔案
-- 刪除資料表空間、資料檔案drop tablespace hpdb_tablespace including contents and datafiles;
--刪除資料表空間、資料檔案、關聯drop tablespace hpdb_tablespace including contents and datafiles cascade constraint;
 二、對暫存資料表空間的操作1、建立暫存資料表空間 (create temporary tablespace)
-- 和建立資料表空間的方式很相似
-- 注意:資料表空間通過create tablespace來建立;暫存資料表空間通過create temporary tablespace類建立;資料表空間通過datafile為資料表空間指定資料檔案的名稱;暫存資料表空間通過tempfile為其指定資料檔案的名稱-- 暫存資料表空間的作用:暫存資料表空間主要用途是在資料庫進行排序運算、管理索引、訪問視圖等操作時提供臨時的運算空間,當運算完成之後系統會自動清理。create temporary tablespace hpdb_tmp tempfile ‘e:\hpdb_tmp.dbf‘ size 100M autoextend on next 30M maxsize unlimited;
 2、查看暫存資料表空間
--查看暫存資料表空間
select name from v$tempfile
--查看目前使用者的暫存資料表空間
select * from database_properties where property_name=‘DEFAULT_TEMP_TABLESPACE‘; 
 3、修改暫存資料表空間的大小
alter database tempfile ‘e:\hpdb_tmp.dbf‘ resize 30M;
 4、為暫存資料表空間設定自動擴充
alter database tempfile ‘e:\hpdb_tmp.dbf‘ autoextend on next 20M maxsize unlimited;
 5、關閉暫存資料表空間的自動擴充
alter database tempfile ‘e:\hpdb_tmp.dbf‘ autoextend off;
 6、為暫存資料表空間添加一個資料檔案
alter tablespace hpdb_tmp add tempfile ‘e:\2.dbf‘ size 100M;
7、刪除暫存資料表空間中的一個資料檔案
--刪除2.dbf檔案
alter tablespace hpdb_tmp drop tempfile ‘e:\2.dbf‘;
8、刪除暫存資料表空間
--刪除資料表空間,不刪除.dbf檔案drop tablespace hpdb_tmp including contents and datafiles cascade constraints;
9、刪除預設的暫存資料表空間

預設的暫存資料表空間不能直接刪除,我們只能通過以下步驟間接的刪除預設的暫存資料表空間:

  1. 先定義一個新的暫存資料表空間temp2,使temp2作為中轉資料表空間;
  2. 將預設資料表空間temp1換成temp2;( alter database default temporary tablespace temp1; )
  3. 然後將之前的預設暫存資料表空間temp1刪除;
  4. 在定義一個新的暫存資料表空間temp3,使temp3作為新的預設暫存資料表空間;
  5. 刪除中轉資料表空間temp2;

經過以上幾步,預設的資料表空間temp1就被替換成了新的資料表空間temp3。

 

三、對使用者的操作1、建立使用者
-- user 後跟使用者名稱-- identified by 登入密碼-- default tablespace 使用者預設資料表空間-- temporary tablespace 使用者暫存資料表空間
-- 如果建立使用者時不指定default tablespace,Oracle會將SYSTEM資料表空間作為使用者預設資料表空間。 
-- 如果建立使用者時不能指定temporary tablespace,Oracle會將資料庫預設暫存資料表空間作為使用者的暫存資料表空間。
create user CS identified by 123456 DEFAULT tablespace hpdb_tablespace temporary tablespace hpdb_tmp;
2、更改使用者的預設資料表空間
alter user CS default tablespace newTemp;
3、更改使用者的預設暫存資料表空間
alter user CS temporary tablespace temp3;
4、修改使用者密碼
alter user CS identified by 000000
5、 刪除使用者
--刪除使用者,並刪除該使用者建立的對象
--不能刪除正在串連的使用者drop user CS cascade
6、鎖定使用者
alter user CS account lock;
7、解除鎖定
alter user CS account unlock;

 

四、使用者權限、角色管理

我們新建立的使用者是沒有任何許可權的,甚至連登入串連資料的許可權都沒有,那麼,我們在建立完使用者後,就要為其分配許可權,或者角色。

使用者的許可權分為兩類:系統許可權、對象許可權

  系統許可權:允許使用者執行某些資料庫操作(如登入需要的許可權create session;建立資料表的許可權create table)。

  對象許可權:允許使用者對某一特定對象執行特定的操作(如select、delete、update等許可權)。

  角        色:為了簡化許可權管理,進而引入了角色的概念,角色是具有名稱的一組許可權的組合。

系統預定義的使用者角色

   CONNECT:時使用者 (只有登入的許可權)
   RESOURCE:更為可靠和正式的使用者
   DBA:資料庫管理員角色,擁有管理資料庫的最高許可權,該角色不應該給一般的使用者。

 

1、授予使用者角色
--為使用者CS授予connect、resource角色GRANT CONNECT,RESOURCE TO CS;
2、授予使用者系統許可權
--授予使用者CS登入串連資料庫的許可權grant create session to CS;
--授予使用者CS建立資料表的許可權
grant create table to CS;
--賦予使用者CS使用資料表空間的許可權
grant ulimited tablespace to CS;
3、授予使用者物件許可權
-- 賦予使用者CS查看資料表dept的許可權grant select on dept to CS;-- 賦予使用者CS查看所有資料表的許可權grant select any table to CS;
4、撤銷使用者角色
--撤銷使用者CS的connect、resource角色REVOKE CONNECT,RESOURCE FROM CS;
--撤銷使用者CS的建立資料表的許可權
revoke create table from CS;
--撤銷使用者CS的使用資料表空間的許可權
revoke ulimited tablespace from CS;
--撤銷使用者CS的查看資料表dept的許可權
revoke select on dept from CS;
--撤銷使用者CS查看所有資料表的許可權
revoke select any table from CS;

 

 5、許可權級聯
grant select on Student to CS with grant option;-- 賦予使用者CS查看資料表Student的許可權,並且使用者CS可以將該許可權賦予其他使用者
  • with grant option (用於對象許可權授權,許可權是級聯的)賦予許可權賬戶被刪除或許可權被撤銷,被賦予許可權的使用者的許可權也將被撤銷
  • with admin option (用於系統許可權授權,許可權是不級聯的)賦予許可權賬戶被刪除或許可權被撤銷,被賦予許可權的使用者的許可權不會被撤銷

 

Oracle對錶空間、使用者、使用者權限的操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.