脚本-oracle个人用户并行限制
生产库个人用户大量使用并行会导致数据库负载忽高忽低,频繁分析,浪费时间,且可能会出现大量直接路径读,影响数据库整体性能(此问题跟他们讲了也不听,不胜其烦)
之前写过使用resource_managed进行并行的限制,该方法适用于数据库体量较小,连接和用户数量少的库,大体量的库会有latch产生(这里不过多阐述)
还有就是使用profile中的用户会话数量进行限制,这个会影响到业务人员开多个窗口的问题
无奈之下编写个人用户并行限制脚本
使用前提:
1.使用此药的数据库生产用户和个人用户有严格的权限划分,比如不同的profile
2.使用并行的用户会话会被kill掉,该用户被锁定5分钟后自动解锁
3.需要提前创建表 user_auto_lock,用户名请自定(稍微改下脚本即可)
#!/bin/bash
# File: auto_lock_parallel_user.sh
# Version: 1.0
#author jiacheng
#The concurrent user is locked and automatically unlocked after five minutes
##############################################################################
###########################---usage---########################################
#one node config!!!
#first: create table dbmt.user_auto_lock (exectime date default sysdate,sid number(10),serial number(7),inst_id number(3),username varchar2(100),sql_id varchar2(100),degree number(3),req_degree number(3),slaves number(3));
#linux: */1 7-20 * * * sh /home/oracle/scripts/auto_lock_parallel_user.sh >> /home/oracle/scripts/auto_lock_parallel_user.log
#HPUX: * 7-20 * * * sh /home/oracle/scripts/auto_lock_parallel_user.sh >> /home/oracle/scripts/auto_lock_parallel_user.log
###############################################################################
>$LOGFILE
set serveroutput on;
begin
for r in (select username from dbmt.user_auto_lock where exectimeSYSDATE-7/1440)
loop
begin
dbms_output.put_line('alter user ' || r.username || ' account unlock');
EXECUTE IMMEDIATE 'alter user ' || r.username || ' account unlock';
exception
when others then
dbms_output.put_line('ERROR ' || SQLCODE || ' ' || SQLERRM);
end;
end loop;
end;
/
exit;
EOF
`
echo "${unlock_user}"
function get_xinxi_sql
{
sqlplus -S '/ as sysdba' <
echo "$px_xinxi" > current_parallel.log
echo "$px_xinxi" > current_parallel.log
--编写不易,且用且珍惜,转载请注明来处