Skip to content

Commit 2f2f7b3

Browse files
Improvements to documentation and samples.
1 parent c7c0d55 commit 2f2f7b3

File tree

6 files changed

+230
-122
lines changed

6 files changed

+230
-122
lines changed

doc/src/api_manual/module.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,10 @@ Oracledb Methods
590590
users). The default value is True.
591591

592592
The ``timeout`` parameter is the length of time (in seconds) that a
593-
connection may remain idle in the pool before it is terminated. If the
594-
value of this parameter is 0, then the connections are never terminated.
595-
The default value is 0.
593+
connection may remain idle in the pool before it is terminated. This
594+
applies only when the pool has more than ``min`` connections open, allowing
595+
it to shrink to the specified minimum size. If the value of this parameter
596+
is 0, then the connections are never terminated. The default value is 0.
596597

597598
The ``wait_timeout`` parameter is the length of time (in milliseconds) that
598599
a caller should wait when acquiring a connection from the pool with
@@ -970,9 +971,10 @@ Oracledb Methods
970971
The default value is True.
971972

972973
The ``timeout`` parameter is the length of time (in seconds) that a
973-
connection may remain idle in the pool before it is terminated. If the
974-
value of this parameter is 0, then the connections are never terminated.
975-
The default value is 0.
974+
connection may remain idle in the pool before it is terminated. This
975+
applies only when the pool has more than ``min`` connections open, allowing
976+
it to shrink to the specified minimim size. If the value of this parameter
977+
is 0, then the connections are never terminated. The default value is 0.
976978

977979
The ``wait_timeout`` parameter is the length of time (in milliseconds) that
978980
a caller should wait when acquiring a connection from the pool with

doc/src/release_notes.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ Thin Mode Changes
1616
#) Added internal support for prefetching the LOB size and chunk size, thereby
1717
eliminating a :ref:`round-trip<roundtrips>` when calling
1818
:meth:`LOB.size()` and :meth:`LOB.getchunksize()`.
19-
#) Added implementation for :data:`ConnectionPool.timeout`.
20-
#) Connections returned to the pool are now the first to be returned when
21-
calling :meth:`ConnectionPool.acquire()` afterwards. This helps reduce the
22-
number of times the session callback must be invoked, if one is used.
19+
#) Added implementation for :data:`ConnectionPool.timeout` to allow pools to
20+
shrink to ``min`` connections.
2321
#) Added check to prevent adding too many elements to bounded database
2422
collections.
2523
#) Removed internally set fixed size for database collections. Collections of
2624
any size supported by the database can now be created.
27-
#) Removed packet for negotiating network services which are not supported in
28-
thin mode.
2925
#) Fixed bug when calling :meth:`Cursor.executemany()` with PL/SQL when the
3026
size of the bound data increases on subsequent calls
3127
(`issue 132 <https://github.com/oracle/python-oracledb/issues/132>`__).
@@ -37,6 +33,14 @@ Thin Mode Changes
3733
#) Fixed bug with SQL containing multibyte characters with certain database
3834
character sets
3935
(`issue 133 <https://github.com/oracle/python-oracledb/issues/133>`__).
36+
#) Implementation changes:
37+
38+
- Made the pool implementation LIFO to improve locality, reduce the number
39+
of times any session callback must be invoked, and allow connections to
40+
be timed out.
41+
- Removed packet for negotiating network services which are not supported
42+
in thin mode.
43+
4044

4145
Thick Mode Changes
4246
++++++++++++++++++

doc/src/user_guide/batch_statement.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,42 @@ be beneficial.
306306

307307
See `load_csv.py <https://github.com/oracle/python-oracledb/tree/main/
308308
samples/load_csv.py>`__ for a runnable example.
309+
310+
311+
Copying Data between Databases
312+
==============================
313+
314+
The :meth:`Cursor.executemany()` function is useful for efficiently copying
315+
data from one database to another:
316+
317+
.. code-block:: python
318+
319+
# Connect to both databases
320+
source_connection = oracledb.connect(user=un1, password=pw1, dsn=cs1)
321+
target_connection = oracledb.connect(user=un2, password=pw2, dsn=cs2)
322+
323+
# Setup cursors
324+
source_cursor = source_connection.cursor()
325+
source_cursor.arraysize = 1000 # tune this for query performance
326+
327+
target_cursor = target_connection.cursor()
328+
target_cursor.setinputsizes(None, 25) # set according to column types
329+
330+
# Perform bulk fetch and insertion
331+
source_cursor.execute("select c1, c2 from MySrcTable")
332+
while True:
333+
rows = source_cursor.fetchmany()
334+
if not rows:
335+
break
336+
target_cursor.executemany("insert into MyDestTable values (:1, :2)", rows)
337+
338+
target_connection.commit()
339+
340+
Tune the :attr:`~Cursor.arraysize` value according to notes in
341+
:ref:`tuningfetch`. Use ``setinputsizes()`` according to `Predefining Memory
342+
Areas`_.
343+
344+
Note that it may be preferable to create a `database link
345+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-D966642A-B19E-449D-9968-1121AF06D793>`__
346+
between the databases and use an INSERT INTO SELECT statement so that data is
347+
not copied to, and back from, the Python process.

doc/src/user_guide/connection_handling.rst

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -666,22 +666,23 @@ re-establish connections in a background thread.
666666

667667
A connection pool can shrink back to its minimum size when connections opened
668668
by the pool are not used by the application. This frees up database resources
669-
while allowing pools to retain connections for active users. Note this is
670-
currently applicable to Thick mode only. If connections are idle in the pool
671-
(i.e. not currently acquired by the application) and are unused for longer than
672-
the pool creation attribute ``timeout`` value , then they will be closed. The
673-
default ``timeout`` is 0 seconds signifying an infinite time and meaning idle
674-
connections will never be closed. The pool creation parameter
675-
``max_lifetime_session`` also allows pools to shrink. This parameter bounds
676-
the total length of time that a connection can exist starting from the time the
677-
pool created it. If a connection was created ``max_lifetime_session`` or
678-
longer seconds ago, then it will be closed when it is idle in the pool. In the
679-
case when ``timeout`` and ``max_lifetime_session`` are both set, the connection
680-
will be terminated if either the idle timeout happens or the max lifetime
681-
setting is exceeded. Note that when using python-oracledb in Thick mode with
682-
Oracle Client libraries prior to 21c, pool shrinkage is only initiated when the
683-
pool is accessed so pools in fully dormant applications will not shrink until
684-
the application is next used.
669+
while allowing pools to retain connections for active users. If connections
670+
are idle in the pool (i.e. not currently acquired by the application) and are
671+
unused for longer than the pool creation attribute ``timeout`` value, then they
672+
will be closed. The default ``timeout`` is 0 seconds signifying an infinite
673+
time and meaning idle connections will never be closed. In python-oracledb
674+
Thick mode, the pool creation parameter ``max_lifetime_session`` also allows
675+
pools to shrink. This parameter bounds the total length of time that a
676+
connection can exist starting from the time the pool created it. If a
677+
connection was created ``max_lifetime_session`` or longer seconds ago, then it
678+
will be closed when it is idle in the pool. In the case when ``timeout`` and
679+
``max_lifetime_session`` are both set, the connection will be terminated if
680+
either the idle timeout happens or the max lifetime setting is exceeded. Note
681+
that when using python-oracledb in Thick mode with Oracle Client libraries
682+
prior to 21c, pool shrinkage is only initiated when the pool is accessed so
683+
pools in fully dormant applications will not shrink until the application is
684+
next used. When using python-oracledb in Thin mode, connection timeout checks
685+
only occur when :meth:`~ConnectionPool.acquire()` is called.
685686

686687
For pools created with :ref:`external authentication <extauth>`, with
687688
:ref:`homogeneous <connpooltypes>` set to False, or when using :ref:`drcp`,
@@ -802,7 +803,7 @@ can be set directly, for example:
802803
803804
.. _sessioncallback:
804805

805-
Session CallBacks for Setting Pooled Connection State
806+
Session Callbacks for Setting Pooled Connection State
806807
-----------------------------------------------------
807808

808809
Applications can set "session" state in each connection. Examples of session

0 commit comments

Comments
 (0)