Oracle用户管理
一、系统权限
1、sys授予用户级联授权权限,例如:让tom用户能够给其他用户级联授予创建会话的权限
SYS@oracle11g>grant create session to tom with admin option; Grant succeeded.
2、sys用户权限回收无级联:当sys回收Tom的创建会话的权限时,Tom无法创建会话,但是Tom授予其他用户的创建会话的权限还会生效!
二、对象权限
1、sys授予用户级联授权权限
--tom不具备查询scott.emp权限 TOM@oracle11g>select * from scott.emp ; select * from scott.emp * ERROR at line 1: ORA-00942: table or view does not exist --tom不具备给marry用户授予查询scott.emp权限 TOM@oracle11g>grant select on scott.emp to marry; grant select on scott.emp to marry * ERROR at line 1: ORA-01031: insufficient privileges --sys用户开始给Tom授权 grant select on scott.emp to tom with grant option; ----tom具备查询scott.emp权限 TOM@oracle11g>select count(*) from scott.emp; COUNT(*) ---------- 14 --tom具备给marry用户授予查询scott.emp权限 TOM@oracle11g>grant select on scott.emp to marry; Grant succeeded. --验证 MARRY@oracle11g>select count(*) from scott.emp; COUNT(*) ---------- 14
2、sys级联回收权限,当sys用户revoke时,Tom不能查询scott.emp,同时marry也不能查询!
SYS@oracle11g>revoke select on scott.emp from tom; Revoke succeeded.
三、角色
概念:角色是一种权限的逻辑集合,我们把用户所需要的权限授予角色,然后将角色再授予用户,用角色的方式管理权限,这样就可以减少数据字典中的垃圾数据,也可以使权限管理更加的灵活。
1、角色的授权使用
--先创建三个角色 SYS@oracle11g>create role r1; Role created. SYS@oracle11g>create role r2; Role created. SYS@oracle11g>create role r3; Role created. --分别授予权限 SYS@oracle11g>grant create session,create table to r1; Grant succeeded. SYS@oracle11g>grant create view to r2; Grant succeeded. SYS@oracle11g>grant create any table to r3; Grant succeeded. SYS@oracle11g>grant r2 to r1; Grant succeeded. SYS@oracle11g>grant r1 to tom; Grant succeeded.
此时的tom就具有r1的权限,而r1又嵌套着r2的权限,实际上tom具有的权限有r1、r2下所有权限; --再将r3授予Tom SYS@oracle11g>grant r3 to tom; Grant succeeded.
此时的tom就具有r1的权限,而r1又嵌套着r2的权限,实际上tom具有的权限有r1、r2、r3下所有权限; --查看权限 TOM@oracle11g>select * from session_roles; ROLE ------------------------------ R1 R2 R3 TOM@oracle11g>select * from session_privs; PRIVILEGE ---------------------------------------- CREATE SESSION CREATE TABLE CREATE ANY TABLE CREATE VIEW
2、授予用户非默认角色(权限的动态管理)
将一个角色授予用户的时候,这个角色就是这个用户的默认角色,也就是说只要用户成功的创建了会话,角色中的权限马上释放;可将自认为危险的权限授予角色,然后授予用户,再把这个角色修改为用户非默认角色,这样用户成功创建会话时角色中的权限不会被释放;
--修改非默认角色 SYS@oracle11g>alter user tom default role all except r3; User altered. --查看得出Tom不具备r3的权限 TOM@oracle11g>select * from session_roles; ROLE ------------------------------ R1 R2 如果想使用r3权限,则需要激活角色,但是只能拥有r3的权限了 TOM@oracle11g>set role r3; Role set. TOM@oracle11g>select * from session_roles; ROLE ------------------------------ R3 如果想要所有角色可见 TOM@oracle11g>set role all; Role set. TOM@oracle11g>select * from session_roles; ROLE ------------------------------ R1 R2 R3
四、用户的资源管理
控制用户在存储上能使用多大的空间。
--创建一个表,插入数据会报错,报错的意思就是不能使用users表空间 TOM@oracle11g>create table t01 (x int); Table created. TOM@oracle11g>insert into t01 values (1); insert into t01 values (1) * ERROR at line 1: ORA-01950: no privileges on tablespace 'USERS'
引出Oracle数据库默认永久表空间,如果用户Tom想使用users空间,则需要分配表空间使用配额。
--查看数据库默认永久表空间 SYS@oracle11g>select a.default_tablespace,a.temporary_tablespace from dba_users a where a.username = 'TOM'; DEFAULT_TABLESPACE TEMPORARY_TABLESPACE ------------------------------ ------------------------------ USERS TEMP --查看用户可用空间即资源份额,-1代表无份额,如果没有查到的用户有两种可能,无配额、无限制 SYS@oracle11g>alter user tom quota 1m on users; User altered. --如何知道Tom用户使用的表空间是谁,temporary_tablespace看排序表空间 SYS@oracle11g>select a.default_tablespace,a.temporary_tablespace from dba_users a where a.username = 'TOM'; --修改Tom用户默认表空间,users改成tbs01 SYS@oracle11g>alter user tom default tablespace TBS01 ; User altered. SYS@oracle11g>select a.default_tablespace,a.temporary_tablespace from dba_users a where a.username = 'TOM'; DEFAULT_TABLESPACE TEMPORARY_TABLESPACE ------------------------------ ------------------------------ TBS01 TEMP --给Tom分配空间 SYS@oracle11g>alter user tom quota 1m on users; User altered. 可以插入数据了 TOM@oracle11g>insert into t01 values (9); 1 row created.
五、概要文件
Oracle数据库为了合理分配和使用系统的资源体系糊了概要文件。所谓的概要文件,就是一份描述如何使用系统的资源(主要是CPU资源)的配置文件。将概要文件授予某个数据库用户,在用户连接并访问数据库服务器时,系统就按照概要文件给他分配资源,其作用:
•管理数据系统资源
利用profile来分配资源配额,必须把初始化参数resource_limit设置为true
ALTER SYSTEM SET resource_limit=TRUE SCOPE=BOTH;
•管理数据库口令及验证方式
默认给用户分配的是default概要文件,将该文件授予用户,但该文件对资源没有任何限制,因此我们需要根据自己的数据库环境建立概要文件。
通过数据字典查看缺省资源配置内容:
select * from dba_profiles order by profile;
例如:当一个用户连接到数据库上以后,如果过一段时间没有任何操作,该进程就会自己中断,这样在应用程序就会因为进程超时自动断开而不能正常执行。
分析:该进程用户的概要文件(profile)配置问题,查看profile中的IDLE_TIME为60,即60秒该进程无任何操作就会自动断开。(!!熟悉profile的参数信息!!)
•概要文件创建
--用户口令(资源)管理风格,用户密码生存时间,改为一分钟 SYS@oracle11g>create profile p1 limit PASSWORD_LIFE_TIME 1/1440; Profile created. --查看 select * from dba_profiles order by profile(1);
•概要文件使用
--查看Tom的概要文件 SYS@oracle11g>select profile from dba_users where username = 'TOM'; PROFILE ------------------------------ --修改概要文件,使Tom用户的密码一分钟失效 SYS@oracle11g>alter user tom profile p1; User altered. --验证发现口令过期,但处于宽限期 SYS@oracle11g>select profile ,account_status from dba_users where username='TOM'; PROFILE ACCOUNT_STATUS ------------------------------ -------------------------------- P1 EXPIRED(GRACE) --修改概要文件,把宽限期也修改成1分钟 SYS@oracle11g>alter profile p1 limit PASSWORD_GRACE_TIME 1/1440; Profile altered. --验证,过一分钟尝试登录 MARRY@oracle11g>conn tom/tom ERROR: ORA-28002: the password will expire within 0 days Connected. --再过一分钟提示重新设置密码 TOM@oracle11g>conn tom/tom ERROR: ORA-28001: the password has expired Changing password for tom New password: 输入新密码 Retype new password: 输入新密码 Password changed Connected.
•PASSWORD_GRACE_TIME:宽限期
•PASSWORD_LOCK_TIME:锁定时间
•PASSWORD_LIFE_TIME:生存期
•PASSWORD_VERIFY_FUNCTION:可以写自己的函数规则
•FAILED_LOGIN_ATTEMPTS:错误的口令可以用几次
•PASSWORD_REUSE_TIME:相同的口令可以重用的时间
•PASSWORD_REUSE_MAX:相同的口令可以重用的次数
•CPU_PER_CALL:CPU调用的总时间量,单位厘秒
•LOGICAL_READS_PER_SESSION:每一个会话期间逻辑读取数,也就是Oracle8K的数量
•LOGICAL_READS_PER_CALL:每一条SQL语句可以读取数据块的数量
•CONNECT_TIME:连接时间,单位分钟,会话连接数据库最多可以持续多久
•IDLE_TIME:空闲时间,单位分钟,会话无任何操作多久断开连接
•PRIVATE_SGA:私有SQL区的大小,在PGA里私有SQL区能够占用的大小,以内存块为单位,通常是4K
•COMPOSITE_LIMIT:负荷资源,总资源不能超过的大小
•SESSIONS_PER_USER:相同的用户名能够启动几个会话连接数据库
•CPU_PER_SESSION:会话持续时间可以占用CPU时间片的总量
资源限制操作:
--启用资源的限制要打开一个参数 SYS@oracle11g>alter system set resource_limit=true; System altered. --相同的用户名Tom能够启动两个会话连接数据库 SYS@oracle11g>alter profile p1 limit SESSIONS_PER_USER 2; Profile altered. --验证,第三个Tom连接数据库 oracle@memory ~]$ sqlplus tom/tom SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 25 06:03:45 2018 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit Enter user-name:
posted on 2018-10-21 20:51 Memory_Python 阅读(162) 评论(0) 编辑 收藏 举报