参考:官方文档
什么是连接、会话和进程
connection(连接):
A connection is a physical communication pathway between a client process and a database instance. A communication pathway is established using available interprocess communication mechanisms or network software. Typically, a connection occurs between a client process and a server process or dispatcher, but it can also occur between a client process and Oracle Connection Manager (CMAN).
用户进程到服务器进程的一个物理通道。
processs(进程):
A process is a mechanism in an operating system that can run a series of steps. The mechanism depends on the operating system. For example, on Linux an Oracle background process is a Linux process. On Windows, an Oracle background process is a thread of execution within a process。
进程是操作系统,对于oracle来说分为客户端进程和服务进程。
session(会话):
A session is a logical entity in the database instance memory that represents the state of a current user login to a database. For example, when a user is authenticated by the database with a password, a session is established for this user. A session lasts from the time the user is authenticated by the database until the time the user disconnects or exits the database application.
会话是实例中存在的一个逻辑结构。这就是你的会话状态,也就是表示特定会话的一组内存 中的数据结构。
连接和会话的关系
1.一个connection 可以有0个会话,1个会话和多个会话:
一个连接0个会话:当数据库没启动,可以连接,但是没有会话。
窗口1查询
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
disconnect 只是中断了session,连接还在
窗口2:
SQL> select t.USERNAME,t.STATUS,t.SID,t.SERIAL# from v$session t where t.USERNAME= 'STUDY';
no rows selected
SQL>
2.一个连接一个session
窗口1:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
窗口2:
SQL> select t.USERNAME,t.STATUS,t.SID,t.SERIAL# from v$session t where t.USERNAME= 'STUDY';
USERNAME STATUS SID SERIAL#
------------------------------------------------------------------------------------------ ------------------------ ---------- ----------
STUDY INACTIVE 8 269
SQL>
3.一个连接多个会话
窗口1:
SQL> set autot on
SQL> select 1 from dual;
1
----------
1
窗口2:
SQL> select t.USERNAME,t.STATUS,t.SID,t.SERIAL# from v$session t where t.USERNAME= 'STUDY';
USERNAME STATUS SID SERIAL#
------------------------------------------------------------------------------------------ ------------------------ ---------- ----------
STUDY INACTIVE 8 273
STUDY INACTIVE 9 409