建立JOB定期清理KILLED的SESSION

本文介绍了一个使用Oracle PL/SQL编写的脚本,该脚本通过创建JOB实现每10秒定期清理数据库中状态为KILLED的会话。需要注意的是,此脚本需以SYS用户授予当前用户v_$session的查询权限。
SQL code
--作用:建立JOB定期清理KILLED的SESSION
--注意:此脚本必须以SYS用户授予当前用户select on v_$session权限
--创建JOB
DECLARE
n_job NUMBER;
BEGIN 
dbms_job.submit(job => n_job, 
what => 'BEGIN
FOR rc IN (SELECT sid,serial# FROM v$session WHERE status = ''KILLED'') LOOP
EXECUTE IMMEDIATE ''ALTER SYSTEM KILL SESSION '''':sid,:serial#'''' IMMEDIATE'' USING rc.sid,rc.serial#;
END LOOP;
END;',
next_date =>SYSDATE, --现在开始
INTERVAL => 'SYSDATE+10/(24*3600)'); --每10秒执行一次 
COMMIT; 
END;
/
--移除JOB
BEGIN
DBMS_JOB.REMOVE(65);
COMMIT;
END;
/
--确认是否正常运行
SELECT last_sec,failures FROM user_jobs WHERE job = 65;
Started by user Yilun Wu Running as SYSTEM Building remotely on aws-test-agent in workspace /build/jenkins/workspace/Tapo_H500_job4_QA_Security_Rounds [Tapo_H500_job4_QA_Security_Rounds] $ /bin/sh -xe /tmp/jenkins9597094916442764199.sh + env JENKINS_HOME=/var/jenkins_home SSH_CLIENT=10.0.138.175 35804 22 USER=ubuntu CI=true RUN_CHANGES_DISPLAY_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/9/display/redirect?page=changes XDG_SESSION_TYPE=tty NODE_LABELS=aws-test-agent SHLVL=0 HUDSON_URL=http://10.0.138.175/ HOME=/home/ubuntu OLDPWD=/home/ubuntu BUILD_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/9/ JENKINS_SERVER_COOKIE=b6155e08db5e2646 HUDSON_COOKIE=4934cf55-e77e-40cc-85bd-4281249ec245 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus WORKSPACE=/build/jenkins/workspace/Tapo_H500_job4_QA_Security_Rounds LOGNAME=ubuntu NODE_NAME=aws-test-agent RUN_ARTIFACTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/9/display/redirect?page=artifacts _=/usr/bin/java XDG_SESSION_CLASS=user EXECUTOR_NUMBER=2 XDG_SESSION_ID=78 BUILD_DISPLAY_NAME=#9 RUN_TESTS_DISPLAY_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/9/display/redirect?page=tests HUDSON_HOME=/var/jenkins_home JOB_BASE_NAME=Tapo_H500_job4_QA_Security_Rounds PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin BUILD_ID=9 XDG_RUNTIME_DIR=/run/user/1000 BUILD_TAG=jenkins-Tapo_H500_job4_QA_Security_Rounds-9 LANG=C.UTF-8 JENKINS_URL=http://10.0.138.175/ JOB_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/ BUILD_NUMBER=9 SHELL=/bin/bash RUN_DISPLAY_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/9/display/redirect HUDSON_SERVER_COOKIE=b6155e08db5e2646 JOB_DISPLAY_URL=http://10.0.138.175/job/Tapo_H500_job4_QA_Security_Rounds/display/redirect JOB_NAME=Tapo_H500_job4_QA_Security_Rounds PWD=/build/jenkins/workspace/Tapo_H500_job4_QA_Security_Rounds SSH_CONNECTION=10.0.138.175 35804 10.0.131.164 22 WORKSPACE_TMP=/build/jenkins/workspace/Tapo_H500_job4_QA_Security_Rounds@tmp + BRANCH_NAME=Tapo/H500 + command -v repo + echo Installing repo tool from Google... Installing repo tool from Google... + mkdir -p /home/ubuntu/.bin + export PATH=/home/ubuntu/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin + curl https://storage.googleapis.com/git-repo-downloads/repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 44952 100 44952 0 0 1223k 0 --:--:-- --:--:-- --:--:-- 1254k + chmod a+rx /home/ubuntu/.bin/repo + echo Repo tool installed successfully Repo tool installed successfully + [ ! -d .repo/repo ] + [ ! -d .repo/manifests ] + echo Repo already initialized, skipping setup... Repo already initialized, skipping setup... + NEED_INIT=false + git config --global user.name Jenkins CI + git config --global user.email jenkins@tp-link.com + git config --global color.ui false + export REPO_NO_SELF_UPDATE=1 + export GIT_TERMINAL_PROMPT=0 + export GIT_SSH_COMMAND=ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null + [ false = true ] + echo Starting repo sync (first attempt - will kill after 3 seconds)... Starting repo sync (first attempt - will kill after 3 seconds)... + SYNC_PID=2401171 + sleep 3 + repo sync -c -j14 -vv Warning: Permanently added '[gerrittest-29418-nlb-929aa8adffe6965c.elb.us-west-1.amazonaws.com]:29418' (ED25519) to the list of known hosts. Warning: Permanently added '[gerrittest-29418-nlb-929aa8adffe6965c.elb.us-west-1.amazonaws.com]:29418' (ED25519) to the list of known hosts. repo sync has finished successfully. + kill 2401171 + true + wait 2401171 + echo Killed first sync attempt, waiting a moment... Killed first sync attempt, waiting a moment... + sleep 1 + echo Running repo sync... Running repo sync... + repo sync -c -j14 -vv Warning: Permanently added '[gerrittest-29418-nlb-929aa8adffe6965c.elb.us-west-1.amazonaws.com]:29418' (ED25519) to the list of known hosts. Warning: Permanently added '[gerrittest-29418-nlb-929aa8adffe6965c.elb.us-west-1.amazonaws.com]:29418' (ED25519) to the list of known hosts. repo sync has finished successfully. + echo Repo sync completed successfully! Repo sync completed successfully! + cd CAMEOS + repo forall -c # Only run if HEAD is detached if [ -z "$(git symbolic-ref --short -q HEAD)" ]; then # Get the remote branch names from origin/gerrit for b in $(git branch -r | grep "gerrit/" | sed "s|gerrit/||"); do # Just pick the branch that exists remotely git checkout -B $b gerrit/$b break done fi + cd ../ [Tapo_H500_job4_QA_Security_Rounds] $ /bin/sh -xe /tmp/jenkins3171628310780652284.sh + IMAGE_NAME=h500_build_env:latest + docker build -t h500_build_env:latest ERROR: failed to build: please specify build context (e.g. "." for the current directory) + echo ❌ Docker image build failed. ❌ Docker image build failed. + exit 1 Build step 'Execute shell' marked build as failure Finished: FAILURE
最新发布
12-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值