2:通过参数shared_server判断
如果shared_server值为0,则表示数据库没有启动共享服务模式。 这个参数是配置shared server必须的,而且只有这个参数是必须的。它指定了当实例启动的时候 shared server process 启动的数量,不要将这个参数设置得太大,否者启动数据库instance的时候就会花更多时间,ORACLE启动过后会根据负载来动态调整shared_servers
SQL> show parameter shared_server NAME TYPE VALUE------------------------------------ -------------------------------- ------------------------------max_shared_servers integer 40shared_server_sessions integershared_servers integer 1SQL>
max_shared_servers:oracle在同一个时刻最大能够使用的shared server process.不要将这个参数设置小于shared_servers,如果动态修改shared_servers大于max_shared_servers,oracle会覆盖max_shared_servers的值,此时你需要修改max_shared_servers.同时也不能大于processes。这个参数是为了给占用很大资源操作而设的(批处理),为了预留一些process 给DBA任务(rman备份), shared_server_sesions: 指定了总共允许的的shared server session 的数量。如果设置了这个参数,那么就不要将这个值超过sessions,如果没有设置这个值,那么只要还有空闲的session,就可以被使用。设置这个值是为专用连接预留的User Sessions.
3:通过lsnrctl services区分。
启用了共享服务器模式,可以通过调度器(dipatcher)的进程区分确认。
[oracle@DB-Server ~]$ lsnrctl services; LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 06-JAN-2015 23:46:30 Copyright (c) 1991, 2007, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.16.22)(PORT=1521)))Services Summary...Service "EPPS" has 2 instance(s). Instance "EPPS", status UNKNOWN, has 1 handler(s) for this service... Handler(s): "DEDICATED" established:0 refused:0 LOCAL SERVER Instance "EPPS", status READY, has 8 handler(s) for this service... Handler(s): "D006" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4336> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=10895)) "D005" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4334> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=2469)) "D004" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4332> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=13008)) "D003" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4330> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=17578)) "D002" established:2 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4328> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=44614)) "D001" established:2 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4326> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=32323)) "D000" established:1 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4324> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=22216)) "DEDICATED" established:0 refused:0 state:ready LOCAL SERVERService "EPPS_XPT" has 1 instance(s). Instance "EPPS", status READY, has 8 handler(s) for this service... Handler(s): "D006" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4336> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=10895)) "D005" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4334> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=2469)) "D004" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4332> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=13008)) "D003" established:0 refused:0 current:0 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4330> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=17578)) "D002" established:2 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4328> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=44614)) "D001" established:2 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4326> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=32323)) "D000" established:1 refused:0 current:1 max:1022 state:blocked DISPATCHER <machine: nbooraclelnx01, pid: 4324> (ADDRESS=(PROTOCOL=tcp)(HOST=DB-Server.localhost.localdomain)(PORT=22216)) "DEDICATED" established:0 refused:0 state:ready LOCAL SERVER
没有启用共享服务器模式,则不会有调度器(dipatcher)的进程
[oracle@DB-Server ~]$ lsnrctl services; LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 06-JAN-2015 23:56:25 Copyright (c) 1991, 2007, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.16.22)(PORT=1521)))Services Summary...Service "EPPS" has 1 instance(s). Instance "EPPS", status UNKNOWN, has 1 handler(s) for this service... Handler(s): "DEDICATED" established:0 refused:0 LOCAL SERVERThe command completed successfully
其他一些不能完全确认的判断方式。
select * from v$shared_server; ---有记录,且STATUS字段为WAIT(COMMON),则说明启动共享;
---status为TERMINATED或者无记录,则说明没有启动共享服务器
select * from v$dispatcher; ---有无记录都不能说明启动共享服务器,只能说明是配置了dispatchers参数
select * from v$circuit ; ---有记录说明当前有使用共享模式的连接,无记录则不能判定服务器模式
关闭数据库共享模式
只需要将参数shared_servers设置为0,即可关闭数据库的共享模式。执行该脚本后,所有以共享方式连接到数据库都不能成功,但是未释放的共享连接会继续保持连接,直到断开为止。
alter system set shared_servers=0;
SQL> show parameter shared_servers NAME TYPE VALUE------------------------------------ -------------------------------- --------max_shared_servers integer 40shared_servers integer 4SQL> alter system set shared_servers=0 scope=both; System altered. SQL> alter system set max_shared_servers=0 scope=both; System altered.
开启数据库共享模式
默认情况下,数据库都是专用服务器模式,如何开启共享服务器模式呢? 一般只需要设置shared_servers这个参数,将其值设置为大于0即可开启服务器共享模式。其他的共享服务器参数可以不用设置,但是最好也设置一下max_shared_servers参数
SQL> alter system set shared_servers=1 scope=both; System altered. SQL> alter system set max_shared_servers =24 scope=both; System altered.
但是在实际测试情况中发现,参数dispatchers也会影响到数据库开启共享服务器模式,如下所示,将参数dispatchers设置为空,shared_servers设置为1
SQL> show parameter shared NAME TYPE VALUE------------------------------------ -------------------------------- --------hi_shared_memory_address integer 0max_shared_servers integer 0shared_memory_address integer 0shared_pool_reserved_size big integer 26843545shared_pool_size big integer 0shared_server_sessions integershared_servers integer 0SQL> alter system set dispatchers='' scope=both; System altered. SQL> alter system set shared_servers=1 scope=both; System altered. SQL>
SQL> alter system set dispatchers='(PROTOCOL=TCP)'; System altered.
结论:如果dispatches参数设置为空的话,不能启动共享服务器。
关于参数dispatchers的设置,可以使用下面命令
alter system set dispatchers='(protocol=TCP)(disp=8)(serv=xxx)’
前面表示的是协议,disp表示调度器(dipatcher)的进程数量,service分别指定要采用共享服务器模式的服务名称。使用上面的模式指定只启动某个服务的共享模式,如果要设置所有服务都使用共享模式,则设置为:
alter system set dispatchers='(PROTOCOL=TCP)';
如何判断某个会话采用的那种连接方式呢?
1:查看V$SESSION视图
SELECT SID, USERNAME, OSUSER, MACHINE,TERMINAL, SERVER FROM V$SESSION WHERE USERNAME IS NOT NULL; COL USERNAME FOR A20COL OSUSER FOR A10COL MACHINE FOR A20COL TERMINAL FOR A20;SELECT SID, USERNAME, OSUSER, MACHINE,TERMINAL, SERVER FROM V$SESSION