connection和session的關係
1.官方解釋:
1.1 connection:
A connection is a physical path from a client to an Oracle instance. A connection is established either over a network or over an IPC mechanism. A connection is typically between a client process and either a dedicated server or a dispatcher. However,using Oracle’s Connection Manager (CMAN), a connection may be between a client and CMAN, and CMAN and the database.
1.2 session
A session is a logical entity that exists in the instance. It is your session state, or a collection of data structures in memory that represents your unique session. It is what would come first to most people’s minds when thinking of a “database connection.” It is your session in the server, where you execute SQL, commit transactions, and run stored procedures.
1.3 connection vs. session
A connection may have zero, one, or more sessions established on it. Each session is separate and independent,even though they all share the same physical connection to the database. A commit in one session does not affect any other session on that connection. In fact, each session using that connection could use different user identities!
In Oracle, a connection is simply a physical circuit between your client process and the database instance—a network connection, most commonly. The connection may be to a dedicated server process or to a dispatcher. As previously stated, a connection may have zero or more sessions, meaning that a connection may exist with no corresponding sessions. Additionally, a session may or may not have a connection. Using advanced Oracle Net features such as connection pooling, a physical connection may be dropped by a client, leaving the session intact (but idle). When the client wants to perform some operation in that session, it would reestablish the physical connection.
2.示例
SQL> conn seagull/aaaa
Connected.
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
Connected.
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
USERNAME||''||SID||''||SERIAL#||''||SERVER||''||PADDR||''||STATUS
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
SQL> set autotrace on statistics
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
USERNAME||''||SID||''||SERIAL#||''||SERVER||''||PADDR||''||STATUS
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
SEAGULL 142 231 DEDICATED 2A220948 INACTIVE
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
SEAGULL 142 231 DEDICATED 2A220948 INACTIVE
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
596 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
SQL>
從例子可以看到,程式(paddr=2A220948)對應了兩個session(140,142),即我們透過一個dedicated server擁有了兩個sessoin,其實那個inactive的session(142)就是autotrace session,用來watch我們真正的sessoin的,可以知道autotrace在我們發出insert,delete,update,select,merge時會作出一下動作:
1)用當前的connection新建1個new session,當然,如果建立後就不用再建立了
2)然後new session會讀取original session的v$sessstat檢視並記錄統計資訊
3)接著在original session中執行DML
4)執行完畢後,new session會再次讀取original session的v$sessstat資訊,並且把和之前的差別統計出來,顯示給使用者看.
如果關閉autotrace,那麼new session會消失,如下:
SQL> set autotrace off
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
USERNAME||''||SID||''||SERIAL#||''||SERVER||''||PADDR||''||STATUS
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
--------------------------------------------------------------------------------
SEAGULL 140 61 DEDICATED 2A220948 ACTIVE
SQL>
此時在sqlplus中執行disconnect操作:
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
在另外的sqlplus登入介面裡查詢v$session
SQL> select * from v$session where username='SEAGULL';
now rows return
SQL> select addr,pid,spid,terminal,username from v$process where addr='2A220948';
ADDR PID SPID TERMINAL USERNAME
-------- ---------- ------------ ------------------------------ ---------------
2A220948 21 13132 pts/0 oracle10
-------- ---------- ------------ ------------------------------ ---------------
2A220948 21 13132 pts/0 oracle10
發現此時session(sid=140)已經沒有了,但用之前的paddr='2A220948'還能查出資訊,表明connection還在,表明1個connection可以對應0個session.
再次原來的sqlplus裡面執行connect操作:
SQL> connect seagull/aaaa
Connected.
Connected.
查詢v$session
SQL> select username||' '||sid||' '||serial#||' '||server||' '||paddr||' '||status from v$session where username='SEAGULL';
USERNAME||''||SID||''||SERIAL#||''||SERVER||''||PADDR||''||STATUS
--------------------------------------------------------------------------------
SEAGULL 146 103 DEDICATED 2A220948 ACTIVE
--------------------------------------------------------------------------------
SEAGULL 146 103 DEDICATED 2A220948 ACTIVE
發現1個new session在原來的connection(paddr=2A220948)基礎上又被建立了。
[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9533994/viewspace-1005832/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- session和cookie關係SessionCookie
- Cookie 和 Session 關係和區別CookieSession
- http中session和cookie的區別和關係HTTPSessionCookie
- Cookie與Session 關係CookieSession
- 如何區分 Connection、Thread和SessionthreadSession
- 理解cookie、session、localStorage、sessionStorage的關係與區別CookieSession
- keycloak~關於session idle和session max的解釋Session
- 關於Session和CookieSessionCookie
- jre 和 jdk的關係JDK
- @SpringBootApplication和@SpringBootConfiguration的關係Spring BootAPP
- PassEncoder和Pipeline的關係
- ThymeleafViewResolver和SpringTemplateEngine和SpringResourceTemplateResolver的關係ViewSpring
- 程式和產品的關係
- flink jobmanager和taskmanager的關係
- 矩陣:橫向關係和縱向關係矩陣
- ascp: Failed to open TCP connection for SSH, exiting. Session Stop (Error: Failed to open TCP connection for SSH)AITCPSessionError
- 關於Cookie、session和Web StorageCookieSessionWeb
- iOS 中 UIView 和 CALayer 的關係iOSUIView
- repo和Git的關係 [轉載]Git
- IP地址和MAC地址的關係Mac
- cmsis和各種庫的關係
- HomeAssistantOS和docker的組織關係Docker
- 談談 JDK 和 SAPMachine 的關係JDKMac
- Python和人工智慧的關係Python人工智慧
- 關於Residual Connection
- 關係型資料庫和非關係型資料庫的區別資料庫
- NIO中SelectionKey和Channel、Selector的關係
- 徹底搞懂Object和Function的關係ObjectFunction
- 理解JavaScript中BOM和DOM的關係JavaScript
- 【轉】QPS和併發數的關係
- Docker——理解好映象和容器的關係Docker
- ERP和MES:互補的夥伴關係
- 聊聊人工智慧和Python的關係人工智慧Python
- Window, WindowManager和WindowManagerService之間的關係
- Angular Ngrx 裡 Store 和 State 的關係Angular
- js中__proto__和prototype的關係JS
- 網站和伺服器的關係網站伺服器
- WebGL和OpenGL的區別及關係Web
- 列舉常見的關係型資料庫和非關係型都有那些?資料庫