转:oracle中用户删除不了,提示“无法删除当前已连接的用户”
1.alter user XXX account lock;SELECT * FROM V$SESSION WHERE USERNAME='LGDB';alter system kill session 'xx,xx'drop user xx cascade
2.或者shutdown掉数据库,再重启
具体可如下:
(1)查看用户的连接状况
select username,sid,serial# from v$session
------------------------------------------
如下结果:
username sid serial#
----------------------------------------
NETBNEW 513 22974
NETBNEW 514 18183
NETBNEW 516 21573
NETBNEW 531 9
WUZHQ 532 4562
(2)找到要删除用户的sid,和serial,并删除
-------------------------------------------
如:你要删除用户'WUZHQ',可以这样做:
alter system kill session'532,4562'
(3)删除用户
--------------------------------------------
drop user username cascade
(**)如果在drop 后还提示ORA-01940:无法删除当前已链接的用户,说明还有连接的session,可以通过查看session的状态来确定该session是否被kill 了,用如下语句查看:
-------------------------------------
select saddr,sid,serial#,paddr,username,status from v$session where username is not null
结果如下(以我的库为例):
saddr sid serial# paddr username status
--------------------------------------------------------------------------------------------------------
564A1E28 513 22974 569638F4 NETBNEW ACTIVE
564A30DC 514 18183 569688CC NETBNEW INACTIVE
564A5644 516 21573 56963340 NETBNEW INACTIVE
564B6ED0 531 9 56962D8C NETBNEW INACTIVE
564B8184 532 4562 56A1075C WUZHQ KILLED
1.你可以用 alter user 用户ID account unlock 先解开这个用户锁定
2.这个机制是在用户的profile中设定,profile主要是对系统资源和用户囗令的管理,你可以打开查看,里面有个 FAILED_LOGIN_ATTEMPTS 参数,你还可以结合其它的参数一起使用来管理资源和囗令。系统有个默认的profile叫default
给个示例:
1.资源的
create profile luck_prof limit
sessions_per_user 8
cpu_per_session 16800
logical_reads_per_session 23688
connect_time 268
idle_time 38;
2.囗令的,如修改 default
alter profile default limit
password_life_time 60
password_grace_time 10
password_reuse_time 1800
failed_login_attempts 3
password_lock_time 1/1440;
然后再创建或修改用户时指定一个profile如:
create user wuser
identified by wuser
.......
profile luck_prof ;