Skip to content

Commit 0467db9

Browse files
Tutorial updates to get ready for the coming weekend's Quest session.
1 parent 5df9a73 commit 0467db9

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed

samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ <h2>Contents</h2>
3333
</li>
3434
<li><a href="#pooling">2. Connection Pooling</a>
3535
<ul>
36-
<li>2.1 Session pooling</li>
37-
<li>2.2 Session pool experiments</li>
36+
<li>2.1 Connection pooling</li>
37+
<li>2.2 Connection pool experiments</li>
3838
<li>2.3 Creating a DRCP Connection</li>
39-
<li>2.4 Session pooling and DRCP</li>
39+
<li>2.4 Connection pooling and DRCP</li>
4040
<li>2.5 More DRCP investigation</li>
4141
</ul>
4242
</li>
@@ -112,7 +112,7 @@ <h2><a name="preface">Preface</a></h2>
112112

113113
<ol>
114114
<li><p><a target="_blank" href="https://www.python.org/">Python</a>. Version 3.6 (or later) is preferred.</p></li>
115-
<li><p>cx_Oracle version 7.2 (or later) and the Oracle Client libraries.</p>
115+
<li><p>cx_Oracle version 7.3 (or later) and the Oracle Client libraries.</p>
116116
<ul>
117117
<li><a target="_blank" href="https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-linux">Linux</a></li>
118118
<li><a target="_blank" href="https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-macos">macOS</a> - please note the special instructions for macOS in the link.</li>
@@ -131,6 +131,14 @@ <h2><a name="preface">Preface</a></h2>
131131
sqlplus sys/yoursyspassword@localhost/orclpdb1 as sysdba @sql/SetupSamples
132132
</pre>
133133

134+
<p>If DRCP is not already running, connect to the SYS user again in
135+
SQL*Plus and execute the command:</p>
136+
137+
<pre>
138+
execute dbms_connection_pool.start_pool()
139+
</pre>
140+
141+
134142
<h2><a name="connectioninformation">Connection Information</a></h2>
135143

136144
<p>The database connection information is set in two files:
@@ -409,7 +417,7 @@ <h4>1.6 Checking versions</h4>
409417
<li><h3><a name="pooling">2. Connection Pooling</a></h3>
410418

411419
<ul>
412-
<li> <h4>2.1 Session pooling</h4>
420+
<li> <h4>2.1 Connection pooling</h4>
413421

414422
<p>Review the code contained in <code>connect_pool.py</code>:</p>
415423
<pre>
@@ -441,22 +449,22 @@ <h4>1.6 Checking versions</h4>
441449
</pre>
442450

443451
<p>The <code>SessionPool()</code> function creates a pool of
444-
Oracle "sessions" for the user. Sessions in the pool
445-
can be used by cx_Oracle connections by calling
446-
<code>pool.acquire()</code>. The initial pool size is 2 sessions.
447-
The maximum size is 5 sessions. When the pool needs to grow, 1 new
448-
session will be created at a time. The pool can shrink back to the
449-
minimum size of 2 when sessions are no longer in use.</p>
452+
Oracle connections for the user. Connections in the pool can
453+
be used by cx_Oracle by calling <code>pool.acquire()</code>.
454+
The initial pool size is 2 connections. The maximum size is 5
455+
connections. When the pool needs to grow, 1 new connection
456+
will be created at a time. The pool can shrink back to the
457+
minimum size of 2 when connections are no longer in use.</p>
450458

451459
<p>The <code>def Query():</code> line creates a method that
452460
is called by each thread. </p>
453461

454462
<p>In the method, the <code>pool.acquire()</code> call gets
455-
one session from the pool (as long as less than 5 are
456-
already in use). This session is used in a loop of 4
463+
one connection from the pool (as long as less than 5 are
464+
already in use). This connection is used in a loop of 4
457465
iterations to query the sequence <code>myseq</code>. At the
458466
end of the method, cx_Oracle will automatically close the
459-
cursor and release the session back to the pool for
467+
cursor and release the connection back to the pool for
460468
reuse.</p>
461469

462470
<p>The <code>seqval, = cur.fetchone()</code> line fetches a
@@ -479,7 +487,7 @@ <h4>1.6 Checking versions</h4>
479487
</li>
480488

481489
<li>
482-
<h4>2.2 Session pool experiments</h4>
490+
<h4>2.2 Connection pool experiments</h4>
483491

484492

485493
<p>Review <code>connect_pool2.py</code>, which has a loop for the number
@@ -521,19 +529,20 @@ <h4>2.2 Session pool experiments</h4>
521529

522530
<p>Experiment with different values of the pool parameters and
523531
<code>numberOfThreads</code>. Larger initial pool sizes will make the
524-
pool creation slower, but the sessions will be available immediately
525-
when needed. When <code>numberOfThreads</code> exceeds the maximum
526-
size of the pool, the <code>acquire()</code> call will generate an
527-
error. Adding the additional argument <code>getmode =
532+
pool creation slower, but the connections will be available immediately
533+
when needed. When <code>numberOfThreads</code> exceeds the maximum size
534+
of the pool, the <code>acquire()</code> call will generate an error such
535+
as "ORA-24459: OCISessionGet() timed out waiting for pool to create new
536+
connections". Adding the additional argument <code>getmode =
528537
cx_Oracle.SPOOL_ATTRVAL_WAIT</code> to the
529538
<code>cx_Oracle.SessionPool()</code> call will prevent the exception
530-
from taking place, but will cause the thread to wait until a session
539+
from taking place, but will cause the thread to wait until a connection
531540
is available.</p>
532541

533542
<p>Pool configurations where <code>min</code> is the same as
534543
<code>max</code> (and <code>increment = 0</code>) are often
535-
recommended as a way to avoid connection storms on the database
536-
server.</p>
544+
recommended as a best practice. This avoids connection storms on the
545+
database server.</p>
537546

538547
</li>
539548

@@ -545,7 +554,7 @@ <h4>2.3 Creating a DRCP Connection</h4>
545554
server processes.</p>
546555

547556
<p>Below left is a diagram without DRCP. Every application
548-
connection or session has its own 'dedicated' database server
557+
connection has its own 'dedicated' database server
549558
process. Application connect and close calls require the expensive
550559
create and destroy of those database server processes. To avoid these
551560
costs, scripts may hold connections open even when not doing
@@ -572,7 +581,7 @@ <h4>2.3 Creating a DRCP Connection</h4>
572581
required. However, if database host memory is large enough, then
573582
the default, 'dedicated' server process model is generally
574583
recommended. If DRCP is enabled, it is best used in conjunction
575-
with cx_Oracle session pooling.</p>
584+
with cx_Oracle's middle-tier connection pooling.</p>
576585

577586
<p>Batch scripts doing long running jobs should generally use
578587
dedicated connections. Both dedicated and DRCP servers can be used
@@ -617,9 +626,9 @@ <h4>2.3 Creating a DRCP Connection</h4>
617626
</li>
618627

619628
<li>
620-
<h4>2.4 Session pooling and DRCP</h4>
629+
<h4>2.4 Connection pooling and DRCP</h4>
621630

622-
<p>DRCP works well with session pooling.</p>
631+
<p>DRCP works well with cx_Oracle's connection pooling.</p>
623632

624633
<p>Edit <code>connect_pool2.py</code>, reset any changed pool options, and modify it to use DRCP:</p>
625634
<pre>
@@ -658,12 +667,13 @@ <h4>2.4 Session pooling and DRCP</h4>
658667

659668
<pre><strong>python connect_pool2.py</strong></pre>
660669

661-
<p>If you get the error "ORA-24418: Cannot open further
670+
<p>If you get an error "ORA-24459: OCISessionGet() timed out waiting for
671+
pool to create new connections" or "ORA-24418: Cannot open further
662672
sessions", it is because connection requests are being made
663673
while the pool is starting or growing. Add the argument
664674
<code>getmode = cx_Oracle.SPOOL_ATTRVAL_WAIT</code> to the
665675
<code>cx_Oracle.SessionPool()</code> call so connection
666-
requests wait for pooled sessions to be available.</p>
676+
requests wait for pooled connections to be available.</p>
667677

668678
<p>Open a new a terminal window and invoke SQL*Plus:</p>
669679

@@ -681,7 +691,7 @@ <h4>2.4 Session pooling and DRCP</h4>
681691
<li>
682692
<h4>2.5 More DRCP investigation</h4>
683693

684-
<p>To explore the behaviors of session and DRCP pooling futher,
694+
<p>To explore the behaviors of cx_Oracle connection pooling and DRCP pooling futher,
685695
you could try changing the purity to
686696
<code>cx_Oracle.ATTR_PURITY_NEW</code> to see the effect on the
687697
DRCP NUM_MISSES statistic.</p>
@@ -921,7 +931,7 @@ <h4>2.5 More DRCP investigation</h4>
921931

922932
<pre><strong>python query_arraysize.py</strong></pre>
923933

924-
<p>Reload a few times to see the average times.</p>
934+
<p>Rerun a few times to see the average times.</p>
925935

926936
<p>Experiment with different arraysize values. For example, edit
927937
<code>query_arraysize.py</code> and change the arraysize to:</p>
@@ -1042,7 +1052,7 @@ <h4>2.5 More DRCP investigation</h4>
10421052
<p>The '<code>rows</code>' array contains the data to be inserted.</p>
10431053

10441054
<p>The <code>executemany()</code> call inserts all rows. This
1045-
calls allows "array binding", which is an efficient way to
1055+
call uses "array binding", which is an efficient way to
10461056
insert multiple records.</p>
10471057

10481058
<p>The final part of the script queries the results back and displays them as a list of tuples.</p>
@@ -1121,11 +1131,11 @@ <h4>2.5 More DRCP investigation</h4>
11211131

11221132
<p>The other data gets inserted and is queried back.</p>
11231133

1124-
<p>At the end of the script, cx_Oracle will rollback an uncommitted transaction. If you want to commit results, you can use:</p>
1134+
<p>At the end of the script, cx_Oracle will roll back an uncommitted transaction. If you want to commit results, you can use:</p>
11251135

11261136
<pre>con.commit()</pre>
11271137

1128-
<p>To force a rollback in cx_Oracle, use:</p>
1138+
<p>To force cx_Oracle to roll back, use:</p>
11291139

11301140
<pre>con.rollback()</pre>
11311141

@@ -2202,7 +2212,7 @@ <h2><a name="summary">Summary</a></h2>
22022212
<p>In this tutorial, you have learned how to: </p>
22032213
<ul>
22042214
<li>Create connections</li>
2205-
<li>Use sessions pooling and Database Resident Connection Pooling</li>
2215+
<li>Use cx_Oracle connection pooling and Database Resident Connection Pooling</li>
22062216
<li>Execute queries and fetch data</li>
22072217
<li>Use bind variables</li>
22082218
<li>Use PL/SQL stored functions and procedures</li>

0 commit comments

Comments
 (0)