@@ -2884,20 +2884,22 @@ id=GUID-82FF6896-F57E-41CF-89F7-755F3BC9C924>`__.
28842884
28852885Using DRCP with python-oracledb applications involves the following steps:
28862886
2887- 1. Configuring and enabling DRCP in the database
2888- 2. Configuring the application to use a DRCP connection
2889- 3. Deploying the application
2887+ 1. Enabling DRCP in the database
2888+ 2. Configuring the application to use DRCP pooled servers
28902889
28912890Enabling DRCP in Oracle Database
28922891--------------------------------
28932892
2894- Every Oracle Database uses a single, default DRCP connection pool. From Oracle
2895- Database 21c, each pluggable database can optionally have its own pool. Note
2896- that DRCP is already enabled in Oracle Autonomous Database and pool management
2897- is different to the steps below .
2893+ Oracle Database versions prior to 21c can have a single DRCP connection pool.
2894+ From Oracle Database 21c, each pluggable database can optionally have its own
2895+ pool, or can use the container level pool. From Oracle Database 23ai, you can
2896+ create multiple pools at the pluggable, or container, database level .
28982897
2899- DRCP pools can be configured and administered by a DBA using the
2900- ``DBMS_CONNECTION_POOL `` package:
2898+ Note that DRCP is already enabled in Oracle Autonomous Database and pool
2899+ management is different to the steps below.
2900+
2901+ In the basic scenario, DRCP pools can be configured and administered by a DBA
2902+ using the ``DBMS_CONNECTION_POOL `` package:
29012903
29022904.. code-block :: sql
29032905
@@ -2942,13 +2944,14 @@ Otherwise, server processes will continue to use old settings.
29422944There is a ``DBMS_CONNECTION_POOL.RESTORE_DEFAULTS() `` procedure to
29432945reset all values.
29442946
2945- When DRCP is used with RAC, each database instance has its own connection
2946- broker and pool of servers. Each pool has the identical configuration. For
2947- example, all pools start with ``minsize `` server processes. A single
2948- DBMS_CONNECTION_POOL command will alter the pool of each instance at the same
2949- time. The pool needs to be started before connection requests begin. The
2950- command below does this by bringing up the broker, which registers itself with
2951- the database listener:
2947+ When DRCP is used with `Oracle RAC
2948+ <https://www.oracle.com/database/real-application-clusters/> `__, each database
2949+ instance has its own connection broker and pool of servers. Each pool has the
2950+ identical configuration. For example, all pools start with ``minsize `` server
2951+ processes. A single DBMS_CONNECTION_POOL command will alter the pool of each
2952+ instance at the same time. The pool needs to be started before connection
2953+ requests begin. The command below does this by bringing up the broker, which
2954+ registers itself with the database listener:
29522955
29532956.. code-block :: sql
29542957
@@ -2962,29 +2965,46 @@ instance restarts, unless explicitly stopped with the
29622965
29632966 EXECUTE DBMS_CONNECTION_POOL.STOP_POOL()
29642967
2965- The pool cannot be stopped while connections are open.
2968+ Oracle Database 23ai allows a ``DRAINTIME `` argument to be passed to
2969+ ``STOP_POOL() ``, indicating that the pool will only be closed after the
2970+ specified time. This allows in-progress application work to continue. A
2971+ draintime value of 0 can be used to immediately close the pool. See the
2972+ database documentation on `DBMS_CONNECTION_POOL.STOP_POOL()
2973+ <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-3FF5F327-7BE3-4EA8-844F-29554EE00B5F> `__.
2974+
2975+ In older database versions, the pool cannot be stopped while connections are
2976+ open.
29662977
29672978Coding Applications to use DRCP
29682979-------------------------------
29692980
29702981To use DRCP, application connection establishment must request a DRCP pooled
2971- server. The best practice is also to specify a user-chosen connection class
2972- name when creating a connection pool. A 'purity' of the connection session
2973- state can optionally be specified. See the Oracle Database documentation on
2974- ` benefiting from scalability <https://www.oracle.com/pls/topic/lookup?ctx=
2982+ server and should specify a user-chosen connection class name. A 'purity' of
2983+ the connection session state can optionally be specified. See the Oracle
2984+ Database documentation on ` benefiting from scalability
2985+ <https://www.oracle.com/pls/topic/lookup?ctx=
29752986dblatest&id=GUID-661BB906-74D2-4C5D-9C7E-2798F76501B3> `__ for more information
29762987on purity and connection classes.
29772988
2978- Note that when using DRCP with a python-oracledb local :ref: `connection pool
2979- <connpooling>` in Thick mode, the local connection pool ``min `` value is
2980- ignored and the pool will be created with zero connections.
2989+ The best practice is to use DRCP in conjunction with a local driver
2990+ :ref: `connection pool <connpooling >` created with
2991+ :meth: `oracledb.create_pool() ` or :meth: `oracledb.create_pool_async() `. The
2992+ python-oracledb connection pool size does not need to match the DRCP pool size.
2993+ The limit on overall execution parallelism is determined by the DRCP pool
2994+ size. Note that when using DRCP with a python-oracledb local connection pool in
2995+ Thick mode, the local connection pool ``min `` value is ignored and the pool
2996+ will be created with zero connections.
29812997
2982- **Requesting a Pooled Server **
2998+ See `drcp_pool.py
2999+ <https://github.com/oracle/python-oracledb/tree/main/samples/drcp_pool.py> `__
3000+ for a runnable example of DRCP.
3001+
3002+ **Requesting Pooled Servers be Used **
29833003
2984- To request a DRCP pooled server , you can:
3004+ To enable connections to use DRCP pooled servers , you can:
29853005
29863006- Use a specific connection string in :meth: `oracledb.create_pool() ` or
2987- :meth: `oracledb.connect() `. For example with the
3007+ :meth: `oracledb.connect() ` to request a pooled server . For example with the
29883008 :ref: `Easy Connect syntax <easyconnect >`:
29893009
29903010 .. code-block :: python
@@ -3013,56 +3033,30 @@ To request a DRCP pooled server, you can:
30133033 server_type = " pooled" ,
30143034 cclass = " MYAPP" )
30153035
3016-
30173036 **DRCP Connection Class Names **
30183037
30193038The best practice is to specify a ``cclass `` class name when creating a
30203039python-oracledb connection pool. This user-chosen name provides some
30213040partitioning of DRCP session memory so reuse is limited to similar
30223041applications. It provides maximum pool sharing if multiple application
3023- processes are started. A class name also allows better DRCP usage tracking in
3024- the database. In the database monitoring views, the class name shown will be
3025- the value specified in the application prefixed with the user name.
3042+ processes are started and use the same class name. A class name also allows
3043+ better DRCP usage tracking in the database. In the database monitoring views,
3044+ the class name shown will be the value specified in the application prefixed
3045+ with the user name.
30263046
30273047If ``cclass `` was not specified during pool creation, then the python-oracledb
30283048Thin mode generates a unique connection class with the prefix "DPY" while the
30293049Thick mode generates a unique connection class with the prefix "OCI".
30303050
3031- To create a connection pool requesting a DRCP pooled server and specifying a
3032- class name, you can call:
3033-
3034- .. code-block :: python
3035-
3036- pool = oracledb.create_pool(user = " hr" , password = userpwd, dsn = " dbhost.example.com/orclpdb:pooled" ,
3037- min = 2 , max = 5 , increment = 1 ,
3038- cclass = " MYAPP" )
3039-
3040- Once the pool has been created, your application can get a connection from it
3041- by calling:
3042-
3043- .. code-block :: python
3044-
3045- connection = pool.acquire()
3046-
3047- The python-oracledb connection pool size does not need to match the DRCP pool
3048- size. The limit on overall execution parallelism is determined by the DRCP
3049- pool size.
3050-
3051- Connection class names can also be passed to :meth: `~ConnectionPool.acquire() `,
3052- if you want to use a connection with a different class:
3051+ To create a connection pool requesting DRCP pooled servers be used, and
3052+ specifying a class name, you can call:
30533053
30543054.. code-block :: python
30553055
30563056 pool = oracledb.create_pool(user = " hr" , password = userpwd, dsn = " dbhost.example.com/orclpdb:pooled" ,
30573057 min = 2 , max = 5 , increment = 1 ,
30583058 cclass = " MYAPP" )
30593059
3060- connection = mypool.acquire(cclass = " OTHERAPP" )
3061-
3062- If a pooled server of a requested class is not available, a server with new
3063- session state is used. If the DRCP pool cannot grow, a server with a different
3064- class may be used and its session state cleared.
3065-
30663060 If ``cclass `` is not set, then the pooled server sessions will not be reused
30673061optimally, and the DRCP statistic views may record large values for NUM_MISSES.
30683062
@@ -3085,24 +3079,30 @@ allocated each time :meth:`~ConnectionPool.acquire()` is called:
30853079 min = 2 , max = 5 , increment = 1 ,
30863080 cclass = " MYAPP" , purity = oracledb.PURITY_NEW )
30873081
3088- **Setting the Connection Class and Purity in the Connection String **
3082+ **Acquiring a DRCP Connection **
30893083
3090- Using python-oracledb Thin mode with Oracle Database 21c, or later, you can
3091- specify the class and purity in the connection string itself. This removes the
3092- need to modify an existing application when you want to use DRCP :
3084+ Once DRCP has been enabled and the driver connection pool has been created with
3085+ the appropriate connection string, then your application can get a connection
3086+ that uses DRCP by calling :
30933087
30943088.. code-block :: python
30953089
3096- dsn = " localhost/orclpdb:pooled?pool_connection_class=MYAPP&pool_purity=self"
3090+ connection = pool.acquire()
3091+
3092+ Connection class names can also be passed to :meth: `~ConnectionPool.acquire() `
3093+ if you want to use a connection with a different class:
30973094
3098- For python-oracledb Thick mode, this syntax is supported if you are using
3099- Oracle Database 21c (or later) and Oracle Client 19c (or later). However,
3100- explicitly specifying the purity as *SELF * in this way may cause some unusable
3101- connections in a python-oracledb Thick mode connection pool to not be
3102- terminated. In summary, if you cannot programmatically set the class name and
3103- purity, or cannot use python-oracledb Thin mode, then avoid explicitly setting
3104- the purity as a connection string parameter when using a python-oracledb
3105- connection pooling in Thick mode.
3095+ .. code-block :: python
3096+
3097+ pool = oracledb.create_pool(user = " hr" , password = userpwd, dsn = " dbhost.example.com/orclpdb:pooled" ,
3098+ min = 2 , max = 5 , increment = 1 ,
3099+ cclass = " MYAPP" )
3100+
3101+ connection = mypool.acquire(cclass = " OTHERAPP" )
3102+
3103+ If a pooled server of a requested class is not available, a server with new
3104+ session state is used. If the DRCP pool cannot grow, a server with a different
3105+ class may be used and its session state cleared.
31063106
31073107**Closing Connections when using DRCP **
31083108
@@ -3122,19 +3122,49 @@ other users:
31223122 # Do some database operations
31233123 connection = mypool.acquire()
31243124 . . .
3125- connection.close(); # <- Add this to release the DRCP pooled server
3125+ connection.close() # <- Add this to release the DRCP pooled server
31263126
31273127 # Do lots of non-database work
31283128 . . .
31293129
31303130 # Do some more database operations
31313131 connection = mypool.acquire() # <- And get a new pooled server only when needed
31323132 . . .
3133- connection.close();
3133+ connection.close()
31343134
3135- See `drcp_pool.py
3136- <https://github.com/oracle/python-oracledb/tree/main/samples/drcp_pool.py> `__
3137- for a runnable example of DRCP.
3135+ Setting the DRCP Connection Class and Purity in the Connection String
3136+ ---------------------------------------------------------------------
3137+
3138+ Although setting the DRCP connection class and purity in the application is
3139+ preferred, sometimes it is not possible to modify an existing code base. For
3140+ these applications, you can specify the class and purity along with the pooled
3141+ server option in the connection string.
3142+
3143+ For example with the :ref: `Easy Connect <easyconnect >` syntax::
3144+
3145+ dbhost.example.com/orclpdb:pooled?pool_connection_class=MYAPP&pool_purity=self
3146+
3147+ or by using a :ref: `TNS Alias <netservice >` in a
3148+ :ref: `tnsnames.ora <optnetfiles >` file::
3149+
3150+ customerpool = (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)
3151+ (HOST=dbhost.example.com)
3152+ (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orclpdb)
3153+ (SERVER=POOLED)
3154+ (POOL_CONNECTION_CLASS=MYAPP)
3155+ (POOL_PURITY=SELF)))
3156+
3157+ You can specify the class and purity options in connection strings when using
3158+ python-oracledb Thin mode with Oracle Database 21c, or later.
3159+
3160+ For python-oracledb Thick mode, setting these options in the connection string
3161+ is supported if you are using Oracle Database 21c (or later) and Oracle Client
3162+ 19c (or later). However, explicitly specifying the purity as *SELF * in this way
3163+ may cause some unusable connections in a python-oracledb Thick mode connection
3164+ pool to not be terminated. In summary, if you cannot programmatically set the
3165+ class name and purity, or cannot use python-oracledb Thin mode, then avoid
3166+ explicitly setting the purity as a connection string parameter when using a
3167+ local python-oracledb connection pool in Thick mode.
31383168
31393169.. _monitoringdrcp :
31403170
0 commit comments