Skip to content

Commit 7751ccf

Browse files
Documentation improvements.
1 parent 2bf6d2f commit 7751ccf

File tree

6 files changed

+95
-47
lines changed

6 files changed

+95
-47
lines changed

doc/src/api_manual/module.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,12 @@ Module Interface
231231
number of connections opened when the pool is created. The increment is the
232232
number of connections that are opened whenever a connection request exceeds
233233
the number of currently open connections. The max parameter is the maximum
234-
number of connections that can be open in the connection pool. Note that
235-
when :ref:`external authentication <extauth>` or :ref:`heterogeneous pools
236-
<connpooltypes>` are used, the pool growth behavior is different.
234+
number of connections that can be open in the connection pool.
235+
236+
Note that when using :ref:`external authentication <extauth>`,
237+
:ref:`heterogeneous pools <connpooltypes>`, or :ref:`drcp`, then the pool
238+
growth behavior is different. In these cases the number of connections
239+
created at pool startup is always zero, and the increment is always one.
237240

238241
If the connectiontype parameter is specified, all calls to
239242
:meth:`~SessionPool.acquire()` will create connection objects of that type,

doc/src/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Welcome to cx_Oracle's documentation!
55
**cx_Oracle** is a module that enables access to Oracle Database and conforms
66
to the Python database API specification. This module is currently tested
77
against Oracle Client 19c, 18c, 12c, and 11.2, and Python 3.5, 3.6, 3.7 and
8-
3.8.
8+
3.8. Older versions of cx_Oracle may be used with previous Python releases.
99

1010
**cx_Oracle** is distributed under an open-source :ref:`license <license>`
1111
(the BSD license). A detailed description of cx_Oracle changes can be found in

doc/src/release_notes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 8.0.1 (TBD)
1212
<https://oracle.github.io/odpi/doc/releasenotes.html#
1313
version-4-0-2-TBD>`__. This includes the fix for
1414
(`issue 459 <https://github.com/oracle/python-cx_Oracle/issues/459>`__).
15+
#) Documentation improvements.
1516

1617

1718
Version 8.0 (June 2020)

doc/src/user_guide/connection_handling.rst

+83-40
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ There are two ways to connect to Oracle Database using cx_Oracle:
2222

2323
* **Pooled connections**
2424

25-
Connection pooling is important for performance when applications
26-
frequently connect and disconnect from the database. Oracle high
27-
availability features in the pool implementation mean that small
28-
pools can also be useful for applications that want a few
29-
connections available for infrequent use. Pools are created with
30-
:meth:`cx_Oracle.SessionPool()` and then
31-
:meth:`SessionPool.acquire()` can be called to obtain a connection
32-
from a pool.
25+
:ref:`Connection pooling <connpool>` is important for performance when
26+
applications frequently connect and disconnect from the database. Pools
27+
support Oracle's :ref:`high availability <highavailability>` features and are
28+
recommended for applications that must be reliable. Small pools can also be
29+
useful for applications that want a few connections available for infrequent
30+
use. Pools are created with :meth:`cx_Oracle.SessionPool()` at application
31+
initialization time, and then :meth:`SessionPool.acquire()` can be called to
32+
obtain a connection from a pool.
3333

3434
Many connection behaviors can be controlled by cx_Oracle options. Other
3535
settings can be configured in :ref:`optnetfiles` or in :ref:`optclientfiles`.
@@ -57,8 +57,7 @@ Connections should be released when they are no longer needed by calling
5757
:meth:`Connection.close()`. Alternatively, you may prefer to let connections
5858
be automatically cleaned up when references to them go out of scope. This lets
5959
cx_Oracle close dependent resources in the correct order. One other approach is
60-
the use of a "with" block, which ensures that a connection is closed once the
61-
block is completed. For example:
60+
the use of a "with" block, for example:
6261

6362
.. code-block:: python
6463
@@ -73,6 +72,9 @@ This code ensures that, once the block is completed, the connection is closed
7372
and resources have been reclaimed by the database. In addition, any attempt to
7473
use the variable ``connection`` outside of the block will simply fail.
7574

75+
Prompt closing of connections is important when using connection pools so
76+
connections are available for reuse by other pool users.
77+
7678
.. _connstr:
7779

7880
Connection Strings
@@ -248,25 +250,38 @@ Connection Pooling
248250
==================
249251

250252
cx_Oracle's connection pooling lets applications create and maintain a pool of
251-
connections to the database. The internal implementation uses Oracle's
252-
`session pool technology <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
253-
id=GUID-F9662FFB-EAEF-495C-96FC-49C6D1D9625C>`__.
254-
In general, each connection in a cx_Oracle connection pool corresponds to one
255-
Oracle session.
253+
connections to the database. Connection pooling is important for performance
254+
when applications frequently connect and disconnect from the database. The pool
255+
implementation uses Oracle's `session pool technology
256+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
257+
id=GUID-F9662FFB-EAEF-495C-96FC-49C6D1D9625C>`__ which supports Oracle's
258+
:ref:`high availability <highavailability>` features and is recommended for
259+
applications that must be reliable. This also means that small pools can be
260+
useful for applications that want a few connections available for infrequent
261+
use.
256262

257263
A connection pool is created by calling :meth:`~cx_Oracle.SessionPool()`. This
258-
is generally called during application initialization. Connections can then be
259-
obtained from a pool by calling :meth:`~SessionPool.acquire()`. The initial
260-
pool size and the maximum pool size are provided at the time of pool creation.
261-
When the pool needs to grow, new connections are created automatically. The
262-
pool can shrink back to the minimum size when connections are no longer in use.
264+
is generally called during application initialization. The initial pool size
265+
and the maximum pool size are provided at the time of pool creation. When the
266+
pool needs to grow, new connections are created automatically. The pool can
267+
shrink back to the minimum size when connections are no longer in use. For
268+
pools created with :ref:`external authentication <extauth>`, with
269+
:ref:`homogeneous <connpooltypes>` set to False, or when using :ref:`drcp`, then
270+
the number of connections initially created is zero even if a larger value is
271+
specified for ``min``. Also in these cases the pool increment is always 1,
272+
regardless of the value of ``increment``.
273+
274+
After a pool has been created, connections can be obtained from it by calling
275+
:meth:`~SessionPool.acquire()`. These connections can be used in the same way
276+
that standalone connections are used.
263277

264278
Connections acquired from the pool should be released back to the pool using
265279
:meth:`SessionPool.release()` or :meth:`Connection.close()` when they are no
266280
longer required. Otherwise, they will be released back to the pool
267281
automatically when all of the variables referencing the connection go out of
268-
scope. The session pool can be completely closed using
269-
:meth:`SessionPool.close()`.
282+
scope. This make connections available for other users of the pool.
283+
284+
The session pool can be completely closed using :meth:`SessionPool.close()`.
270285

271286
The example below shows how to connect to Oracle Database using a
272287
connection pool:
@@ -291,6 +306,17 @@ connection pool:
291306
# Close the pool
292307
pool.close()
293308
309+
Other :meth:`cx_Oracle.SessionPool()` options can be used at pool creation. For
310+
example the ``getmode`` value can be set so that any ``aquire()`` call will wait
311+
for a connection to become available if all are currently in use, for example:
312+
313+
.. code-block:: python
314+
315+
# Create the session pool
316+
pool = cx_Oracle.SessionPool("hr", userpwd, "dbhost.example.com/orclpdb1",
317+
min=2, max=5, increment=1, getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, encoding="UTF-8")
318+
319+
294320
Applications that are using connections concurrently in multiple threads should
295321
set the ``threaded`` parameter to *True* when creating a connection pool:
296322

@@ -300,6 +326,7 @@ set the ``threaded`` parameter to *True* when creating a connection pool:
300326
pool = cx_Oracle.SessionPool("hr", userpwd, "dbhost.example.com/orclpdb1",
301327
min=2, max=5, increment=1, threaded=True, encoding="UTF-8")
302328
329+
303330
See `ConnectionPool.py
304331
<https://github.com/oracle/python-cx_Oracle/tree/master/samples/ConnectionPool.py>`__
305332
for an example.
@@ -314,33 +341,49 @@ will also do a full :ref:`round-trip <roundtrips>` ping to the database when it
314341
is about to return a connection that was unused in the pool for 60 seconds. If
315342
the ping fails, the connection will be discarded and another one obtained before
316343
:meth:`~SessionPool.acquire()` returns to the application. Because this full
317-
ping is time based, it won't catch every failure. Also since network timeouts
318-
and session kills may occur after :meth:`~SessionPool.acquire()` and before
319-
:meth:`Cursor.execute()`, applications need to check for errors after each
320-
:meth:`~Cursor.execute()` and make application-specific decisions about retrying
321-
work if there was a connection failure. Note both the lightweight and full ping
322-
connection checks can mask configuration issues, for example firewalls killing
323-
connections, so monitor the connection rate in AWR for an unexpected value. You
324-
can explicitly initiate a full ping to check connection liveness with
325-
:meth:`Connection.ping()` but overuse will impact performance and scalability.
344+
ping is time based, it won't catch every failure. Also network timeouts and
345+
session kills may occur after :meth:`~SessionPool.acquire()` and before
346+
:meth:`Cursor.execute()`. To handle these cases, applications need to check
347+
for errors after each :meth:`~Cursor.execute()` and make application-specific
348+
decisions about retrying work if there was a connection failure. Oracle's
349+
:ref:`Application Continuity <highavailability>` can do this automatically in
350+
some cases. Note both the lightweight and full ping connection checks can mask
351+
performance-impacting configuration issues, for example firewalls killing
352+
connections, so monitor the connection rate in `AWR
353+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-56AEF38E-9400-427B-A818-EDEC145F7ACD>`__
354+
for an unexpected value. You can explicitly initiate a full ping to check
355+
connection liveness with :meth:`Connection.ping()` but overuse will impact
356+
performance and scalability.
357+
358+
Connection Pool Sizing
359+
----------------------
326360

327361
The Oracle Real-World Performance Group's recommendation is to use fixed size
328-
connection pools. The values of min and max should be the same (and the
329-
increment equal to zero). The :ref:`firewall <hanetwork>`, `resource manager
330-
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-2BEF5482-CF97-4A85-BD90-9195E41E74EF>`__
331-
or user profile `IDLE_TIME
332-
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-ABC7AE4D-64A8-4EA9-857D-BEF7300B64C3>`__
333-
should not expire idle sessions. This avoids connection storms which can
334-
decrease throughput. See `Guideline for Preventing Connection Storms: Use
335-
Static Pools
362+
connection pools. The values of ``min`` and ``max`` should be the same (and the
363+
``increment`` equal to zero). This avoids connection storms which can decrease
364+
throughput. See `Guideline for Preventing Connection Storms: Use Static Pools
336365
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-7DFBA826-7CC0-4D16-B19C-31D168069B54>`__,
337-
which contains details about sizing of pools.
366+
which contains more details about sizing of pools. Having a fixed size will
367+
guarantee that the database can handle the upper pool size. For example, if a
368+
pool needs to grow but the database resources are limited, then
369+
:meth:`SessionPool.acquire()` may return errors such as ORA-28547. With a fixed
370+
pool size, this class of error will occur when the pool is created, allowing you
371+
to change the size before users access the application. With a dynamically
372+
growing pool, the error may occur much later after the pool has been in use for
373+
some time.
338374

339375
The Real-World Performance Group also recommends keeping pool sizes small, as
340376
they may perform better than larger pools. The pool attributes should be
341377
adjusted to handle the desired workload within the bounds of available resources
342378
in cx_Oracle and the database.
343379

380+
Make sure the :ref:`firewall <hanetwork>`, `resource manager
381+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-2BEF5482-CF97-4A85-BD90-9195E41E74EF>`__
382+
or user profile `IDLE_TIME
383+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-ABC7AE4D-64A8-4EA9-857D-BEF7300B64C3>`__
384+
do not expire idle sessions, since this will require connections be recreated,
385+
which will impact performance and scalability.
386+
344387
.. _sessioncallback:
345388

346389
Session CallBacks for Setting Pooled Connection State

doc/src/user_guide/ha.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Oracle Application Continuity and Transparent Application Continuity are Oracle
119119
Database technologies that record application interaction with the database and,
120120
in the event of a database instance outage, attempt to replay the interaction on
121121
a surviving database instance. If successful, users will be unaware of any
122-
database issue.
122+
database issue. AC and TAC are best suited for OLTP applications.
123123

124124
When AC or TAC are configured on the database service, they are transparently
125125
available to cx_Oracle applications.

src/cxoConnection.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,9 @@ static PyObject *cxoConnection_unsubscribe(cxoConnection *conn, PyObject* args,
18531853

18541854

18551855
//-----------------------------------------------------------------------------
1856-
// cxoConnection_commit()
1857-
// Commit the transaction on the connection.
1856+
// cxoConnection_getSodaDatabase()
1857+
// Create and return a new SODA database object associated with the
1858+
// connection.
18581859
//-----------------------------------------------------------------------------
18591860
static PyObject *cxoConnection_getSodaDatabase(cxoConnection *conn,
18601861
PyObject *args)

0 commit comments

Comments
 (0)