oracle session connection,session connection 关系介绍

本文详细介绍了数据库中的Session和Connection的概念及其相互关系。一个Session可以对应一个或多个Connection,而一个Connection也可以服务于一个或多个Session,这种关系在Oracle数据库中表现为多对多。通过SQL查询示例展示了从一对一到多对一的Session和Connection的对应情况,揭示了两者在网络通信和数据库操作中的动态变化。
摘要由CSDN通过智能技术生成

经常看到网上关于sessions和connection之间的关系,这里总结一下,方便以后查阅。

一个session可以有一个connection,可以有两个connection,或多个,这种情况只有在share server 模式中才会出现

同样一个connection同样可以有一个session或多少.

所以session和connection之间的关系是多对多之间的关系(当然包一对一)

那到底 session和connection是指什么。

这里引用tom大师的话:

一个connection是一条物理路径从客户端到数据库实例,它是建立在网络或IPC的基础上。

一个session是指一个逻辑单元存在于数据库实例,它可以标识SQL执行,内存分配数据集合等信息。

先看看一对一的情况吧:

C:\Users\Administrator>sqlplus  /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Wed Jan 8 10:25:51 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

SQL> conn / as sysdba

Connected.

SQL> select paddr from v$session where username=user;

PADDR

----------------

000007FF5E315D90

SQL> select count(*) from v$process where addr=hextoraw('000007FF5E315D90');

COUNT(*)

----------

1

两个session对应一个connection的情况:

SQL> set autotrace on;

SQL> select paddr,username from v$session where username=user;

PADDR            USERNAME

---------------- ------------------------------

000007FF5E315D90 SYS

000007FF5E315D90 SYS

看到查询结果有两条记录,对应同一个paddr。0个session对应一个connection

这里开启两个窗口

窗口1:

C:\Users\Administrator>sqlplus  /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Wed Jan 8 10:25:51 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

SQL> conn / as sysdba

Connected.

SQL> select paddr from v$session where username=user;

PADDR

----------------

000007FF5E315D90

SQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> disconnect

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64

bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

窗口2:

C:\Users\Administrator>sqlplus  /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Wed Jan 8 10:25:51 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

SQL> conn / as sysdba

Connected.

SQL> select count(*) from v$process where addr=hextoraw('000007FF5E315D90');

COUNT(*)

----------

1

虽然窗口1disconnect,但它的connection并没有关,在窗口2中依然可以查到connection.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值