如何杀掉一个用户下的所有进程并drop掉这个用户
如何杀掉一个用户下的所有进程并drop掉这个用户
Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION
This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE
CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
sleep_interval IN NUMBER DEFAULT 10)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
cannot_drop_user EXCEPTION;
PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);
user_count NUMBER := -1;
BEGIN
SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
IF user_count = 0 THEN
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
RETURN;
END IF;
FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
END LOOP;
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';
EXIT WHEN SQLCODE <> -1940;
EXCEPTION
WHEN cannot_drop_user THEN
--DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
DBMS_LOCK.SLEEP(sleep_interval);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
END;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT
SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Grant succeeded.
SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.
SQL> SET serveroutput ON size 1000000
SQL> SET timing ON
SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.
PL/SQL procedure successfully completed.
Elapsed: 00:00:10.71
SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL>
转自MOS
如何杀掉一个用户下的所有进程并drop掉这个用户
Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION
This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE
CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
sleep_interval IN NUMBER DEFAULT 10)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
cannot_drop_user EXCEPTION;
PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);
user_count NUMBER := -1;
BEGIN
SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
IF user_count = 0 THEN
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
RETURN;
END IF;
FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
END LOOP;
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';
EXIT WHEN SQLCODE <> -1940;
EXCEPTION
WHEN cannot_drop_user THEN
--DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
DBMS_LOCK.SLEEP(sleep_interval);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
END;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT
SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Grant succeeded.
SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.
SQL> SET serveroutput ON size 1000000
SQL> SET timing ON
SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.
PL/SQL procedure successfully completed.
Elapsed: 00:00:10.71
SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL>
转自MOS
Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION
This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE
CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
sleep_interval IN NUMBER DEFAULT 10)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
cannot_drop_user EXCEPTION;
PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);
user_count NUMBER := -1;
BEGIN
SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
IF user_count = 0 THEN
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
RETURN;
END IF;
FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
END LOOP;
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';
EXIT WHEN SQLCODE <> -1940;
EXCEPTION
WHEN cannot_drop_user THEN
--DBMS_OUTPUT.PUT_LINE(SQLERRM);
DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
DBMS_LOCK.SLEEP(sleep_interval);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
END;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT
SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Grant succeeded.
SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.
SQL> SET serveroutput ON size 1000000
SQL> SET timing ON
SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.
PL/SQL procedure successfully completed.
Elapsed: 00:00:10.71
SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL>
转自MOS
如何杀掉一个用户下的所有进程并drop掉这个用户的更多相关文章
- 【linux】kill ;杀死某一用户下的所有进程
[linux]kill :杀死某一用户下的所有进程 https://my.oschina.net/u/347414/blog/600854
- linux暂停一个在运行中的进程【转】
转自:https://blog.csdn.net/Tim_phper/article/details/53536621 转载于: http://www.cszhi.com/20120328/linux ...
- linux下批量kill进程的方法
--kill某个用户下的所有进程(用户为test)--pkill # pkill -u test--killall # killall -u test--ps # ps -ef | grep t ...
- (转)Linux下Oracle启动、建立表空间、用户、授权、数据库导入导出
Linux系列 启动1.启动数据库实例,分为两步:第一步,启动监听:第二步,启动数据库实例. 1.1进入到sqlplus启动实例 [oracle@redhat ~]$ su - oracle ...
- 使用sys用户创建其他用户下的dblink
因为dblink的创建和删除只能是它的所属用户来操作,所以我们无法直接使用sys用户创建其他用户下的dblink,当遇到有这样的需求时,可以先建立该用户下存储过程,再通过调用这个存储过程来间接实现. ...
- spool命令、创建一个表,创建而且copy表,查看别的用户下的表,rowid行地址 索引的时候使用,表的增删改查,删除表,oracle的回收站
1.spool命令 spool "D:\test.txt" spool off SQL> host cls 2.创建一个表 SQL> --条件(1):有创建 ...
- oracle impdp将导出用户的所有对象导入至另一个用户下,生成的触发器语句问题处理
问题产生的操作步骤及详细说明: 1)操作的数据库是oracle 11g,先通过命令将用户GAS_NEW的数据导出,命令语句如下: expdp GAS_NEW/GAS_NEW@ORCL schemas= ...
- Oracle 如何删除掉一个用户下的所有对象
create or replace procedure drop_all as cursor cur_obj is select uo.OBJECT_NAME, uo.OBJECT_TYPE from ...
- linux下的守护进程
关于守护进程,在此会介绍一下几种: 1.screen 2.supervisord(python) 一:Screen 开始使用Screen 简单来说,Screen是一个可以在多个进程之间多路复用一个物理 ...
随机推荐
- C# 检查键盘是否唤醒到桌面上显示
大概需要的win32函数 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName)//返回值为具有 ...
- C# B站的弹幕提取
要知道B站的弹幕位置 如果只考虑视频,B站的链接格式为:https://www.bilibili.com/video/av34042815.把av后面的数字看做是唯一标记即可. 既然能够把弹幕加载出来 ...
- BZOJ - 2457 思維+貪心
//為什麼我的Chrome OS更新後變成強制繁體了?? 題目要求使用最少的雙端隊列來維護一個單調非降序列 先來看下規律 首先,val肯定是單調非降的,在相等val範圍內的id可以xjb亂放不影響 其 ...
- Web Worker 案例
什么是 Web Worker? 当在 HTML 页面中执行脚本时,页面的状态是不可响应的,直到脚本已完成. web worker 是运行在后台的 JavaScript,独立于其他脚本,不会影响页面的性 ...
- [转] domeOS 环境搭建 自动化构建部署
[From]http://dockone.io:82/article/4150 系统:CentOS Linux 7A机子(domeos服务器):1. gitlab安装(私有仓库):yum -y ins ...
- html自定义垂直导航菜单(加强版--自定义传入menu参数,支持JSONArray、JSArray、JSONObject、JSObject)
在上一篇中我简单写了个html自定义垂直导航菜单,缺点很明显,里面的数据是固定死的,不能动态更改数据. 这里我重写了一个修改版的垂直二级导航菜单,将原先的menuBox.init(config);修改 ...
- oracle 笔记---(六)__表空间
查看表空间的大小 select tablespace_name,block_size,contents from dba_tablespaces; 查看表空间对应的数据文件 select file_n ...
- Ba Gua Zhen
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5544 学习链接:https://www.cnblogs.com/qscqesze/p/4902518. ...
- Yii 自带的分页实例
yii自带的分页很好用,简单的几行代码就能把分页搞出来,唯一恼火的是只能写在controller中,所以有时候controller中的方法有点臃肿.废话少说,上代码上图. 一.代码实例: 1.控制器中 ...
- Python之装饰器、迭代器和生成器
在学习python的时候,三大“名器”对没有其他语言编程经验的人来说,应该算是一个小难点,本次博客就博主自己对装饰器.迭代器和生成器理解进行解释. 为什么要使用装饰器 什么是装饰器?“装饰”从字面意思 ...