ORACLE Profile使用详解

如何限制oracle中用户的资源的使用(包括连接时间和空闲时间等)

 

可以创建不同的资源限制,最好将ALTER SYSTEM SET RESOURCE_LIMIT=TRUE。
写在init文件中:RESOURCE_LIMIT=TRUE ,不然下次启动可能失效。

create profile low_limits limit
           idle_time  10 --分钟
           connect_time  unlimited; --分钟

然后把某种配置文件赋给某个用户:
alter user youruser  profile low_limits;

然后可以查看:
select profile from dba_users where username='YOURUSER';
select * from dba_profile where profile='low_limits';

 

一、目的:

Oracle系统中的profile可以用来对用户所能使用的数据库资源进行限制,使用Create Profile命令创建一个Profile,用它来实现对数据库资源的限制使用,如果把该profile分配给用户,则该用户所能使用的数据库资源都在该profile的限制之内。 

 

二、条件:

创建profile必须要有CREATE PROFILE的系统权限。

为用户指定资源限制,必须:

1.动态地使用alter system或使用初始化参数resource_limit使资源限制生效。该改变对密码资源无效,密码资源总是可用。 

SQL> show parameter resource_limit

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

resource_limit                       boolean     FALSE

 

SQL> alter system set resource_limit=true;

 

系统已更改。

 

SQL> show parameter resource_limit;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

resource_limit                       boolean     TRUE

 

SQL>

 

2.使用create profile创建一个定义对数据库资源进行限制的profile。

3.使用create user 或alter user命令把profile分配给用户。

 

三、语法:

     CREATE PROFILE profile

LIMIT { resource_parameters

         | password_parameters

         }

           [ resource_parameters

           | password_parameters

           ]... ;

 

<resource_parameters> 

{ { SESSIONS_PER_USER

 | CPU_PER_SESSION

 | CPU_PER_CALL

 | CONNECT_TIME

 | IDLE_TIME

 | LOGICAL_READS_PER_SESSION

 | LOGICAL_READS_PER_CALL

 | COMPOSITE_LIMIT

 }

 { integer | UNLIMITED | DEFAULT }

| PRIVATE_SGA

 { integer [ K | M ] | UNLIMITED | DEFAULT }

}

 

< password_parameters >

{ { FAILED_LOGIN_ATTEMPTS

 | PASSWORD_LIFE_TIME

 | PASSWORD_REUSE_TIME

 | PASSWORD_REUSE_MAX

 | PASSWORD_LOCK_TIME

 | PASSWORD_GRACE_TIME

 }

 { expr | UNLIMITED | DEFAULT }

| PASSWORD_VERIFY_FUNCTION

     { function | NULL | DEFAULT }

}

 

四、语法解释:

profile:配置文件的名称。Oracle数据库以以下方式强迫资源限制:

       1.如果用户超过了connect_time或idle_time的会话资源限制,数据库就回滚当前事务,并结束会话。用户再次执行命令,数据库则返回一个错误,

       2.如果用户试图执行超过其他的会话资源限制的操作,数据库放弃操作,回滚当前事务并立即返回错误。用户之后可以提交或回滚当前事务,必须结束会话。 

       提示:可以将一条分成多个段,如1小时(1/24天)来限制时间,可以为用户指定资源限制,但是数据库只有在参数生效后才会执行限制。 

       

       Unlimited:分配该profile的用户对资源使用无限制,当使用密码参数时,unlimited意味着没有对参数加限制。 

 

       Default:指定为default意味着忽略对profile中的一些资源限制,Default profile初始定义对资源不限制,可以通过alter profile命令来改变。 

 

Resource_parameter部分

       

       Session_per_user:指定限制用户的并发会话的数目。

       Cpu_per_session:指定会话的CPU时间限制,单位为百分之一秒。 

       Cpu_per_call:指定一次调用(解析、执行和提取)的CPU时间限制,单位为百分之一秒。

       Connect_time:指定会话的总的连接时间,以分钟为单位。

       Idle_time:指定会话允许连续不活动的总的时间,以分钟为单位,超过该时间,会话将断开。但是长时间运行查询和其他操作的不受此限制。 

       Logical_reads_per_session:指定一个会话允许读的数据块的数目,包括从内存和磁盘读的所有数据块。 

       Logical_read_per_call:指定一次执行SQL(解析、执行和提取)调用所允许读的数据块的最大数目。

       Private_sga:指定一个会话可以在共享池(SGA)中所允许分配的最大空间,以字节为单位。(该限制只在使用共享服务器结构时才有效,会话在SGA中的私有空间包括私有的SQL和PL/SQL,但不包括共享的SQL和PL/SQL)。

       Composite_limit:指定一个会话的总的资源消耗,以service units单位表示。Oracle数据库以有利的方式计算cpu_per_session,connect_time,logical_reads_per_session和private-sga总的service units

       

 

Password_parameter部分:

       

       Failed_login_attempts:指定在帐户被锁定之前所允许尝试登陆的的最大次数。

       Password_life_time:指定同一密码所允许使用的天数。如果同时指定了password_grace_time参数,如果在grace period内没有改变密码,则密码会失效,连接数据库被拒绝。如果没有设置password_grace_time参数,默认值unlimited将引发一个数据库警告,但是允许用户继续连接。

       Password_reuse_time和password_reuse_max:这两个参数必须互相关联设置,password_reuse_time指定了密码不能重用前的天数,而password_reuse_max则指定了当前密码被重用之前密码改变的次数。两个参数都必须被设置为整数。

       1.如果为这两个参数指定了整数,则用户不能重用密码直到密码被改变了password_reuse_max指定的次数以后在password_reuse_time指定的时间内。

       如:password_reuse_time=30,password_reuse_max=10,用户可以在30天以后重用该密码,要求密码必须被改变超过10次。 

       2.如果指定了其中的一个为整数,而另一个为unlimited,则用户永远不能重用一个密码。

       3.如果指定了其中的一个为default,Oracle数据库使用定义在profile中的默认值,默认情况下,所有的参数在profile中都被设置为unlimited,如果没有改变profile默认值,数据库对该值总是默认为unlimited。

       4.如果两个参数都设置为unlimited,则数据库忽略他们。

 

       Password_lock_time:指定登陆尝试失败次数到达后帐户的缩定时间,以天为单位。

       Password_grace_time:指定宽限天数,数据库发出警告到登陆失效前的天数。如果数据库密码在这中间没有被修改,则过期会失效。

       Password_verify_function:该字段允许将复杂的PL/SQL密码验证脚本做为参数传递到create profile语句。Oracle数据库提供了一个默认的脚本,但是自己可以创建自己的验证规则或使用第三方软件验证。 对Function名称,指定的是密码验证规则的名称,指定为Null则意味着不使用密码验证功能。如果为密码参数指定表达式,则该表达式可以是任意格式,除了数据库标量子查询。 

       
===========================================================================================

 

 

用create user创建用户的时候可以指定PROFILE子句

PROFILE Clause

Specify the profile you want to assign to the user. The profile limits the amount of database resources the user can use. If you omit this clause, then Oracle Database assigns the DEFAULT profile to the user.

下面我们看一下DEFAULT PROFILE的内容

SQL> select * from dba_profiles where profile='DEFAULT';

PROFILE    RESOURCE_NAME                  RESOURCE LIMIT
---------- ------------------------------ -------- --------------------
DEFAULT    COMPOSITE_LIMIT                KERNEL   UNLIMITED
DEFAULT    SESSIONS_PER_USER              KERNEL   UNLIMITED
DEFAULT    CPU_PER_SESSION                KERNEL   UNLIMITED
DEFAULT    CPU_PER_CALL                   KERNEL   UNLIMITED
DEFAULT    LOGICAL_READS_PER_SESSION      KERNEL   UNLIMITED
DEFAULT    LOGICAL_READS_PER_CALL         KERNEL   UNLIMITED
DEFAULT    IDLE_TIME                      KERNEL   UNLIMITED
DEFAULT    CONNECT_TIME                   KERNEL   UNLIMITED
DEFAULT    PRIVATE_SGA                    KERNEL   UNLIMITED
DEFAULT    FAILED_LOGIN_ATTEMPTS          PASSWORD 10
DEFAULT    PASSWORD_LIFE_TIME             PASSWORD UNLIMITED

PROFILE    RESOURCE_NAME                  RESOURCE LIMIT
---------- ------------------------------ -------- --------------------
DEFAULT    PASSWORD_REUSE_TIME            PASSWORD UNLIMITED
DEFAULT    PASSWORD_REUSE_MAX             PASSWORD UNLIMITED
DEFAULT    PASSWORD_VERIFY_FUNCTION       PASSWORD NULL
DEFAULT    PASSWORD_LOCK_TIME             PASSWORD UNLIMITED
DEFAULT    PASSWORD_GRACE_TIME            PASSWORD UNLIMITED

16 rows selected.

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

 

=========================================================

一些错误信息及解决方法
ORA-02390 exceeded COMPOSITE_LIMIT, you are being logged off
Cause: The COMPOSITE_LIMIT for the profile is exceeded. That is, the weighted sum of the connection time, logical reads per session, CPU usage per session, and private SGA space used during the session exceeded the limit set by the COMPOSITE_LIMIT clause set in the user profile.
Action: If this happens often, ask the database administrator to raise the COMPOSITE_LIMIT of the user profile, or determine which resource is used the most and raise the limit on that resource.

ORA-02391 exceeded simultaneous SESSIONS_PER_USER limit
Cause: An attempt was made to exceed the maximum number of concurrent sessions allowed by the SESSIONS_PER_USER clause of the user profile.
Action: End one or more concurrent sessions or ask the database administrator to increase the SESSIONS_PER_USER limit of the user profile. For more information about SESSIONS_PER_USER and the database administrator's specific tasks of adjusting concurrent sessions, see the Oracle9i SQL Reference and the Oracle9i Database Administrator's Guide.

ORA-02392 exceeded session limit on CPU usage, you are being logged off
Cause: An attempt was made to exceed the maximum CPU usage allowed by the CPU_PER_SESSION clause of the user profile.
Action: If this happens often, ask the database administrator to increase the CPU_PER_SESSION limit of the user profile.

ORA-02393 exceeded call limit on CPU usage
Cause: An attempt was made to exceed the maximum CPU time for a call, a parse, execute, or fetch, allowed by the CPU_PER_CALL clause of the user profile.
Action: If this happens often, ask the database administrator to increase the CPU_PER_CALL limit of the user profile.

ORA-02394 exceeded session limit on IO usage, you are being logged off
Cause: An attempt was made to exceed the maximum I/O allowed by the LOGICAL_READS_PER_SESSION clause of the user profile.
Action: If this happens often, ask the database administrator to increase the LOGICAL_READS_PER_SESSION limit of the user profile.

ORA-02395 exceeded call limit on IO usage
Cause: An attempt was made to exceed the maximum I/O for a call, a parse, execute, or fetch, allowed by the LOGICAL_READS_PER_CALL clause of the user profile.
Action: If this happens often, ask the database administrator to increase the LOGICAL_READS_PER_CALL limit of the user profile.

ORA-02396 exceeded maximum idle time, please connect again
Cause: A user has exceeded the maximum time allowed to remain idle.
Action: The user must reconnect to the database.

ORA-02397 exceeded PRIVATE_SGA limit, you are being logged off
Cause: This error occurs only when using a multi-threaded server.
Action: Contact the database administrator to expand the PRIVATE_SGA limit.

===========================================================================================

刚才自己去做了一下实验 设置了FAILED_LOGIN_ATTEMPTS=10,登录了10次用户账户就被锁定了。可是我的resource_limit设置的是false啊,怎么也起作用了?网上搜了一下,答案如下:

 

profile分两部分,resource_limit为true限定 资源参数(resource parameters) 设置有效,密码参数(password parameters)设置始终有效,不管resouce_limit的值为true或false.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值