ORA-12537 TNS Connection Closed - Resolution Guide
ORA-12537: TNS:connection Closed
Section titled “ORA-12537: TNS:connection Closed”Error Overview
Section titled “Error Overview”Error Text: ORA-12537: TNS:connection closed
This error occurs when a network connection to an Oracle database is unexpectedly terminated. The connection was established but then dropped before the operation completed. It’s a critical production error that often indicates network infrastructure problems, listener issues, or resource exhaustion.
Common Causes
Section titled “Common Causes”1. Firewall Timeout
Section titled “1. Firewall Timeout”- Firewall dropping idle connections
- Connection idle longer than firewall timeout
- Stateful firewall losing connection state
2. Network Infrastructure Issues
Section titled “2. Network Infrastructure Issues”- Network switches or routers dropping connections
- MTU size mismatches causing packet fragmentation
- Load balancer timeout settings
- VPN tunnel disconnections
3. Listener Problems
Section titled “3. Listener Problems”- Listener process crashing or restarting
- Listener overloaded with connection requests
- Incorrect listener configuration
4. Oracle Server Issues
Section titled “4. Oracle Server Issues”- Database instance crash or shutdown
- PMON process cleanup killing sessions
- Memory pressure causing process termination
- OS killing Oracle processes (OOM killer)
5. Client-Side Issues
Section titled “5. Client-Side Issues”- Client network timeout settings too aggressive
- TCP keepalive not configured
- Client process abnormal termination
Diagnostic Queries
Section titled “Diagnostic Queries”Check Listener Status and Log
Section titled “Check Listener Status and Log”# Check listener statuslsnrctl status
# View listener log for errorstail -100 $ORACLE_BASE/diag/tnslsnr/$(hostname)/listener/trace/listener.log
# Check for connection refused or reset entriesgrep -i "12537\|connection closed\|connection reset" $ORACLE_BASE/diag/tnslsnr/*/listener/trace/listener.logCheck Database Instance Status
Section titled “Check Database Instance Status”-- Verify instance is runningSELECT instance_name, status, startup_time, host_nameFROM v$instance;
-- Check for recent instance restartsSELECT startup_time, instance_nameFROM v$instance;
-- Check alert log for errors around the time of disconnectionSELECT originating_timestamp, message_textFROM x$dbgalertextWHERE originating_timestamp > SYSTIMESTAMP - INTERVAL '1' HOUR AND (message_text LIKE '%ORA-%' OR message_text LIKE '%shutdown%' OR message_text LIKE '%terminated%')ORDER BY originating_timestamp DESC;Check Session and Process Limits
Section titled “Check Session and Process Limits”-- Are we hitting resource limits?SELECT resource_name, current_utilization, max_utilization, limit_valueFROM v$resource_limitWHERE resource_name IN ('processes', 'sessions', 'transactions');
-- Check for dead/disconnected sessionsSELECT status, COUNT(*) as session_countFROM v$sessionGROUP BY status;
-- Sessions killed recently (KILLED status)SELECT sid, serial#, username, machine, program, status, last_call_etFROM v$sessionWHERE status = 'KILLED';Check Network Configuration
Section titled “Check Network Configuration”-- Current SQL*Net parametersSELECT name, valueFROM v$parameterWHERE name IN ( 'sqlnet.expire_time', 'tcp.connect_timeout', 'tcp.validnode_checking');
-- Check for SQLNET.EXPIRE_TIME (dead connection detection)-- This should be set in sqlnet.oraCheck for OOM Killer Activity (Linux)
Section titled “Check for OOM Killer Activity (Linux)”# Check if Linux OOM killer terminated Oracle processesdmesg | grep -i "out of memory\|killed process" | tail -20
# Check specific Oracle process killsgrep -i "oracle\|ora_" /var/log/messages | grep -i "killed"Resolution Steps
Section titled “Resolution Steps”Solution 1: Configure TCP Keepalive
Section titled “Solution 1: Configure TCP Keepalive”# In sqlnet.ora on BOTH client and server:SQLNET.EXPIRE_TIME = 10# Sends a probe every 10 minutes to keep connection alive
# For more aggressive keepalive (Linux server):# /etc/sysctl.confnet.ipv4.tcp_keepalive_time = 300net.ipv4.tcp_keepalive_intvl = 60net.ipv4.tcp_keepalive_probes = 5
# Apply without rebootsysctl -pSolution 2: Adjust Firewall Timeouts
Section titled “Solution 2: Adjust Firewall Timeouts”# Identify firewall timeout# Most firewalls default to 30-60 minutes for idle TCP connections
# Set SQLNET.EXPIRE_TIME lower than firewall timeout# If firewall drops at 30 min, set probe at 10 min:SQLNET.EXPIRE_TIME = 10
# Or request firewall team to increase timeout# Recommended: at least 2 hours for Oracle connectionsSolution 3: Configure Connection Timeout Parameters
Section titled “Solution 3: Configure Connection Timeout Parameters”# sqlnet.ora - Server sideSQLNET.EXPIRE_TIME = 10 # Dead connection detection (minutes)SQLNET.RECV_TIMEOUT = 300 # Receive timeout (seconds)SQLNET.SEND_TIMEOUT = 300 # Send timeout (seconds)
# sqlnet.ora - Client sideSQLNET.OUTBOUND_CONNECT_TIMEOUT = 30 # Connection establishment timeoutSQLNET.RECV_TIMEOUT = 600 # Allow longer for query resultsTCP.CONNECT_TIMEOUT = 10 # TCP level connection timeoutSolution 4: Fix Listener Configuration
Section titled “Solution 4: Fix Listener Configuration”# listener.ora - Ensure proper configurationLISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = your_hostname)(PORT = 1521)) ) )
# Increase listener queue size for busy serversLISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = your_hostname)(PORT = 1521)) (QUEUESIZE = 50) ) )
# Reload listener after changeslsnrctl reloadSolution 5: Application Connection Pool Validation
Section titled “Solution 5: Application Connection Pool Validation”-- Configure connection pool to validate connections before use-- JDBC example:-- Set validationQuery: SELECT 1 FROM dual-- Set testOnBorrow: true-- Set testWhileIdle: true-- Set timeBetweenEvictionRuns: 30000
-- For Oracle UCP (Universal Connection Pool):-- setValidateConnectionOnBorrow(true)-- setConnectionWaitTimeout(30)-- setSQLForValidateConnection("SELECT 1 FROM dual")Solution 6: Check and Increase Resource Limits
Section titled “Solution 6: Check and Increase Resource Limits”-- If hitting process/session limitsALTER SYSTEM SET processes = 500 SCOPE=SPFILE;ALTER SYSTEM SET sessions = 600 SCOPE=SPFILE;-- Requires database restart
-- Check current limitsSHOW PARAMETER processes;SHOW PARAMETER sessions;Monitoring and Prevention
Section titled “Monitoring and Prevention”Proactive Connection Monitoring
Section titled “Proactive Connection Monitoring”-- Monitor connection patternsSELECT TO_CHAR(sample_time, 'YYYY-MM-DD HH24') as hour, COUNT(DISTINCT session_id) as active_sessions, COUNT(CASE WHEN event LIKE '%SQL*Net%' THEN 1 END) as network_waitsFROM v$active_session_historyWHERE sample_time > SYSDATE - 1GROUP BY TO_CHAR(sample_time, 'YYYY-MM-DD HH24')ORDER BY hour;
-- Track disconnection frequencySELECT TO_CHAR(logon_time, 'YYYY-MM-DD') as day, COUNT(*) as total_sessions, SUM(CASE WHEN status = 'KILLED' THEN 1 ELSE 0 END) as killed_sessionsFROM v$sessionGROUP BY TO_CHAR(logon_time, 'YYYY-MM-DD')ORDER BY day DESC;Network Health Check Script
Section titled “Network Health Check Script”#!/bin/bash# Quick network connectivity test to Oracle serverDB_HOST="your_db_host"DB_PORT="1521"
# Test TCP connectivitync -z -w5 $DB_HOST $DB_PORTif [ $? -ne 0 ]; then echo "ERROR: Cannot reach $DB_HOST:$DB_PORT" exit 1fi
# Test tnspingtnsping YOUR_TNS_ALIASif [ $? -ne 0 ]; then echo "ERROR: tnsping failed" exit 1fi
echo "Network connectivity OK"Related Errors
Section titled “Related Errors”- ORA-03113: End-of-file on Communication - Similar disconnection error
- ORA-12170: TNS Connect Timeout - Connection establishment timeout
- ORA-12547: TNS Lost Contact - Connection lost during operation
- ORA-12541: TNS No Listener - Listener not running
- ORA-12560: TNS Protocol Adapter Error - Protocol-level failure