ORACLE的连接模式专用服务器和共享服务器
1.综述 ORACLE数据存在两种连接模式,一种是一个会话建立一个连接的专用服务器模式;另外一种是多个会话共用一个连接的共享服务器模式。在不同的场景中,恰当的运用可以极大的提高应用访问效率和命令执行效率。 2.专用服务器 专用服务器,顾名思义,就是指该
1.综述
ORACLE数据存在两种连接模式,一种是一个会话建立一个连接的专用服务器模式;另外一种是多个会话共用一个连接的共享服务器模式。在不同的场景中,恰当的运用可以极大的提高应用访问效率和命令执行效率。
2.专用服务器
专用服务器,顾名思义,就是指该服务器连接只提供单个用户使用,不得与其他用户共用。当用户采取专用服务器方式请求连接时,服务器会专门为该用户创建一个连接进程提供服务。
当我们进行专用服务器方式连接数据库时,则会创建一个专门的进程来提供服务:
然后,我们通过pl/sql developer用 scott用户与实例建立两个专用服务器连接,再次查询数据库实例进程:
可以发现实例多了两个会话进程,从而得出实例为每个会话分配一个专门进程,会话与专用服务器一一对应。
专用服务器的原理图如下所示:
当用户登录时,总会创建一个进程来为会话提供专门的服务。每当一个新会话建立,监听程序会创建新的专用服务器来提供专门服务,会话与专门服务器一一对应。用户的客户进程会通过某种网络通道与专门服务器直接通信,来响应我们提交的SQL、PL/SQL调用。
3.共享服务器
共享服务器,可以理解为类似连接池原理,有众多的会话,但可供使用的连接数一定,通过资源调度来动态管理会话与实例建立连接,这些连接供所有的会话共享,可以有效的减少资源负载。
共享服务器的原理如下图所示:
由于共享服务器进程的共享,需要在客户进程与共享服务器通信之间建立一种调度机制——调度程序,来保障调度的有效性。用户提出连接请求,监听器接收到连接请求后,会从可调用的调度程序中选择一个,将连接端口等信息返回给用户,调度程序在相应的端口等待,客户进程将于该调度程序进行连接。与调度程序连接后,将用户请求转入SGA的请求队列中,第一个空闲的共享服务器会得到这个请求,并进行处理。待处理完成,共享服务器会将结果放在响应的队列中。调度程序一致在监听响应队列,一旦发现有结果了,就会把结果传给用户。
4. 使用场景
专用服务器与共享服务器的主要区别:
客户进程不会与共享服务器直接通信,而可以与专用服务器直接通信。在客户进程与共享服务器之间还有一层调度机制。
共享服务器方式比专用服务器方式能够更好的分配资源,均衡负载,但是调度机制在使用过程中对系统资源有一定的消耗,执行效率有所下降,所以需要慎重使用方式。
专用服务器使用环境:
1. 连接用户数少的情况下,并不超出共享进程的限定数,提高了连接效率。
2. 数据库为了实现数据仓库,则必须使用专用服务器,oracle的强制要求。
3. 当联机事务处理系统满足用户连接数大于共享进程的限定数,且处理的事务都是大,则专用服务相对于共享服务器更高效。
共享服务器使用环境:
1. 连接用户数比较多,事务都比较小,则共享服务器可以高效的配置资源调高效率。
2. 服务器内存的考虑,共享服务器可以再有效的资源下更加高效。
3. 例如:负载均衡等特性要求采用共享服务器。
ORACLE默认推荐使用的是专用服务器方式,而共享服务器带了优势:
1. 操作系统进程数减少,减少操作系统上下文切换的资源消耗,提高效率。
2. 有效的限制并发度,即将系统消耗现在一个合理的范围。
这两种模式有利有弊需要视情况使用。
5. 服务器模式设置
5.1 专用服务器
专用服务器这是ORACLE的默认启动选项,不需要额外的设置。
5.2 共享服务器
1.参数:SHARED_SERVERS
SHARED_SERVERS的值大于0,表示启动了共享模式。
共享服务器个数:
alter systemset shared_servers = 1 scope=both ;
最大共享服务器个数:
alter systemset max_shared_servers = 5 scope=both ;
2.参数:DISPATCHERS
alter systemset dispatchers=’ (PROTOCOL=TCP) (SERVICE=zrgXDB) ‘;
ORACLE文档上指出该参数为可选项,如果不配置将匹配任何协议和服务。但在测试将参数设置为控制,进行登录时,显示失败。
PROTOCOL表示连接的协议。
SERVICE表示允许共享服务器的服务。
3.在客户端的tnsnames.ora 的tns设置中,在 CONNECT_DATA 设置中将SERVER 的值 DEDICATED改为SHARED,即可使用共享服务器连接。
5.3 TNS配置在客户端的TNS中配置如下:
根据监听器状态,服务zrgXDB.zrg.com可以配置共享服务器连接:
DBZRG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.199.134)(PORT = 1521))
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = zrgXDB.zrg.com)
)
)
如果我们将SERVICE_NAME改为orcl.zrg.com或pdbzrg.zrg.com,则会出现ORA-12520: TNS: 监听程序无法找到需要的服务器类型的可用句柄。
而专用服务器的连接可以配置为:
DBZRG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.199.134)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = zrgXDB.zrg.com)
)
)
专用服务器模式是数据库默认支持的所以无需配置,而共享服务器需要配置开启的,支持共享服务器模式的,也可以进行专用服务器模式连接。
我们也可以将SERVICE_NAME改用SID=epps代替,epps作为连接的实例,存在服务使用共享服务器,可以建立共享服务器连接,同时也可以建立专用服务器连接。
6. 服务器模式判断
判断当前是否启动了共享服务器可以从以下视图入手:
1. V$session
可以看到我用PL/SQL DEVELOPER与实例建立了共享服务器方式:SERVER类型为SHARED,如果为NONE也表示了启用了共享服务器。还可以发现系统后台进程全部启动了专用服务器进程。
2. V$shared_server
启动共享服务器:
关闭共享服务器:
需要将已经建立的共享服务器的会话结束,该参数才会发生变化。
3. V$circuit
有查询结果则表示启用了共享模式,否则不能做出判断。
4. 查看监听器状态
从以上信息,我们看到有一个服务zrgXDB.zrg.com使用的是共享服务器,有一个调度器“D000”;还有两个服务orcl.zrg.com,pdbzrg.zrg.com使用的是专用服务器。
7. 关闭共享服务器模式
将参数shared_servers的值设置为0,就可以禁用共享服务器模式了。
命令如下:
alter systemset shared_servers = 0 ;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

Oracle uses the "||" symbol to concatenate strings. The usage method is as follows: connect the strings to be connected with the "||" symbol; the priority of string connection is low, and parentheses need to be used to ensure the priority; an empty string will still be an empty string after connection; NULL value connection is still NULL.
