Taming Connection Storms from Kubernetes: Database Resident Connection Pooling on Exadata in Oracle Database@Azure
Microservices are good at scaling out and bad at sharing. Each pod of the order service in Azure Kubernetes Service opens its own pool of database connections, and each connection is a dedicated server process on the database. When the deployment scales from 20 to 60 pods for a sales campaign, the number of server processes triples, logon storms hit the listener at every rolling restart, and most of those processes sit idle, holding memory.
Database Resident Connection Pooling (DRCP) puts the pool inside the database. Clients connect to a connection broker, which hands them a pooled server only while they run a database call and takes it back afterwards. A few hundred pooled servers can serve thousands of client connections. This post enables DRCP on an Exadata Database Service cluster in Oracle Database@Azure and moves the order service onto it.
The Use Case
The order service runs in AKS with python-oracledb. Each pod keeps a local pool of 20 connections, and the deployment runs 40 to 60 pods. At peak, the two RAC instances carry about 1,200 sessions from this service alone, while AWR shows that fewer than 150 are active at any moment. Rolling restarts of the deployment cause bursts of several hundred logons per second. The goal is fewer server processes, faster connects and no change to the application's SQL.
Environment used in this runbook
Service: Exadata Database Service on Dedicated Infrastructure in Oracle Database@Azure
Database: Oracle Database 19c (19.24), container database SALESCDB with PDB SALESPDB, two-node RAC
Clients: order-service pods in Azure Kubernetes Service, python-oracledb in thin mode
Network: AKS virtual network peered with the Oracle Database@Azure delegated subnet
Licence: DRCP is part of Oracle Database and needs no extra-cost option
How DRCP Works
A connection broker accepts the clients. Clients connect through the listener as usual, but with SERVER=POOLED; the broker holds their connections without a server process.
Pooled servers do the work. When a client sends a call, the broker attaches a pooled server, which combines a server process and a session; when the client releases it, the server goes back to the pool.
Connection classes keep sessions apart. Pooled sessions are reused only by clients of the same connection class, so session state from one application does not leak into another.
In 19c the pool belongs to the CDB. The default pool, SYS_DEFAULT_CONNECTION_POOL, is started and configured in CDB$ROOT and serves all PDBs; from 21c, pools can also be configured per PDB.
Not for every workload. Long batch jobs that hold a session for hours gain nothing; DRCP suits many short requests from many clients.
Step 1: Measure the Current Sessions
Count the sessions and how many of them are actually active, per instance and program. This is the number DRCP will reduce.
SQL |
-- Connected to CDB$ROOT as SYSDBA COLUMN program FORMAT A20
SELECT inst_id, program, COUNT(*) AS sessions, SUM(CASE WHEN status = 'ACTIVE' THEN 1 ELSE 0 END) AS active FROM gv$session WHERE username = 'ORDER_SVC' GROUP BY inst_id, program ORDER BY inst_id; |
Expected output |
INST_ID PROGRAM SESSIONS ACTIVE
---------- -------------------- ---------- ----------
1 order-service 612 71
2 order-service 598 64What to expect: About 1,200 sessions with only around 10 percent active. Each idle dedicated server still holds its process memory and its slot in the PROCESSES limit. This gap between connected and active is what DRCP closes.
Step 2: Check the Pool Configuration
Look at the default pool before changing it. In 19c, run this in CDB$ROOT.
SQL |
COLUMN connection_pool FORMAT A28 COLUMN status FORMAT A8
SELECT connection_pool, status, minsize, maxsize, inactivity_timeout, max_think_time FROM dba_cpool_info; |
Expected output |
CONNECTION_POOL STATUS MINSIZE MAXSIZE INACTIVITY_TIMEOUT MAX_THINK_TIME
---------------------------- -------- ---------- ---------- ------------------ --------------
SYS_DEFAULT_CONNECTION_POOL INACTIVE 4 40 300 120What to expect: The default pool exists but is INACTIVE, with the default sizes: at least 4 and at most 40 pooled servers per instance, idle pooled servers released after 300 seconds, and a client that holds a pooled server for 120 seconds without a call loses its connection. The maximum of 40 is far too small for this workload.
Step 3: Size and Start the Pool
Size the pool from the active sessions measured in Step 1, with headroom, and start it. On RAC, the pool runs on every instance and the sizes apply per instance.
SQL |
BEGIN DBMS_CONNECTION_POOL.CONFIGURE_POOL( pool_name => 'SYS_DEFAULT_CONNECTION_POOL', minsize => 40, maxsize => 200, incrsize => 10, session_cached_cursors => 100, inactivity_timeout => 300, max_think_time => 600);
DBMS_CONNECTION_POOL.START_POOL; END; /
SELECT connection_pool, status, minsize, maxsize, inactivity_timeout, max_think_time FROM dba_cpool_info; |
Expected output |
PL/SQL procedure successfully completed.
CONNECTION_POOL STATUS MINSIZE MAXSIZE INACTIVITY_TIMEOUT MAX_THINK_TIME
---------------------------- -------- ---------- ---------- ------------------ --------------
SYS_DEFAULT_CONNECTION_POOL ACTIVE 40 200 300 600What this does: Each instance keeps between 40 and 200 pooled servers, growing in steps of 10. About 70 sessions are active per instance at peak, so 200 leaves room for spikes. The longer max_think_time of 600 seconds protects requests where the application does some work between two calls. The pool stays started across instance restarts until STOP_POOL is called.
Tip: Check the PROCESSES parameter before you raise maxsize. Pooled servers and the connection broker processes count towards it, and dedicated connections from other applications still need their share.
Step 4: Point the Pods at the Pool
Change the connect string of the order service to request a pooled server, and give the application its own connection class. Clients with the same class share pooled sessions; others never see them.
Shell |
# Connect string in the Kubernetes secret or config map, Easy Connect syntax with :POOLED kubectl -n orders create configmap order-db \ --from-literal=DB_DSN="salesdb-scan.example.internal:1521/salespdb_orders.example.internal:POOLED" \ --dry-run=client -o yaml | kubectl apply -f -
# Application code (python-oracledb): two extra arguments to create_pool # oracledb.create_pool(..., dsn=os.environ["DB_DSN"], min=2, max=20, # cclass="ORDERSVC", purity=oracledb.PURITY_SELF)
kubectl -n orders rollout restart deployment/order-service kubectl -n orders rollout status deployment/order-service |
Expected output |
configmap/order-db configured
deployment.apps/order-service restarted
deployment "order-service" successfully rolled outWhat this does: The :POOLED suffix is the Easy Connect form of SERVER=POOLED. The cclass value ORDERSVC names the connection class, and PURITY_SELF lets a request reuse a pooled session of that class, with its cached cursors and session settings. The password still comes from the existing Kubernetes secret; nothing about authentication changes.
Step 5: Watch the Pool Fill and Serve
After the rollout, read the pool statistics. They show how many requests came in, how many were served from the pool, and whether anyone had to wait.
SQL |
SELECT inst_id, num_open_servers, num_busy_servers, num_requests, num_hits, num_misses, num_waits FROM gv$cpool_stats ORDER BY inst_id; |
Expected output |
INST_ID NUM_OPEN_SERVERS NUM_BUSY_SERVERS NUM_REQUESTS NUM_HITS NUM_MISSES NUM_WAITS
---------- ---------------- ---------------- ------------ ---------- ---------- ----------
1 88 63 418772 414105 4667 0
2 84 59 405319 401002 4317 0What to expect: Fewer than 90 pooled servers per instance serve all the pods, with a hit rate of about 99 percent, meaning the request reused a pooled session of the same class instead of creating one. NUM_WAITS of 0 means no request had to wait for a free pooled server. If NUM_WAITS climbs, raise maxsize; if NUM_MISSES stays high, check that every pod sets the same connection class.
Step 6: Check the Connection Classes
The per-class statistics confirm that the application uses its own class and that sessions are reused within it.
SQL |
COLUMN cclass_name FORMAT A30
SELECT inst_id, cclass_name, num_requests, num_hits, num_misses FROM gv$cpool_cc_stats ORDER BY inst_id, cclass_name; |
Expected output |
INST_ID CCLASS_NAME NUM_REQUESTS NUM_HITS NUM_MISSES
---------- ------------------------------ ------------ ---------- ----------
1 ORDER_SVC.ORDERSVC 418772 414105 4667
2 ORDER_SVC.ORDERSVC 405319 401002 4317What to expect: One class, named after the database user and the cclass value. A class shown as ORDER_SVC.SHARED, or one class per pod, would mean that the cclass setting is missing or differs between pods, and the hit rate would drop.
Step 7: Compare the Server Processes
Count the sessions again. Client connections now wait at the broker without a server process, so the number of sessions in the database falls to the size of the pool.
SQL |
SELECT inst_id, COUNT(*) AS sessions, SUM(CASE WHEN status = 'ACTIVE' THEN 1 ELSE 0 END) AS active FROM gv$session WHERE username = 'ORDER_SVC' GROUP BY inst_id ORDER BY inst_id; |
Expected output |
INST_ID SESSIONS ACTIVE
---------- ---------- ----------
1 88 66
2 84 61What to expect: From about 1,200 sessions down to about 170, with the same number of active ones. The memory those idle processes held is now free for the buffer cache and PGA of the active workload, and logons during a rolling restart are cheap because the broker attaches existing pooled servers instead of starting new processes.
Step 8: Rehearse a Rolling Restart
A rolling restart used to be the worst moment for the database. Restart the deployment during the day and watch the broker connections and the pool.
Shell |
kubectl -n orders rollout restart deployment/order-service
# During the rollout, on a database server sqlplus -s / as sysdba <<'EOF' SELECT inst_id, num_open_servers, num_busy_servers, num_waits FROM gv$cpool_stats ORDER BY inst_id; EOF |
Expected output |
deployment.apps/order-service restarted
INST_ID NUM_OPEN_SERVERS NUM_BUSY_SERVERS NUM_WAITS
---------- ---------------- ---------------- ----------
1 92 58 0
2 86 55 0What to expect: The number of open pooled servers barely moves while pods are replaced, and no request waits. Compare the listener log for the same period with an earlier restart: the logon rate is the same, but each logon now attaches to the broker instead of creating a dedicated process.
Step 9: Know How to Go Back
If an application component behaves badly with pooled sessions, for example because it relies on session state between requests in a way the connection class does not cover, it can go back to dedicated servers without touching the others.
Shell |
# Per application: remove :POOLED from its connect string and restart it kubectl -n orders create configmap order-db \ --from-literal=DB_DSN="salesdb-scan.example.internal:1521/salespdb_orders.example.internal" \ --dry-run=client -o yaml | kubectl apply -f -
# For the whole CDB, only when no application uses DRCP any more: # sqlplus / as sysdba -> EXEC DBMS_CONNECTION_POOL.STOP_POOL; |
Expected output |
configmap/order-db configuredWhat this does: The application returns to dedicated servers at its next restart, while other applications keep using the pool. Stopping the pool itself affects every PDB in the CDB in 19c, so leave it running as long as any client still connects with SERVER=POOLED.
Summary
DRCP moves connection pooling into the database, where pods in Azure Kubernetes Service can share it. Measure connected and active sessions, size the default pool in CDB$ROOT from the active count with headroom, and start it. Point each application at it with the :POOLED connect string, a connection class and PURITY_SELF, then check V$CPOOL_STATS and V$CPOOL_CC_STATS for hits, misses and waits. On Exadata Database Service in Oracle Database@Azure this turned 1,200 mostly idle sessions into fewer than 200 busy ones, and made rolling restarts uneventful. In 19c the pool is CDB-wide; from 21c it can also be configured per PDB.
Comments