Oracle下session的查詢與刪除
Oracle下session的查詢與刪除
1、查詢當前session
SQL> select username,sid,serial# from v$session where username is not null;
USERNAME SID SERIAL#
------------------------------ ---------- ----------
SYS 144 4
HYL 146 48
SCOTT 147 64
HR 159 15
--SERIAL#:SID有可能會重複,當兩個session的SID重複時,SERIAL#用來區別session
2、刪除當前session
SQL> alter system kill session '146,48';
System altered.
hyl的session下執行操作如下:
SQL> show user
USER is "HYL"
SQL> select * from test1;
select * from test1
*
ERROR at line 1:
ORA-00028: your session has been killed
--------------------------------------------------------------------------------
Linux-6-64下安裝Oracle 12C筆記
在CentOS 6.4下安裝Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虛擬機器中安裝步驟
Debian 下 安裝 Oracle 11g XE R2
--------------------------------------------------------------------------------
3、刪除當前session的使用者
思路:先關閉session,然後再刪除使用者
示範:在不關閉session的情況下刪除使用者現象:
SQL> select username,account_status from dba_users;
--查看當前有哪些使用者
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
CSMIG OPEN
MGMT_VIEW OPEN
SYS OPEN
SYSTEM OPEN
HYL OPEN
OE EXPIRED & LOCKED
6 rows selected.
SQL> select username,sid,serial# from v$session where username is not null;
--通過v$session視圖,查看會話的sid、serial#
USERNAME SID SERIAL#
------------------------------ ---------- ----------
SYS 144 4
HYL 146 54
SCOTT 147 64
HR 159 15
SQL> drop user hyl; --刪除,報錯了,表明會話中存在的使用者是不能被刪除的,需要先將其關閉
drop user hyl
*
ERROR at line 1:
ORA-01940: cannot drop a user that is currently connected
SQL> alter system kill session '146,54';
System altered.
--hyl的session下查看資料,資訊顯示該session已經被kill掉,表明刪除session成功
SQL> select * from test1;
select * from test1
*
ERROR at line 1:
ORA-00028: your session has been killed
--下面完成刪除使用者
SQL> drop user hyl; --刪除使用者報錯了,此時hyl使用者下有對象存在
drop user hyl
*
ERROR at line 1:
ORA-01922: CASCADE must be specified to drop 'HYL'
SQL> drop user hyl cascade; --將使用者及其所有對象全部刪除
User dropped.
--嘗試hyl串連,報錯,無法使用hyl登陸session
SQL> conn hyl/oracle
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
--查看dba_users資料字典,表明hyl使用者已經被刪除
SQL> select username,account_status from dba_users;
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
CSMIG OPEN
MGMT_VIEW OPEN
SYS OPEN
SYSTEM OPEN
OE EXPIRED & LOCKED
5 rows selected.
小結:
查詢當前會話:select username,sid,serial# from v$session where username is not null;
刪除當前會話:alter system kill session 'sid,serial#';
刪除當前會話的使用者,先kill session,再drop user(若使用者下有對象,使用cascade命令)
更多詳情見請繼續閱讀下一頁的精彩內容: