欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

【用户连接】

程序员文章站 2022-06-13 13:46:14
...

1.本地连接 SQL conn scott/tiger Connected. SQL select sid,server from v$sessionwhere username=SCOTT; SID SERVER ---------- --------- 42 DEDICATED SQL select sid,server,paddr,processfrom v$session where username=SCOTT; SID SERVER PADDR PROC

1.本地连接

SQL> conn scott/tiger

Connected.

SQL> select sid,server from v$sessionwhere username='SCOTT';

SID SERVER

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

42 DEDICATED

SQL> select sid,server,paddr,processfrom v$session where username='SCOTT';

SID SERVER PADDR PROCESS

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

42 DEDICATED 000000009188D050 16592

--此处的16592标识进程

SQL> conn scott/tiger

Connected.

SQL> ho ps -ef|grep 16592

oracle 16592 16531 0 21:58 pts/1 00:00:00 sqlplus

oracle 16733 16592 0 22:02 ? 00:00:00 oracleorcl(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

–local=yes标识是本地连接,不经过TCP/IP

oracle 16915 16836 0 22:06 pts/2 00:00:00 /bin/bash -c ps -ef|grep 16592

2.远程连接

SQL> select sid,server,paddr,processfrom v$session where username='SCOTT';

SID SERVER PADDR PROCESS

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

42 DEDICATED 000000009188D050 17041

SQL> ho ps -ef|grep 17041

oracle 17041 16531 0 22:11 pts/1 00:00:00 sqlplus

oracle 17131 16836 0 22:14 pts/2 00:00:00 /bin/bash -c ps -ef|grep 17041

远程连接用同本地连接相同的查询方法查不到结果,可以用如下查询:

SQL> select spid from v$process whereaddr='000000009188D050';

SPID

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

17045

SQL> ho ps -ef|grep 17045

oracle 17045 1 0 22:11 ? 00:00:00 oracleorcl (LOCAL=NO)

–local=no 标识远程连接,走TCP/IP

oracle 17180 16836 0 22:15 pts/2 00:00:00 /bin/bash -c ps -ef|grep 17045

3.连接模式

A.专有 每个用户进程与一个服务进程进行连接

适合消耗pga为主业务比如dss、olap、 dba常规管理任务、dg实现同步--dg需要专有连接

SQL> select sid,serial#,server fromv$session where username='SCOTT';

SID SERIAL# SERVER

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

37 236 DEDICATED

SQL> show parameter dispatchers

NAME TYPE VALUE

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

dispatchers string (PROTOCOL=TCP) (SERVICE=orclXDB)

max_dispatchers integer

B.共享 多个用户进程与一个服务器的子进程进行连接

[oracle@oracle ~]$ sqlplusscott/tiger@oracle:1521/orclXDB

SQL> select sid,serial#,server from v$sessionwhere username='SCOTT';

SID SERIAL# SERVER

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

21 536 DEDICATED

27 1008 SHARED ---shared/none 标识共享连接

SQL> select sid,serial#,server,paddrfrom v$session where username='SCOTT';

SID SERIAL# SERVER PADDR

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

27 1008 NONE 0000000091888F50

44 1430 NONE 0000000091888F50

-------注意共享连接不管是多少个,此处的PADDR都是一样的。

SQL> select sid,serial#,server,paddrfrom v$session where username=’SCOTT’;

SID SERIAL# SERVER PADDR

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

21 536 DEDICATED 0000000091892190

44 1433 DEDICATED 0000000091894210

------注意专有连接不管是多少个,每个PADDR都是不一样的。

一个服务器进程可以服务多个用户进程,反之则不成立。

4.连接----物理方式通过协议进行连接

会话----在连接基础上产生的一些信息,可以有一个、可以有多个、可以没有

连接关闭,会话结束

会话结束,连接不一定关闭

会话1:

[oracle@oracle ~]$sqlplus scott/tiger

SQL> set autot trace stat

会话2:

SQL> select sid,serial#,server,paddrfrom v$session where username='SCOTT';

SID SERIAL# SERVER PADDR

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

21 536 DEDICATED 0000000091892190

34 799 DEDICATED 0000000091895250

51 252 DEDICATED 0000000091895250

–--表示在一个连接上产生两个会话

SQL> selectsid,serial#,server,paddr,process from v$session where username='SCOTT';

SID SERIAL# SERVER PADDR PROCESS

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

21 536 DEDICATED 0000000091892190 19652

34 799 DEDICATED 0000000091895250 21284

51 252 DEDICATED 0000000091895250 21284

--–注意PROCESS是相同,即为同一个进程

SQL> select spid from v$process whereaddr=' 0000000091895250';

SPID

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

21287

想要KILL这个会话,可以如下操作:

SQL> alter system kill session '51,252';

alter system kill session '51,252'

*

ERROR at line 1:

ORA-00031: session marked for kill

可能会出现如上的错误,这虽然能终止该会话,但是不能释放相关资源。

SQL> alter system kill session '51,252'immediate;

System altered.

SQL> selectsid,serial#,server,paddr,process from v$session where username='SCOTT';

SID SERIAL# SERVER PADDR PROCESS

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

21 536 DEDICATED 0000000091892190 19652

Kill一个进程只需要执行如下操作:

SQL> selectsid,serial#,server,paddr,process from v$session where username='SCOTT';

SID SERIAL# SERVER PADDR PROCESS

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

21 536 DEDICATED 0000000091892190 19652

27 1094 DEDICATED 000000009188D050 21629

SQL> select spid from v$process whereaddr='000000009188D050';

SPID

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

21632

SQL> ho kill -9 21632

SQL> select sid,serial#,server,paddr,process from v$session whereusername='SCOTT';

SID SERIAL# SERVER PADDR PROCESS

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

21 536 DEDICATED 0000000091892190 19652

27 1094 DEDICATED 000000009188D050 21629

虽然进程被kill了,但是没有退出去,还是能查到,退出之后就查不到了。

http://docs.oracle.com/cd/E11882_01/server.112/e40540/process.htm#CNCPT9840