從ORA-01950報錯聊起——令人困惑的Resource角色和隱含unlimited tablespace系統許可權
相信大家一定對Resource 角色不會陌生,Resource 角色是授予開發人員的,能在自己的方案中建立表、序列、檢視等。很多DBA習慣在建立新使用者後直接賦予Connect和Resource 角色,這樣就可以在資料庫裡執行建立表等操作了。
最近在測試過程中發現一些奇怪的現象,有時候擁有Connect和Resource 角色的使用者會提示“ORA-01950: no privileges on tablespace 'USERS'”錯誤,也就是說沒有操作表空間的許可權,這是怎麼回事呢?
透過一系列的測試發現,unlimited tablespace是隱含在resource角色中的一個系統許可權,當使用者得到resource的角色時,unlimited tablespace系統許可權也隱式授權給使用者。但是需要注意的是,unlimited tablespace系統許可權只能授予使用者,不能被授予角色;也不會隨著resource角色被授予role而級聯授予給使用者。
首先,我們瞭解一下和unlimited tablespace系統許可權的一個概念QUOTA,然後透過若干測試來驗證以上結論。
關於QUOTA
對於一個新建的使用者,如果沒有分配給unlimited tablespace系統許可權的使用者,必須先給他們指定限額,之後他們才能在表空間中建立物件。
限額是指定標空間中允許的空間容量,預設的情況下,使用者在任何表空間中都是沒有限額的,可以使用以下三個選項來為使用者提供表空間限額:
A、無限制的:允許使用者最大限度的使用表空間中的可用空間
B、值:使用者可以使用的表空間,以千位元組或者兆位元組為單位。但是這並不能保證會為使用者保留該空間。
C、UNLIMITED TABLESPACE系統許可權:此係統許可權會覆蓋所有的單個表空間限額,並向使用者提供所有表空間(包括SYSTEM和SYSAUX)的無限制限額(注:授予resource角色的時候也會授予此許可權)
如果需要為一個使用者指定一個限額,可以有兩種方法:
1、在建立使用者的時候指定限額:
點選(此處)摺疊或開啟
-
CREATE USER hoegh IDENTIFIED BY hoegh
-
DEFAULT TABLESPACE users
-
TEMPORARY TABLESPACE TEMP
- QUOTA 3M ON users;
2、在建立使用者完成之後,對使用者限額進行指定:
點選(此處)摺疊或開啟
-
CREATE USER hoegh IDENTIFIED BY hoegh
-
DEFAULT TABLESPACE TEST;
- ALTER USER hoegh QUOTA 3M ON users;
測試1 授予connect和resource角色
建立新使用者hoegh1,授予connect和resource角色,嘗試建表和插入操作,透過查詢user_sys_privs資料字典來驗證使用者的系統許可權。點選(此處)摺疊或開啟
-
SYS@HOEGH> create user hoegh1 identified by hoegh1;
-
-
User created.
-
-
SYS@HOEGH>
-
SYS@HOEGH> grant connect,resource to hoegh1;
-
-
Grant succeeded.
-
-
SYS@HOEGH> conn hoegh1/hoegh1
-
Connected.
-
hoegh1@HOEGH>
-
hoegh1@HOEGH> create table test(id number);
-
-
Table created.
-
-
hoegh1@HOEGH> insert into test values(1);
-
-
1 row created.
-
-
hoegh1@HOEGH>
-
hoegh1@HOEGH> select privilege from user_sys_privs;
-
-
PRIVILEGE
-
----------------------------------------
-
UNLIMITED TABLESPACE
-
-
hoegh1@HOEGH> select username,GRANTED_ROLE,ADMIN_OPTION from user_role_privs;
-
-
USERNAME GRANTED_ROLE ADM
-
------------------------------ ------------------------------ ---
-
HOEGH1 CONNECT NO
-
HOEGH1 RESOURCE NO
-
- hoegh1@HOEGH>
測試2 逐條授予resource角色包含的系統許可權
建立新使用者hoegh2,授予connect並逐條授予resource角色包含的系統許可權,嘗試建表和插入操作,透過查詢user_sys_privs資料字典來驗證使用者的系統許可權。點選(此處)摺疊或開啟
-
SYS@HOEGH> create user hoegh2 identified by hoegh2;
-
-
User created.
-
-
SYS@HOEGH> grant connect to hoegh2;
-
-
Grant succeeded.
-
-
SYS@HOEGH>
-
SYS@HOEGH> select privilege from role_sys_privs
-
where role='RESOURCE'; 2
-
-
PRIVILEGE
-
----------------------------------------
-
CREATE SEQUENCE
-
CREATE TRIGGER
-
CREATE CLUSTER
-
CREATE PROCEDURE
-
CREATE TYPE
-
CREATE OPERATOR
-
CREATE TABLE
-
CREATE INDEXTYPE
-
-
8 rows selected.
-
-
SYS@HOEGH>
-
SYS@HOEGH> select 'grant '||PRIVILEGE||' to hoegh2;' from role_sys_privs
-
where role='RESOURCE'; 2
-
-
'GRANT'||PRIVILEGE||'TOhoegh2;'
-
-----------------------------------------------------
-
grant CREATE SEQUENCE to hoegh2;
-
grant CREATE TRIGGER to hoegh2;
-
grant CREATE CLUSTER to hoegh2;
-
grant CREATE PROCEDURE to hoegh2;
-
grant CREATE TYPE to hoegh2;
-
grant CREATE OPERATOR to hoegh2;
-
grant CREATE TABLE to hoegh2;
-
grant CREATE INDEXTYPE to hoegh2;
-
-
8 rows selected.
-
-
SYS@HOEGH> grant CREATE SEQUENCE to hoegh2;
-
grant CREATE TRIGGER to hoegh2;
-
grant CREATE CLUSTER to hoegh2;
-
grant CREATE PROCEDURE to hoegh2;
-
grant CREATE TYPE to hoegh2;
-
grant CREATE OPERATOR to hoegh2;
-
grant CREATE TABLE to hoegh2;
-
grant CREATE INDEXTYPE to hoegh2;
-
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
Grant succeeded.
-
-
SYS@HOEGH>
-
SYS@HOEGH>
-
SYS@HOEGH> conn hoegh2/hoegh2
-
Connected.
-
hoegh2@HOEGH> create table test(id number);
-
-
Table created.
-
-
hoegh2@HOEGH> insert into test values(1);
-
insert into test values(1)
-
*
-
ERROR at line 1:
-
ORA-01950: no privileges on tablespace 'USERS'
-
-
-
hoegh2@HOEGH>
-
hoegh2@HOEGH>
-
hoegh2@HOEGH> select privilege from user_sys_privs;
-
-
PRIVILEGE
-
----------------------------------------
-
CREATE TABLE
-
CREATE CLUSTER
-
CREATE TYPE
-
CREATE TRIGGER
-
CREATE PROCEDURE
-
CREATE OPERATOR
-
CREATE INDEXTYPE
-
CREATE SEQUENCE
-
-
8 rows selected.
-
-
hoegh2@HOEGH> select username,GRANTED_ROLE,ADMIN_OPTION from user_role_privs;
-
-
USERNAME GRANTED_ROLE ADM
-
------------------------------ ------------------------------ ---
-
HOEGH2 CONNECT NO
-
-
hoegh2@HOEGH>
- hoegh2@HOEGH>
測試3 將connect和resource角色授予新的角色
建立角色hoegh,並將connect和resource角色授予這個角色;然後建立新使用者hoegh3,將hoegh角色授予使用者hoegh3,嘗試建表和插入操作。點選(此處)摺疊或開啟
-
SYS@HOEGH>
-
SYS@HOEGH> create user hoegh3 identified by hoegh3;
-
-
User created.
-
-
SYS@HOEGH>
-
SYS@HOEGH> create role hoegh;
-
-
Role created.
-
-
SYS@HOEGH> grant connect,resource to hoegh;
-
-
Grant succeeded.
-
-
SYS@HOEGH> grant hoegh to hoegh3;
-
-
Grant succeeded.
-
-
SYS@HOEGH>
-
SYS@HOEGH> conn hoegh3/hoegh3
-
Connected.
-
hoegh3@HOEGH>
-
hoegh3@HOEGH> create table test(id number);
-
-
Table created.
-
-
hoegh3@HOEGH> insert into test values(1);
-
insert into test values(1)
-
*
-
ERROR at line 1:
-
ORA-01950: no privileges on tablespace 'USERS'
-
-
-
hoegh3@HOEGH>
-
hoegh3@HOEGH> select privilege from user_sys_privs;
-
-
no rows selected
-
-
hoegh3@HOEGH>
-
hoegh3@HOEGH> select username,GRANTED_ROLE,ADMIN_OPTION from user_role_privs;
-
-
USERNAME GRANTED_ROLE ADM
-
------------------------------ ------------------------------ ---
-
HOEGH3 HOEGH NO
-
-
hoegh3@HOEGH>
- hoegh3@HOEGH>
測試4 直接授予使用者unlimited tablespace系統許可權
建立新使用者hoegh4,授予connect角色後,直接授予create table和unlimited tablespace系統許可權,嘗試建表和插入操作。點選(此處)摺疊或開啟
-
SYS@HOEGH> create user hoegh4 identified by hoegh4;
-
-
User created.
-
-
SYS@HOEGH> grant connect to hoegh4;
-
-
Grant succeeded.
-
-
SYS@HOEGH> grant create table to hoegh4;
-
-
Grant succeeded.
-
-
SYS@HOEGH> grant unlimited tablespace to hoegh4;
-
-
Grant succeeded.
-
-
SYS@HOEGH>
-
SYS@HOEGH> conn hoegh4/hoegh4
-
Connected.
-
hoegh4@HOEGH>
-
hoegh4@HOEGH> create table test(id number);
-
-
Table created.
-
-
hoegh4@HOEGH> insert into test values(1);
-
-
1 row created.
-
-
hoegh4@HOEGH>
-
hoegh4@HOEGH> select privilege from user_sys_privs;
-
-
PRIVILEGE
-
----------------------------------------
-
CREATE TABLE
-
UNLIMITED TABLESPACE
-
-
hoegh4@HOEGH> select username,GRANTED_ROLE,ADMIN_OPTION from user_role_privs;
-
-
USERNAME GRANTED_ROLE ADM
-
------------------------------ ------------------------------ ---
-
HOEGH4 CONNECT NO
-
-
hoegh4@HOEGH>
- hoegh4@HOEGH>
~~~~~~~ the end~~~~~~~~~
hoegh
2016.10.26
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30162081/viewspace-2127149/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 詳解Oracle的unlimited tablespace系統許可權OracleMIT
- unlimited tablespace許可權的授予和回收MIT
- unlimited tablespace許可權和quota 配額MIT
- oracle unlimited tablespace 許可權的用途OracleMIT
- 系統許可權UNLIMITED TABLESPACE為什麼如此特殊?MIT
- 使用者有connect,resource,dba角色許可權後回收dba許可權導致無UNLIMITED TABLESPACE許可權造成業務中斷MIT
- 表空間配額和UNLIMITED TABLESPACE許可權MIT
- Unlimited Tablespace 許可權 及 “延遲段”特性MIT
- Oracle的物件許可權、角色許可權、系統許可權Oracle物件
- 檢視角色裡包含的系統許可權、物件許可權和角色物件
- 角色許可權(Role)和系統許可權(System)的幾個澄清實驗
- 許可權系統設計(4)--resource
- Oracle內建角色connect與resource的許可權Oracle
- 系統,物件,角色許可權簡析物件
- 系統、角色、物件相關許可權字典物件
- 基於角色的許可權系統的問題
- 11G的rsource角色與Unlimited TablespaceMIT
- Android系統許可權和root許可權Android
- linux檔案系統的隱藏許可權Linux
- 系統許可權傳遞和物件許可權傳遞的測試物件
- PostgreSQL學習手冊(角色和許可權)SQL
- Oracle 查詢許可權角色Oracle
- mongodb 的許可權系統MongoDB
- 查詢使用者的系統許可權和使用者所擁有的角色
- 許可權系統:一文搞懂功能許可權、資料許可權
- MySQL許可權系統MySql
- Oracle系統許可權Oracle
- 在MacOS系統中如何管理隱私許可權控制?Mac
- Oracle 使用者、物件許可權、系統許可權Oracle物件
- Oracle角色許可權之Default RoleOracle
- Java Web角色許可權設計JavaWeb
- MongoDB4.0建立自定義許可權(只有查詢,插入和更新的許可權)的角色步驟MongoDB
- 許可權系統:許可權應用服務設計
- Oracle檢視使用者預設表空間、臨時表空間、系統許可權、物件許可權、角色許可權舉例說明Oracle物件
- 許可權系統的基本概念和架構架構
- Oracle資料庫的系統和物件許可權Oracle資料庫物件
- 【JavaWeb】許可權管理系統JavaWeb
- 有贊許可權系統