您的位置:首页 > 数据库 > Oracle

The difference of Connection vs Session in Oracle

2013-09-25 15:39 453 查看
Sometimes it is easy to confuse Oracle connection with Oracle session, but one saying is a connection can have 0, 1 or more sessions, and gives SQL*Plus as example. It is true but for a java developer it is a little hard to get.

It is better to go to official document for reference but not find post/blog to help understand. in Oracle Database Concepts, 10g Release 2 (10.2):

Connections and Sessions

Connection and session are closely related to user process
but are very different in meaning.

A connection is a communication pathway between a user process and an Oracle
instance. A communication pathway is established using available interprocess
communication mechanisms (on a computer that runs both the user process and
Oracle) or network software (when different computers run the database application
and Oracle, and communicate through a network).

A session is a specific connection of a user to an Oracle instance through a user
process.

In configurations without the shared server, Oracle creates a server process on behalf
of each user session. However, with the shared server, many user sessions can share a
single server process.

From this definition, it accentuates that session is also a connection (just specific), and in last paragraph, it mentioned Shared Server and another server process (actually it is Dedicated Server), so the difference is dropped on the difference of server
process. (Shared Server vs Dedicated Server)



Dedicated Server process maintains a one-to-one ratio between the number of user processes and server processes. Even when the user is not actively making a database request, the dedicated server process remains (though it is inactive and can be paged out
on some operating systems). In other words, in this model, one connection corresponds one session.



Abover picture contains two graphs, left is the scenario that the user process and the dedicated server process run on different computers while right is the user process and the dedicated server process run on the same computer,  the communication mechanisms
are different. But each session occupies a connection, one-one-mapping.

Shared server architectureeliminates the need for a dedicated server process for each connection.A dispatcher directs multiple incoming network session requests to a pool of shared server processes.



Once User Process ties Server Process then an Oracle Connection is established. If this connection contains Dedicated Server Process + User Process, then this connection contains only one session. If this connection contains a Shared Server Process + User
Process, due to Shared Server Process can handle many User Process, so this connection can contain many sessions.

There is a Connection as long as a User Process is there, in JDBC, the connection is a session in Oracle. Like J2EE application, if app just finishes a transaction, and no user does any action, then no session, but app is running, it is a User Process which
occupies a Connection. Now this connection has 0 session.

There is another article:session 和connection的不同 is good to read.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Oracle connection session
相关文章推荐