kcbzps oracle_Oracle 11g DRCP配置与使用(上)
Oracle 11g推出了駐留連接池(Database Resident Connection Pool)特性,提供了數據庫層面上的連接池管理機制,為應對高并發、短會話前端應用進行有益的嘗試。
DRCP的配置很簡單,本篇中讓我們一起來配置一個11g環境上的DRCP,分析其工作特性。
1、Database Level Configuration
配置DRCP是分為兩個步驟:database level configuration和application level configuration。首先在Database Server層面創建連接池對象。我們使用Oracle 11g進行試驗。
SQL> select * from v$version;
BANNER
---------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE11.2.0.1.0Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0–Production
在默認情況下,Oracle 11g中是有一個默認的連接池對象。在視圖dba_cpool_info中,可以看到連接池信息。
SQL> select connection_pool, status, minsize, maxsize, INACTIVITY_TIMEOUT from dba_cpool_info;
CONNECTION_POOLSTATUSMINSIZEMAXSIZE INACTIVITY_TIMEOUT
------------------------------ ---------------- ---------- ---------- ------------------
SYS_DEFAULT_CONNECTION_POOLINACTIVE440300
連接池sys_default_connection_pool就是默認連接池,狀態是inactive。使用dbms_connection_pool包,可以方便的對其進行管理。
SQL> exec dbms_connection_pool.start_pool();
PL/SQL procedure successfully completed
使用start_pool方法,可以對默認池進行開啟。注意:該方法還有參數pool_name,如果指定了名稱,就可以創建出一個自定義的連接池,也可以同時管理多個連接池情況。如果不指定名稱,就針對默認連接池進行管理。
Start_pool之后,dba_cpool_info視圖中可以看到連接池狀態。
SQL> select connection_pool, status from dba_cpool_info;
CONNECTION_POOLSTATUSMINSIZE
------------------------------ ---------------- ----------
SYS_DEFAULT_CONNECTION_POOLACTIVE4
注意,此時沒有連接,但是我們觀察后臺進程,發現新增加了連接池Server Process對象。
[oracle@oracle11g ~]$ ps -ef | grep ora_n
oracle580011 05:07 ?00:00:00 ora_n000_wilson
oracle581655840 05:07 pts/000:00:00 grep ora_n
[oracle@oracle11g ~]$ ps -ef | grep ora_l
oracle568910 05:03 ?00:00:00 ora_lgwr_wilson
oracle580210 05:07 ?00:00:00ora_l000_wilson
oracle580410 05:07 ?00:00:00 ora_l001_wilson
oracle580610 05:07 ?00:00:00 ora_l002_wilson
oracle580810 05:07 ?00:00:00 ora_l003_wilson
oracle581855840 05:07 pts/000:00:00 grep ora_l
其中ora_n000進程是對應的Connection Broker對象,負責連接管理。Ora_lxxx進程就是連接池中的連接對象。當沒有連接的時候,連接池維持minsize大小,與配置minsize=4相匹配。
下面進行application level configuration。
2、Application Level Configuration
在應用層面,可以從連接字符串或者本地服務名上進行配置。本篇主要從本地服務名上進行配置。
在tnsnames.ora中,我們可以進行本地命名配置。為了保證正確性,筆者傾向使用Oracle提供的netca工具來進行基礎配置。
--開啟X Windows Passive模式
[oracle@oracle11g ~]$ export DISPLAY=192.168.0.1:0.0
[oracle@oracle11g ~]$ netca
Oracle Net Services Configuration:
Default local naming configuration complete.
Created net service name: wilsondrcp
Oracle Net Services configuration successful. The exit code is 0
之后,修改tnsname.ora文件的相關內容。
WILSONDRCP=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.88)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = POOLED) --新增加到其中,表明連接使用連接池;
(SERVICE_NAME = wilson)
)
)
可以使用tnsping方法進行驗證。
[oracle@oracle11g ~]$ tnsping wilsondrcp
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 01-MAR-2012 05:10:46
Copyright (c) 1997, 2009, Oracle.All rights reserved.
Used parameter files:
/u01/oracle/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.88)(PORT = 1521))) (CONNECT_DATA =(SERVER = POOLED)(SERVICE_NAME = wilson)))
OK (0 msec)
配置了wilsondrcp名稱之后,就可以使用sqlplus等工具進行連接。
[oracle@oracle11g ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 1 05:11:47 2012
Copyright (c) 1982, 2009, Oracle.All rights reserved.
SQL> conn scott/tiger@wilsondrcp
Connected.
SQL> select sid from v$mystat where rownum<2;
SID
----------
146
此時,會話(sid=146)已經連接。此時,我們可以查看后臺進程情況。
--標記LOCAL的本地連接進程不存在;
[oracle@oracle11g ~]$ ps -ef | grep LOCAL
oracle596359310 05:14 pts/100:00:00 grep LOCAL
那么,我們連接的會話進程究竟是哪一個呢?
SQL> select paddr from v$session where sid=146;
PADDR
--------
38BCD994
SQL> select pid, spid from v$process where addr='38BCD994';
PID SPID
---------- ------------------------
31 5806–OS Level的進程編號;
[oracle@oracle11g ~]$ ps -ef | grep 5806
oracle580610 05:07 ?00:00:00 ora_l002_wilson
oracle597559310 05:15 pts/100:00:00 grep 5806
對應的ora_l002_wilson進程就是我們剛剛看到的連接池進程。說明:我們使用sqlplus連接使用的連接池對象是通過DRCP。
在sqlplus退出之后,l002進程依然存在,只是被釋放回連接池。
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@oracle11g ~]$ ps -ef | grep 5806
oracle580610 05:07 ?00:00:00 ora_l002_wilson
oracle598159310 05:15 pts/100:00:00 grep 5806
[oracle@oracle11g ~]$
3、連接池關閉
DRCP連接池是可以關閉的,同樣使用dbms_connection_pool的stop_pool方法。
--關閉connection pool
SQL> exec dbms_connection_pool.stop_pool;
PL/SQL procedure successfully completed
[oracle@oracle11g ~]$ ps -ef | grep ora_n
oracle580010 05:07 ?00:00:00 ora_n000_wilson
oracle600859310 05:18 pts/100:00:00 grep ora_n
[oracle@oracle11g ~]$ ps -ef | grep ora_l
oracle568910 05:03 ?00:00:00 ora_lgwr_wilson
oracle601059310 05:18 pts/100:00:00 grep ora_l
關閉連接池后,連接池中連接lxxx立即被銷毀釋放。Connection Broker進程暫時存在。但是,過一會之后,該進程消失。
[oracle@oracle11g ~]$ ps -ef | grep ora_n
oracle602759310 05:22 pts/100:00:00 grep ora_n
本篇中,我們一起進行了Oracle DRCP啟動關閉,以及對應的后臺Server Process情況。下篇中,我們一起來分析如何進行配置DRCP各種參數。
總結
以上是生活随笔為你收集整理的kcbzps oracle_Oracle 11g DRCP配置与使用(上)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 管理 mysql 数据库 代码_
- 下一篇: android 使用Binder通信