HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

Oracle intermittently throws "ORA-12516, TNS:listener could not find available handler with matching protocol stack"

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
protocolavailabletnsstackwithhandlercouldthrowslistenerora

Problem

While testing the Oracle XE connection establishing mechanism I bumped into the following issue.
Although connections are closed on each iteration, after 50-100 connections Oracle starts throwing intermittently the following exception:

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12516, TNS:listener could not find available handler with matching protocol stack
 
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:553) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:254) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
    at com.vladmihalcea.book.high_performance_java_persistence.jdbc.connection.OracleConnectionCallTest.test(OracleConnectionCallTest.java:57) [test-classes/:na]


The test can be found on GitHub:

for (int i = 0; i < callCount; i++) {
    try {
        long startNanos = System.nanoTime();
        try (Connection connection = dataSource.getConnection()) {
        }
        timer.update(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
        sleep(waitMillis);
    } catch (SQLException e) {
        LOGGER.info("Exception on iteration " + i, e);
    }
}


If I try to open/close connections with a 35 ms wait step, everything works fine. If I lower the wait to 10 ms the excep

Solution

It's not a bug. This behaviour is expected. If you need to increase the connections, just change the processes limit:

SQL> show parameter processes
processes                            integer     150

SQL> alter system set processes =  scope=[...];
SQL> shutdown immediate;
SQL> startup;


-- Either using pfile or spfile, you'll need to bounce the db, because processes parameter is static.

And for completeness sake, it worths saying that when in a production environment and you need to increase processes limit, you may also need to increase correlated parameters, such as transactions and sessions (derived from processes). You can query v$resource_limit to determine current limits and values in use:

SQL> select * from v$resource_limit where resource_name in ('processes', 'sessions', 'transactions');

Code Snippets

SQL> show parameter processes
processes                            integer     150

SQL> alter system set processes = <integer> scope=[...];
SQL> shutdown immediate;
SQL> startup;
SQL> select * from v$resource_limit where resource_name in ('processes', 'sessions', 'transactions');

Context

StackExchange Database Administrators Q#110819, answer score: 8

Revisions (0)

No revisions yet.