怎么启用Oracle Shared Server

如题所述

如何启用Oracle Shared Server

在某些应用中共享服务器还是有独特的优势的,从官方描述中可以看到如下优势:
减少实例进程的数目
增加对外服务的用户数目
减少无用或者空闲服务器的进程数目
减少oracle数据库对内存占用和os的开销
实现负载平衡
相对于专有服务器模式,一个比较重要的区别是共享服务器要求使用net services来连接,即使用户经常和服务器进程在同一台机器上也是如此。
但是在某些情况下必须使用专用服务器:比如使用sysdba登陆进行管理操作的时候。
当然,要使用这两种不同的模式,重要的还是在服务器进行配置后还要在客户端的连接串配置有所体现
专用服务器连接---(SERVER = DEDICATED)
共享服务器连接---(SERVER = SHARED)
那么如何配置共享服务器呢?有两个参数是必须的:
DISPATCHERS
SHARED_SERVERS
可选择配置的参数:
MAX_DISPATCHERS
MAX_SHARED_SERVERS
CIRCUITS
SHARED_SERVER_SESSIONS
大部分情况下我们只要修改DISPATCHERS即可,我们先看下默认的专用服务器情况下参数:
[oracle@test ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Aug 14 15:04:26 2012

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

sys@GT10G> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

sys@GT10G> show parameter disp;

NAME TYPE VALUE
------------------------------------ -------- ------------------------------
dispatchers string (PROTOCOL=TCP) (SERVICE=gt10gXDB)
max_dispatchers integer
共享服务器和专用服务器还可以从监听程序的信息体现出来,我们先记录下修改之前的专用服务器的监听状态和信息:
[oracle@test ~]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:03:32

Copyright (c) 1991, 2010, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 14-AUG-2012 14:52:08
Uptime 0 days 0 hr. 11 min. 24 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/10g/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/oracle/10g/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
The command completed successfully

[oracle@test ~]$ lsnrctl service

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:03:39

Copyright (c) 1991, 2010, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"D002" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 18635>
(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=47446))
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully

现在我们要设置一下共享服务器,这里我们只要设置DISPATCHERS参数:
sys@GT10G> alter system set DISPATCHERS = "(PROTOCOL=TCP)(DISPATCHERS=3)(PROTOCOL=IPC)(DISPATCHERS=1)";

System altered.

我们首先从监听状态和信息来看下前后的不同:
[oracle@test ~]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:07:37

Copyright (c) 1991, 2010, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 14-AUG-2012 14:52:08
Uptime 0 days 0 hr. 15 min. 28 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/10g/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/oracle/10g/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
The command completed successfully

[oracle@test ~]$ lsnrctl service

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 14-AUG-2012 15:09:22

Copyright (c) 1991, 2010, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "gt10g" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 19006>
(ADDRESS=(PROTOCOL=ipc)(KEY=#19006.1))
Service "gt10gXDB" has 1 instance(s).
Instance "gt10g", status READY, has 1 handler(s) for this service...
Handler(s):
"D002" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 18635>
(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=47446))
Service "gt10g_XPT" has 1 instance(s).
Instance "gt10g", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: test, pid: 19006>
(ADDRESS=(PROTOCOL=ipc)(KEY=#19006.1))
The command completed successfully

比较下可以看到最大的变化就是共享服务器在监听信息中体现出了调度进程"D000"。
接下来我们通过修改tnsname配置参数来实际连接,再通过视图可以看到我们已经有一个共享模式连接到服务器了:
GT10G4 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = SHARED) #重点在这里
(SERVICE_NAME = gt10g)
)
)
sys@GT10G> Select Count(*) From V$CIRCUIT;

COUNT(*)
----------
1
那么,如果我们没有配置共享服务模式的参数,但是客户端配置了使用共享模式连接,会是什么结果呢?
alter system set DISPATCHERS="(PROTOCOL=TCP) (SERVICE=gt10gXDB)";
alter system reset DISPATCHERS scope=spfile sid='*';
尝试了上述两条语句发现还是无法恢复内存中的参数值,只好重启数据库,发现还是不行,后来搜索了下发现直接清空即可:
sys@GT10G> alter system set dispatchers='' scope=both;

System altered.

sys@GT10G> show parameter disp;

NAME TYPE VALUE
------------------------------------ -------- ------------------------------
dispatchers string
max_dispatchers integer
这个时候在客户端继续尝试用共享模式连接会发现报错了:
C:\Users\Administrator>sqlplus gtlions/gtlions@gt10g4
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 8月 14 15:41:14 2012

Copyright (c) 1982, 2005, Oracle. All rights reserved.

ERROR:
ORA-12520: TNS: 监听程序无法为请求的服务器类型找到可用的处理程序

-The End-
温馨提示:答案为网友推荐,仅供参考