这是来自Jessie的需求。以前只是知道怎么做,本案做了实践。在此记录以备忘。
关键字:限制会话数 profile SESSIONS_PER_USER resource_limit
[@more@]功能需求
限制通过某个DB user建立的session数。
实验环境:
·OS
Microsoft Winsows XP Professional 版本 2002 Service Pack 3
·DB
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
步骤
1-查询用户使用的profile
SQL> select profile from dba_users where username='JOE';
PROFILE
------------------------------
DEFAULT
2-查询使用该profile的用户
SQL> select count(1) from dba_users where profile='DEFAULT';
COUNT(1)
----------
28
不止一个用户使用profile default,所以不能直接修改profile default,否则其他用户都会受到限制。
3-创建新的profile
由于只对用户做连接树的限制,所以新建的profile中其他项都要与profile default一致。
--创建新profile与profile default完全一样
create profile prof_joe limit
sessions_per_user unlimited
cpu_per_session unlimited
cpu_per_call unlimited
connect_time unlimited
idle_time unlimited
logical_reads_per_session unlimited
logical_reads_per_call unlimited
composite_limit unlimited
private_sga unlimited
failed_login_attempts 10
password_life_time unlimited
password_reuse_time unlimited
password_reuse_max unlimited
password_lock_time unlimited
password_grace_time unlimited
password_verify_function Null;
--修改sessions_per_user参数限制连接数
alter profile prof_joe limit SESSIONS_PER_USER &limit_num;
4-修改用户使用新的profile
alter user joe profile prof_joe;
5-开启resource_limit
alter system set resource_limit=true;
效果
本实验中设置的SESSIONS_PER_USER为1,即仅允许用户JOE创建一个连接。当创建第二个连接时,报如下错误:
ERROR:ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21129591/viewspace-1052411/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21129591/viewspace-1052411/