zoukankan      html  css  js  c++  java
  • 【Oracle】删除正在连接的用户

    1.查询用户的连接状态
    Select username,sid,serial# from v$session where username='XY1027';

    USERNAME                              SID    SERIAL#
    ------------------------------ ---------- ----------
    XY1027                                 22          1
    XY1027                                142          1

    2.逐个删除
    Alter system kill session'22,1';

    3.删除用户
    drop user xy1027 cascade;

    4.检查状态

    如果在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

    status 为要删除用户的session状态,如果还为inactive,说明没有被kill掉,如果状态为killed,说明已kill。

    由此可见,WUZHQ这个用户的session已经被杀死。此时可以安全删除用户。

  • 相关阅读:
    [LeetCode] 314. Binary Tree Vertical Order Traversal
    [LeetCode] 139. Word Break
    [LeetCode] 540. Single Element in a Sorted Array
    [LeetCode] 1443. Minimum Time to Collect All Apples in a Tree
    [LeetCode] 1442. Count Triplets That Can Form Two Arrays of Equal XOR
    [LeetCode] 1441. Build an Array With Stack Operations
    [LeetCode] 277. Find the Celebrity
    [LeetCode] 1232. Check If It Is a Straight Line
    [LeetCode] 10. Regular Expression Matching
    [LeetCode] 1192. Critical Connections in a Network
  • 原文地址:https://www.cnblogs.com/masb/p/2340562.html
Copyright © 2011-2022 走看看