您的位置:首页 > 数据库 > Oracle

All about oracle profile

2013-05-09 23:24 239 查看
一、目的:

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

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

SYS@ orcl> alter profile default limit IDLE_TIME 1;
Profile altered.

SYS@ orcl> alter system set resource_limit=true;
System altered.

00:24:57 SYS@ orcl> select sid, serial#, status from v$session;
SID    SERIAL# STATUS
------- ---------- --------
1          5 ACTIVE
2          1 ACTIVE
3          1 ACTIVE
4          1 ACTIVE
5          1 ACTIVE
6          1 ACTIVE
7          1 ACTIVE
8          1 ACTIVE
9          1 ACTIVE
10          1 ACTIVE
11          1 ACTIVE
12          1 ACTIVE
13          1 ACTIVE
14          1 ACTIVE
15          1 ACTIVE
16          1 ACTIVE
17          7 ACTIVE
18          5 ACTIVE
20          2 ACTIVE
21          1 ACTIVE
24          1 ACTIVE
25          5 ACTIVE
28          4 ACTIVE
31          1 ACTIVE
35        167 INACTIVE
37         31 ACTIVE
43        104 ACTIVE
44         11 ACTIVE
47         94 INACTIVE

00:24:58 SYS@ orcl> /
SID    SERIAL# STATUS
------- ---------- --------
1          5 ACTIVE
2          1 ACTIVE
3          1 ACTIVE
4          1 ACTIVE
5          1 ACTIVE
6          1 ACTIVE
7          1 ACTIVE
8          1 ACTIVE
9          1 ACTIVE
10          1 ACTIVE
11          1 ACTIVE
12          1 ACTIVE
13          1 ACTIVE
14          1 ACTIVE
15          1 ACTIVE
16          1 ACTIVE
17          7 ACTIVE
18          5 ACTIVE
20          2 ACTIVE
21          1 ACTIVE
24          1 ACTIVE
25          5 ACTIVE
28          4 ACTIVE
31          1 ACTIVE
35        167 SNIPED
37         31 ACTIVE
43        104 ACTIVE
44         11 ACTIVE
47         94 INACTIVE

[oracle@rhel5 ~]$ sqlplus scott/tiger

SCOTT@ orcl> select distinct sid from v$mystat;
SID
----------
35

SCOTT@ orcl> /
select distinct sid from v$mystat
*
ERROR at line 1:
ORA-02396: exceeded maximum idle time, please connect again


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:指定在帐户被锁定之前所允许尝试登陆的的最大次数。

SQL> select name,lcount from user$ where name='SYSTEM';
NAME                               LCOUNT
------------------------------ ----------
SYSTEM                                  0
SQL> conn system/1;
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> conn system/2;
ERROR:
ORA-01017: invalid username/password; logon denied
SQL> conn system/3;
ERROR:
ORA-01017: invalid username/password; logon denied
SQL> conn system/4;
ERROR:
ORA-01017: invalid username/password; logon denied
SQL> conn / as sysdba;
Connected.
SQL> select name,lcount from user$ where name='SYSTEM';
NAME                               LCOUNT
------------------------------ ----------
SYSTEM                                  4
SQL> conn system/oracle;
Connected.
SQL> conn / as sysdba;
Connected.
SQL> select name,lcount from user$ where name='SYSTEM';
NAME                               LCOUNT
------------------------------ ----------
SYSTEM                                  0


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则意味着不使用密码验证功能。如果为密码参数指定表达式,则该表达式可以是任意格式,除了数据库标量子查询。

      

五、举例:

1.创建一个profile:

create profile new_profile limit 

password_reuse_max 10

password_reuse_time 30;

2.设置profile资源限制:

create profile app_user limit

sessions_per_user unlimited

cpu_per_session unlimited

cpu_per_call 3000

connect_time 45

logical_reads_per_session default

logical_reads_per_call 1000

private_sga 15k

composite_limit 5000000;

总的resource cost不超过五百万service units。计算总的resource cost的公式由alter resource cost语句来指定。

      

3.设置密码限制profile:

create profile app_users2 limit

failed_login_attempts 5

password_life_time 60

password_reuse_time 60

password_reuse_max 5

password_verify_function verify_function

password_lock_time 1/24

password_grace_time 10;

            

4.将配置文件分配给用户:

SQL> alter user dinya profile app_user;

用户已更改。
             

SQL> alter user dinya profile default;

用户已更改。

错误信息及解决方法

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: