首页 > Linux操作系统 > Linux操作系统 > 进程、会话、连接之间的差异
2. 单个连接,单个会话,单个进程-->没有建立建立连接时,没有任何会话服务器进程 [oracle@odbp ~]$ ps -ef | grep oracleorcl oracle 5685 5446 0 19:30 pts/1 00:00:00 grep oracleorcl [oracle@odbp ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jun 27 19:30:49 2011 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. idle> ho ps -ef | grep oracleorcl -->使用nolog登录是同样也看不到任何会话服务器进程 oracle 5691 5686 0 19:31 pts/0 00:00:00 /bin/bash -c ps -ef | grep oracleorcl
- -->没有建立建立连接时,没有任何会话服务器进程
- [oracle@odbp ~]$ ps -ef | grep oracleorcl
- oracle 5685 5446 0 19:30 pts/1 00:00:00 grep oracleorcl
- [oracle@odbp ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jun 27 19:30:49 2011
- Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
- idle> ho ps -ef | grep oracleorcl -->使用nolog登录是同样也看不到任何会话服务器进程
- oracle 5691 5686 0 19:31 pts/0 00:00:00 /bin/bash -c ps -ef | grep oracleorcl
3. 无连接,无会话,单个进程-->使用scott身份登录,有一个对应的服务器进程被产生 idle> conn scott/tiger Connected. scott@ORCL> select sid,serial#,username from v$session where username is not null; SID SERIAL# USERNAME ---------- ---------- ------------------------- 159 5 SCOTT scott@SQL> ho ps -ef | grep oracleorcl oracle 5696 5686 0 19:32 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 5699 5686 0 19:32 pts/0 00:00:00 /bin/bash -c ps -ef | grep oracleorcl
- -->使用scott身份登录,有一个对应的服务器进程被产生
- idle> conn scott/tiger
- Connected.
- scott@ORCL> select sid,serial#,username from v$session where username is not null;
- SID SERIAL# USERNAME
- ---------- ---------- -------------------------
- 159 5 SCOTT
- scott@SQL> ho ps -ef | grep oracleorcl
- oracle 5696 5686 0 19:32 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
- oracle 5699 5686 0 19:32 pts/0 00:00:00 /bin/bash -c ps -ef | grep oracleorcl
4. 单个连接,多个会话,单个进程-->使用disconnect断开会话,但对应的服务器进程并没有撤销,直到使用exit则对应的服务器进程被释放 scott@SQL> disconnect Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options -->此时开启另外一个会话session2来查看scott的会话是否还存在,从下面的查询中已经不存在scott用户的会话 sys@ORCL> select sid,serial#,username from v$session where username='SCOTT'; no rows selected scott@SQL> ho ps -ef | grep 5696 -->对应的后台进程依然存在 oracle 5696 5686 0 19:32 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 5702 5686 0 19:32 pts/0 00:00:00 /bin/bash -c ps -ef | grep 5696 scott@ORCL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@odbp admin]$ ps -ef | grep 5696 -->exit命令退出后则相应的进程5696被释放 oracle 4082 16943 0 19:45 pts/0 00:00:00 grep 5696
- -->使用disconnect断开会话,但对应的服务器进程并没有撤销,直到使用exit则对应的服务器进程被释放
- scott@SQL> disconnect
- Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- -->此时开启另外一个会话session2来查看scott的会话是否还存在,从下面的查询中已经不存在scott用户的会话
- sys@ORCL> select sid,serial#,username from v$session where username='SCOTT';
- no rows selected
- scott@SQL> ho ps -ef | grep 5696 -->对应的后台进程依然存在
- oracle 5696 5686 0 19:32 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
- oracle 5702 5686 0 19:32 pts/0 00:00:00 /bin/bash -c ps -ef | grep 5696
- scott@ORCL> exit
- Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- [oracle@odbp admin]$ ps -ef | grep 5696 -->exit命令退出后则相应的进程5696被释放
- oracle 4082 16943 0 19:45 pts/0 00:00:00 grep 5696
set autotrace 完成的动作-->从视图中观察对应的session与后台进程 -->在session1中使用scott登录 idle> conn scott/tiger; Connected. -->在session2 中使用sys帐户登录 sys@ORCL> select sid,serial#,username from v$session where username is not null; SID SERIAL# USERNAME ---------- ---------- ------------------------------ 141 4 SYS 159 5 SCOTT -->在session1中开启autotrace功能 scott@ORCL> set autotrace on -->可以看到在session2的v$session视图查询时多出了一个账户为scott,但SID与SERIAL#与之前不同的记录 sys@ORCL> set linesize 160 sys@ORCL> SELECT spid, s.sid, s.serial#,s.status,s.username, p.program 2 FROM v$process p, v$session s 3 WHERE p.addr = s.paddr 4 and s.username='SCOTT'; SPID SID SERIAL# STATUS USERNAME PROGRAM ------------ ---------- ---------- -------- ------------------------- -------------------------------------- 4602 159 5 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3) 4602 139 25 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3) sys@ORCL> ho ps -ef | grep 4602 oracle 4602 4499 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 4856 4655 0 18:47 pts/3 00:00:00 /bin/bash -c ps -ef | grep 4602 sys@ORCL> ho ps -ef | grep oracleorcl oracle 4602 4499 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 4656 4655 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 4859 4655 0 18:47 pts/3 00:00:00 /bin/bash -c ps -ef | grep oracleorcl -->从上面的查询结果可以看出,SCOTT用户对应的后台进程仅有一个,其spid为4062
- -->从视图中观察对应的session与后台进程
- -->在session1中使用scott登录
- idle> conn scott/tiger;
- Connected.
- -->在session2 中使用sys帐户登录
- sys@ORCL> select sid,serial#,username from v$session where username is not null;
- SID SERIAL# USERNAME
- ---------- ---------- ------------------------------
- 141 4 SYS
- 159 5 SCOTT
- -->在session1中开启autotrace功能
- scott@ORCL> set autotrace on
- -->可以看到在session2的v$session视图查询时多出了一个账户为scott,但SID与SERIAL#与之前不同的记录
- sys@ORCL> set linesize 160
- sys@ORCL> SELECT spid, s.sid, s.serial#,s.status,s.username, p.program
- 2 FROM v$process p, v$session s
- 3 WHERE p.addr = s.paddr
- 4 and s.username='SCOTT';
- SPID SID SERIAL# STATUS USERNAME PROGRAM
- ------------ ---------- ---------- -------- ------------------------- --------------------------------------
- 4602 159 5 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3)
- 4602 139 25 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3)
- sys@ORCL> ho ps -ef | grep 4602
- oracle 4602 4499 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
- oracle 4856 4655 0 18:47 pts/3 00:00:00 /bin/bash -c ps -ef | grep 4602
- sys@ORCL> ho ps -ef | grep oracleorcl
- oracle 4602 4499 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
- oracle 4656 4655 0 18:36 ? 00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
- oracle 4859 4655 0 18:47 pts/3 00:00:00 /bin/bash -c ps -ef | grep oracleorcl
- -->从上面的查询结果可以看出,SCOTT用户对应的后台进程仅有一个,其spid为4062
有关启用set autotrace 请参考:启用 AUTOTRACE 功能当启用set autotrace功能后,通常会创建一个新的会话用于监控当前的操作并返回统计信息,下面描述其过程 a.在session1执行一个查询,则此时原来创建的会话(159,5)执行DML或DQL操作 b.新创建的会话(139,25)会话则开始查询V$SESSTAT 视图来记住实际会话(即运行DML 的会话)的初始统计值 c.原会话(139,25)中得DML或DQL操作执行 d.新会话(139,25)将再次查询V$SESSTAT 视图,根据与上次的差值计算统计信息并生成执行时的执行计划以及统计信息予以返回
- 当启用set autotrace功能后,通常会创建一个新的会话用于监控当前的操作并返回统计信息,下面描述其过程
- a.在session1执行一个查询,则此时原来创建的会话(159,5)执行DML或DQL操作
- b.新创建的会话(139,25)会话则开始查询V$SESSTAT 视图来记住实际会话(即运行DML 的会话)的初始统计值
- c.原会话(139,25)中得DML或DQL操作执行
- d.新会话(139,25)将再次查询V$SESSTAT 视图,根据与上次的差值计算统计信息并生成执行时的执行计划以及统计信息予以返回
5.SID不变,serial#变化的情形-->下面演示在session1中的查询 scott@ORCL> select count(1) from emp; COUNT(1) ---------- 14 Execution Plan ---------------------------------------------------------- Plan hash value: 2937609675 ------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | | | | 2 | INDEX FULL SCAN| PK_EMP | 14 | 1 (0)| 00:00:01 | ------------------------------------------------------------------- Statistics ---------------------------------------------------------- 296 recursive calls 0 db block gets 54 consistent gets 1 physical reads 0 redo size 411 bytes sent via SQL*Net to client 385 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 6 sorts (memory) 0 sorts (disk) 1 rows processed scott@ORCL> set autotrace off; -->在session2中再次执行查询,可以看到会话139,25已经被释放 sys@ORCL> / SPID SID SERIAL# STATUS USERNAME PROGRAM ------------ ---------- ---------- -------- ------------------------- -------------------------------------- 4602 159 5 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3)
- -->下面演示在session1中的查询
- scott@ORCL> select count(1) from emp;
- COUNT(1)
- ----------
- 14
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 2937609675
- -------------------------------------------------------------------
- | Id | Operation | Name | Rows | Cost (%CPU)| Time |
- -------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
- | 1 | SORT AGGREGATE | | 1 | | |
- | 2 | INDEX FULL SCAN| PK_EMP | 14 | 1 (0)| 00:00:01 |
- -------------------------------------------------------------------
- Statistics
- ----------------------------------------------------------
- 296 recursive calls
- 0 db block gets
- 54 consistent gets
- 1 physical reads
- 0 redo size
- 411 bytes sent via SQL*Net to client
- 385 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 6 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- scott@ORCL> set autotrace off;
- -->在session2中再次执行查询,可以看到会话139,25已经被释放
- sys@ORCL> /
- SPID SID SERIAL# STATUS USERNAME PROGRAM
- ------------ ---------- ---------- -------- ------------------------- --------------------------------------
- 4602 159 5 INACTIVE SCOTT oracle@oradb.robinson.com (TNS V1-V3)
有关kill session的说明,请参考:Oracle 彻底 kill session-->将所有的会话全部退出,下面来查看SID不变而serial#变化的情形 [oracle@oradb ~]$ ps -ef | grep oracleorcl -->此时Oracle数据库无任何服务器进程 oracle 26767 16943 0 19:49 pts/0 00:00:00 grep oracleorcl [oracle@oradb ~]$ sqlplus scott/tiger@orcl Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP and Data Mining options scott@ORCL> select sid,serial#,username from v$session where username='SCOTT'; SID SERIAL# USERNAME ---------- ---------- ------------------------------ 134 39 SCOTT scott@ORCL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP and Data Mining options [uniread] Saved history (652 lines) [oracle@oradb ~]$ sqlplus scott/tiger@orcl Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP and Data Mining options scott@ORCL> select sid,serial#,username from v$session where username='SCOTT'; SID SERIAL# USERNAME ---------- ---------- ------------------------------ 134 41 SCOTT -->从上面的情形可以看出尽管scott用户退出后重新登录,依然使用了相同的SID,因此在执行kill session时,一定要注意SID,serial# -->两者的值,以免kill掉不该kill的session
- -->将所有的会话全部退出,下面来查看SID不变而serial#变化的情形
- [oracle@oradb ~]$ ps -ef | grep oracleorcl -->此时Oracle数据库无任何服务器进程
- oracle 26767 16943 0 19:49 pts/0 00:00:00 grep oracleorcl
- [oracle@oradb ~]$ sqlplus scott/tiger@orcl
- Connected to:
- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
- With the Partitioning, OLAP and Data Mining options
- scott@ORCL> select sid,serial#,username from v$session where username='SCOTT';
- SID SERIAL# USERNAME
- ---------- ---------- ------------------------------
- 134 39 SCOTT
- scott@ORCL> exit
- Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
- With the Partitioning, OLAP and Data Mining options
- [uniread] Saved history (652 lines)
- [oracle@oradb ~]$ sqlplus scott/tiger@orcl
- Connected to:
- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
- With the Partitioning, OLAP and Data Mining options
- scott@ORCL> select sid,serial#,username from v$session where username='SCOTT';
- SID SERIAL# USERNAME
- ---------- ---------- ------------------------------
- 134 41 SCOTT
- -->从上面的情形可以看出尽管scott用户退出后重新登录,依然使用了相同的SID,因此在执行kill session时,一定要注意SID,serial#
- -->两者的值,以免kill掉不该kill的session
- -->如在下面的系统的设置中processes得值为150,session的值设定为170,
- scott@ORCL> select name,value from v$parameter where name='processes';
- NAME VALUE
- -------------------- --------------------
- processes 150
- scott@ORCL> select name,value from v$parameter where name='sessions';
- NAME VALUE
- -------------------- --------------------
- sessions 170
- scott@ORCL> select 150*1.1+5 from dual;
- 150*1.1+5
- ----------
- 170
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22578826/viewspace-703462/ ,如需转载,请注明出处,否则将追究法律责任。