ユーザー、権限、ロール(2)-権限管理
###私が使用しているシステムはLinux AS 4 U 6データベースバージョン10.2.0.1.0###です.
アクセス権:2種類に分けられます
1.システム権限
2.オブジェクト権限
システム権限:オブジェクト、表領域、ユーザー、データベース自体などの管理権限-権限は作成、変更、削除などがあります.
すべてのシステム権限はシステムに置かれています.privilege_mapデータ辞書にあります.
次に中の数を見てみましょう
いくつかの権限を簡単に見てみましょう
-scott CREATE TABLE権限のみの場合、scottというSCHEMAの下でしかテーブルを作成できません.CREATE ANY TABLE権限があれば、どのSCHEMAでもテーブルを作成できます.
これにより、特定のユーザに対して特定の表領域に対して使用権限を付与することができる.(特定の大きさでも無限の-1は無限を表す)
オブジェクト
表
試みる
シーケンス#シーケンス#
ストアド・プロシージャ、メソッド、パッケージ*1
実体化ビュー(Materialized View)
データ辞書
ライブラリ
ユーザー定義タイプ
操作
索引タイプ
ALTER
√
√
DELETE
√
√
√
EXECUTE
√
√
√
√
√
DEBUG
√
√
√
√
FLASHBACK
√
√
√
INDEX
√
INSERT
√
√
√
ON COMMIT REFRESH
√
QUERY REWFITE
√
READ
√
REFERENCES
√
√
SELECT
√
√
√
√
UNDER
√
√
UPDATE
√
√
√
WRITE
√
アクセス権:2種類に分けられます
1.システム権限
2.オブジェクト権限
システム権限:オブジェクト、表領域、ユーザー、データベース自体などの管理権限-権限は作成、変更、削除などがあります.
すべてのシステム権限はシステムに置かれています.privilege_mapデータ辞書にあります.
次に中の数を見てみましょう
SQL> select count(*) from system_privilege_map;
COUNT(*)
----------
166
SQL>
166
,
いくつかの権限を簡単に見てみましょう
SQL> select name from system_privilege_map where name like 'CREATE%' order by 1;
NAME
----------------------------------------
CREATE ANY CLUSTER
CREATE ANY CONTEXT
CREATE ANY DIMENSION
CREATE ANY DIRECTORY
CREATE ANY EVALUATION CONTEXT
CREATE ANY INDEX
CREATE ANY INDEXTYPE
CREATE ANY JOB
CREATE ANY LIBRARY
CREATE ANY MATERIALIZED VIEW
CREATE ANY OPERATOR
CREATE ANY OUTLINE
CREATE ANY PROCEDURE
CREATE ANY RULE
CREATE ANY RULE SET
CREATE ANY SEQUENCE
CREATE ANY SQL PROFILE
CREATE ANY SYNONYM
CREATE ANY TABLE
CREATE ANY TRIGGER
CREATE ANY TYPE
CREATE ANY VIEW
CREATE CLUSTER
CREATE DATABASE LINK
CREATE DIMENSION
CREATE EVALUATION CONTEXT
CREATE EXTERNAL JOB
CREATE INDEXTYPE
CREATE JOB
CREATE LIBRARY
CREATE MATERIALIZED VIEW
CREATE OPERATOR
CREATE PROCEDURE
CREATE PROFILE
CREATE PUBLIC DATABASE LINK
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE ROLLBACK SEGMENT
CREATE RULE
CREATE RULE SET
CREATE SEQUENCE
CREATE SESSION
CREATE SYNONYM
CREATE TABLE
CREATE TABLESPACE
CREATE TRIGGER
CREATE TYPE
CREATE USER
CREATE VIEW
49 rows selected.
SQL>
, CREATE 49 , , ANY SCHEMA 。
ANYがない場合は、その存在するSCHEMAのみを操作できます.-scott CREATE TABLE権限のみの場合、scottというSCHEMAの下でしかテーブルを作成できません.CREATE ANY TABLE権限があれば、どのSCHEMAでもテーブルを作成できます.
:
1. sysdba sysopen:
。 UNIX root 。 。
, sysdba (sys )。
2. restricted session
restricted , 。
sys 。
3. create session
。 。 connect
-- , SQL REFERENCE 18 GRANT 。
4. create table create any table 。
create table schema 。create any table schema 。
。
SQL> create user grant_user1 identified by test1234;
User created.
SQL> create user grant_user2 identified by test1234;
User created.
SQL> create user grant_user3 identified by test1234;
User created. --
SQL> grant connect to grant_user1,grant_user2; -- 1,2
Grant succeeded.
SQL> grant create table to grant_user1; -- 1
Grant succeeded.
SQL> conn grant_user3/test1234 -- 3 ,
ERROR:
ORA-01045: user GRANT_USER3 lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
SQL> conn grant_user2/test1234;
Connected.
SQL> create table table1 (id int); -- ,
create table table1 (id int)
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> conn grant_user1/test1234
Connected.
SQL> create table table1 (id int); -- , USERS
create table table1 (id int)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'USERS'
SQL> conn / as sysdba
Connected.
SQL> grant unlimited tablespace to grant_user1; --
Grant succeeded.
SQL> conn grant_user1/test1234
Connected.
SQL> create table table1 (id int); -- 。
Table created.
SQL>
grant 。
grant create any table to xxx schema 。
SQL> show user
USER is "GRANT_USER1"
SQL> create table grant_user2.table1 (id int); --
create table grant_user2.table1 (id int)
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> conn / as sysdba
Connected.
SQL> grant create any table to grant_user1; --
Grant succeeded.
SQL> conn grant_user1/test1234
Connected.
SQL> create table grant_user2.table1 (id int); --
create table grant_user2.table1 (id int)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'USERS'
SQL> conn / as sysdba
Connected.
SQL> grant unlimited tablespace to grant_user2; -- 2
Grant succeeded.
SQL> conn grant_user1/test1234;
Connected.
SQL> create table grant_user2.table1 (id int); --
Table created.
SQL>
-- , schema - grant_user2 ,grant_user2 。 。
-- grant , "grant revoke "
。 , 1 。
-- USERS 。
-- , USERS。
-- , " - "
quota
SQL> alter user grant_user3 quota 100M on USERS;
User altered.
SQL> alter user grant_user3 quota UNLIMITED on USERS;
User altered.
これにより、特定のユーザに対して特定の表領域に対して使用権限を付与することができる.(特定の大きさでも無限の-1は無限を表す)
SQL> select username,tablespace_name,max_bytes from dba_ts_quotas;
USERNAME TABLESPACE_NAME MAX_BYTES
------------------------------ ------------------------------ ----------
DMSYS SYSAUX 209715200
GRANT_USER3 USERS 104857600
SYSMAN SYSAUX -1
OLAPSYS SYSAUX -1
SQL>
, , 。 sys , 。
O7_DICTIONARY_ACCESSIBILITY ( , O, 0)
SQL> show parameter o7
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
O7_DICTIONARY_ACCESSIBILITY boolean FALSE
SQL>
sys 。( SPFILE )
FALSE, 。
( SCHEMA) 。
オブジェクト
表
試みる
シーケンス#シーケンス#
ストアド・プロシージャ、メソッド、パッケージ*1
実体化ビュー(Materialized View)
データ辞書
ライブラリ
ユーザー定義タイプ
操作
索引タイプ
ALTER
√
√
DELETE
√
√
√
EXECUTE
√
√
√
√
√
DEBUG
√
√
√
√
FLASHBACK
√
√
√
INDEX
√
INSERT
√
√
√
ON COMMIT REFRESH
√
QUERY REWFITE
√
READ
√
REFERENCES
√
√
SELECT
√
√
√
√
UNDER
√
√
UPDATE
√
√
√
WRITE
√
.
-- , "grant revoke "
, SCHEMA .
.
SQL> create user user1 identified by test1234; --
User created.
SQL> create user user2 identified by test1234;
User created.
SQL> grant resource,connect to user1; -- .
Grant succeeded.
SQL> grant resource,connect to user2; -- user2 resource .
Grant succeeded.
SQL> grant unlimited tablespace to user1; -- user1 。
Grant succeeded.
SQL> conn user1/test1234;
Connected.
SQL> create table table1 (id int); -- user1
Table created.
SQL> insert into table1 values (1); --
1 row created.
SQL> insert into table1 values (2);
1 row created.
SQL> select * from table1;--
ID
----------
1
2
SQL> conn user2/test1234;-- 。
Connected.
SQL> select * from user1.table1;
select * from user1.table1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> conn user1/test1234;
Connected.
SQL>grant all on table1 to user2; --
Grant succeeded.
SQL> conn user2/test1234;
Connected.
SQL> select * from user1.table1; --
ID
----------
1
2
SQL> insert into user1.table1 values (3);--
1 row created.
SQL>
。( sys )
。 。
, ,
-- :sys CREATE TABLE user01 , GRANT CREATE TABLE 。
SQL> create user user01 identified by test1234; --
User created.
SQL> create user user02 identified by test1234;
User created.
SQL> grant connect to user01,user02 --
2 ;
Grant succeeded.
SQL> grant unlimited tablespace to user01,user02; --
Grant succeeded.
SQL> grant create table to user01 with admin option; -- user01 ,
Grant succeeded.
SQL> conn user01/test1234;
Connected.
SQL> create table table1 (id int);
Table created.
SQL> grant create table to user02; -- user02
Grant succeeded.
SQL> conn user02/test1234;
Connected.
SQL> create table table1 (id int); --user02
Table created.
SQL> conn / as sysdba;
Connected.
SQL> revoke create table from user01; -- user01
Revoke succeeded.
SQL> conn user02/test1234;
Connected.
SQL> create table table2 (id int); --user02
Table created.
SQL>
, , , 。
。
SQL> create user user1 identified by test1234;--
User created.
SQL> create user user2 identified by test1234;
User created.
SQL> create user user3 identified by test1234;
User created.
SQL> grant connect to user1,user2,user3;--
Grant succeeded.
SQL> grant unlimited tablespace to user1;-- user1
Grant succeeded.
SQL> grant resource to user1;-- user1
Grant succeeded.
SQL> conn user1/test1234;
Connected.
SQL> create table table1 (id int);-- ,
Table created.
SQL> insert into table1 values (1);
1 row created.
SQL> insert into table1 values (2);
1 row created.
SQL> grant all on table1 to user2 with grant option;-- user2 , 。
Grant succeeded.
SQL> conn user2/test1234;
Connected.
SQL> select * from user1.table1;
ID
----------
1
2
SQL> insert into user1.table1 values(3);
1 row created.
SQL> select * from user1.table1;
ID
----------
1
2
3
SQL> grant all on user1.table1 to user3;--user2 user3
Grant succeeded.
SQL> conn user3/test1234;
Connected.
SQL> select * from user1.table1;--user3 。
ID
----------
1
2
3
SQL> conn user1/test1234;
Connected.
SQL> revoke all on table1 from user2;-- user2
Revoke succeeded.
SQL> conn user3/test1234;
Connected.
SQL> select * from user1.table1;--user3
select * from user1.table1
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
, 。user1 user2 ,user2 user3 , user1 user2 ,user2 user3 ( ) 。 。
, (connect,resource 。 。) (role), " -role"。