TNS-12150 TNS Unable to Send Data - Network Communication Error Resolution
TNS-12150: TNS Unable to Send Data
Section titled “TNS-12150: TNS Unable to Send Data”Error Overview
Section titled “Error Overview”Error Text: TNS-12150: TNS:unable to send data
This error occurs when the Oracle TNS (Transparent Network Substrate) layer cannot send data across the network connection. It indicates a breakdown in network communication between the client and the Oracle database server, often caused by network interruptions, firewall issues, or connection timeouts.
Understanding TNS Communication
Section titled “Understanding TNS Communication”TNS Architecture
Section titled “TNS Architecture”Client Application ↓Oracle Client Libraries (TNS) ↓Network Layer (TCP/IP) ↓Oracle Listener ↓Oracle Database Instance
Communication Flow
Section titled “Communication Flow”- Connection Establishment - Client connects to listener
- Data Transmission - SQL statements and results exchanged
- Session Management - Connection maintained during session
- Connection Termination - Clean disconnection
Common Causes
Section titled “Common Causes”Network Infrastructure Issues
Section titled “Network Infrastructure Issues”- Network congestion or packet loss
- Unstable network connections
- Router or switch problems
- Network cable issues
- WiFi connectivity problems
Firewall and Security
Section titled “Firewall and Security”# Common firewall blocking scenarios- Port 1521 (default Oracle port) blocked- Intermediate firewalls dropping connections- NAT/PAT translation issues- VPN connection problems
Database Server Issues
Section titled “Database Server Issues”- High server load causing timeouts
- Oracle listener overloaded
- Database instance problems
- Memory or resource constraints
Client-Side Problems
Section titled “Client-Side Problems”- Network adapter issues
- DNS resolution problems
- Client software bugs
- Connection pooling issues
Diagnostic Steps
Section titled “Diagnostic Steps”Network Connectivity Tests
Section titled “Network Connectivity Tests”# Test basic network connectivityping database_server
# Test specific port connectivitytelnet database_server 1521# ornc -v database_server 1521
# Test with nmapnmap -p 1521 database_server
# Check network routetraceroute database_server# Windows: tracert database_server
Oracle-Specific Diagnostics
Section titled “Oracle-Specific Diagnostics”# Test TNS connectivitytnsping service_nametnsping database_server:1521
# Check listener statuslsnrctl statuslsnrctl services
# Test SQL*Net connectivitysqlplus username/password@service_name
Client-Side Diagnostics
Section titled “Client-Side Diagnostics”# Check TNS_ADMIN environmentecho $TNS_ADMIN
# Verify tnsnames.oracat $TNS_ADMIN/tnsnames.ora
# Check client configurationcat $TNS_ADMIN/sqlnet.ora
# Enable SQL*Net tracing (if needed)# Add to sqlnet.ora:# TRACE_LEVEL_CLIENT = 16# TRACE_DIRECTORY_CLIENT = /tmp
Server-Side Diagnostics
Section titled “Server-Side Diagnostics”-- Check listener and database statusSELECT instance_name, status FROM v$instance;
-- Check current connectionsSELECT count(*) FROM v$session;
-- Check for blocking sessionsSELECT blocking_session, sid, serial#, wait_class, eventFROM v$sessionWHERE blocking_session IS NOT NULL;
-- Check system loadSELECT * FROM v$system_eventWHERE event LIKE '%TNS%' OR event LIKE '%send%';
Resolution Steps
Section titled “Resolution Steps”Network Troubleshooting
Section titled “Network Troubleshooting”1. Verify Network Connectivity
Section titled “1. Verify Network Connectivity”# Step-by-step network verificationping -c 4 database_server
# If ping fails, check network configurationifconfig # Linux/Unixipconfig # Windows
# Check routing tableroute -n # Linux/Unixroute print # Windows
2. Firewall Configuration
Section titled “2. Firewall Configuration”# Linux iptables - allow Oracle portsudo iptables -A INPUT -p tcp --dport 1521 -j ACCEPTsudo iptables -A OUTPUT -p tcp --sport 1521 -j ACCEPT
# Windows Firewall - create rule for Oraclenetsh advfirewall firewall add rule name="Oracle Database" dir=in action=allow protocol=TCP localport=1521
# Check current firewall rulessudo iptables -L -n # Linuxnetsh advfirewall firewall show rule name=all # Windows
3. Port and Service Verification
Section titled “3. Port and Service Verification”# Check if Oracle listener is running and listeningnetstat -an | grep 1521 # Linux/Unixnetstat -an | findstr 1521 # Windows
# Check process listening on portlsof -i :1521 # Linux/Unixnetstat -ano | findstr :1521 # Windows
# Verify listener processps -ef | grep tnslsnr # Linux/Unix
Oracle Configuration Fixes
Section titled “Oracle Configuration Fixes”1. Listener Configuration
Section titled “1. Listener Configuration”# Check listener.ora configurationcat $ORACLE_HOME/network/admin/listener.ora
# Sample listener.oraLISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = server_name)(PORT = 1521)) ) )
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = ORCL) (ORACLE_HOME = /u01/app/oracle/product/19.0.0/dbhome_1) ) )
# Restart listenerlsnrctl stoplsnrctl start
2. Client Configuration (tnsnames.ora)
Section titled “2. Client Configuration (tnsnames.ora)”# Verify tnsnames.ora entrycat $TNS_ADMIN/tnsnames.ora
# Sample tnsnames.ora entryORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = database_server)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl.domain.com) ) )
# Test the connectiontnsping ORCLsqlplus username/password@ORCL
3. SQL*Net Configuration (sqlnet.ora)
Section titled “3. SQL*Net Configuration (sqlnet.ora)”# Check sqlnet.ora settingscat $TNS_ADMIN/sqlnet.ora
# Recommended sqlnet.ora settings for network issuesSQLNET.EXPIRE_TIME = 10SQLNET.RECV_TIMEOUT = 600SQLNET.SEND_TIMEOUT = 600TCP.CONNECT_TIMEOUT = 60TCP.NODELAY = yes
# Disable features that might cause issuesNAMES.DIRECTORY_PATH = (TNSNAMES, EZCONNECT)SQLNET.AUTHENTICATION_SERVICES = (NONE)
Advanced Troubleshooting
Section titled “Advanced Troubleshooting”1. Network Packet Analysis
Section titled “1. Network Packet Analysis”# Capture network packets (requires root/admin)tcpdump -i any -w oracle_traffic.pcap host database_server and port 1521
# Windows equivalentnetsh trace start capture=yes tracefile=oracle_traffic.etl provider=Microsoft-Windows-TCPIP
# Analyze with Wiresharkwireshark oracle_traffic.pcap
2. SQL*Net Tracing
Section titled “2. SQL*Net Tracing”# Enable detailed tracing in sqlnet.oraTRACE_LEVEL_CLIENT = 16TRACE_DIRECTORY_CLIENT = /tmp/traceTRACE_FILE_CLIENT = sqlnet_clientTRACE_UNIQUE_CLIENT = ON
# Server-side tracingTRACE_LEVEL_SERVER = 16TRACE_DIRECTORY_SERVER = /tmp/traceTRACE_FILE_SERVER = sqlnet_server
# After reproducing issue, check trace filesls -la /tmp/trace/
3. Connection Multiplexing
Section titled “3. Connection Multiplexing”# Add connection multiplexing to listener.oraUSE_SHARED_SOCKET_LISTENER = TRUECONN_SHARE_LISTENER = TRUE
# Or use connection manager (CMAN)# Configure connection manager for connection multiplexing
Application-Level Solutions
Section titled “Application-Level Solutions”Connection Retry Logic
Section titled “Connection Retry Logic”// Java example with retry logicpublic Connection getConnection() throws SQLException { int maxRetries = 3; int retryDelay = 1000; // 1 second
for (int attempt = 1; attempt <= maxRetries; attempt++) { try { return DriverManager.getConnection( "jdbc:oracle:thin:@database_server:1521:ORCL", username, password ); } catch (SQLException e) { if (e.getErrorCode() == 12150 && attempt < maxRetries) { try { Thread.sleep(retryDelay * attempt); // Exponential backoff } catch (InterruptedException ie) { Thread.currentThread().interrupt(); throw new SQLException("Connection retry interrupted", ie); } continue; } throw e; } } return null;}
Connection Pool Configuration
Section titled “Connection Pool Configuration”// Connection pool settings for network issuesHikariConfig config = new HikariConfig();config.setJdbcUrl("jdbc:oracle:thin:@database_server:1521:ORCL");config.setUsername(username);config.setPassword(password);
// Network timeout settingsconfig.setConnectionTimeout(30000); // 30 secondsconfig.setValidationTimeout(5000); // 5 secondsconfig.setIdleTimeout(600000); // 10 minutesconfig.setMaxLifetime(1800000); // 30 minutes
// Pool sizingconfig.setMinimumIdle(5);config.setMaximumPoolSize(20);
// Connection validationconfig.setConnectionTestQuery("SELECT 1 FROM DUAL");
Application Timeout Settings
Section titled “Application Timeout Settings”# Python cx_Oracle exampleimport cx_Oracle
def create_connection(): dsn = cx_Oracle.makedsn("database_server", 1521, service_name="orcl")
connection = cx_Oracle.connect( user=username, password=password, dsn=dsn, # Network timeout settings tcp_connect_timeout=60, retry_count=3, retry_delay=1 )
return connection
Monitoring and Prevention
Section titled “Monitoring and Prevention”Network Monitoring Script
Section titled “Network Monitoring Script”#!/bin/bash# Oracle network connectivity monitor
DB_HOST="database_server"DB_PORT=1521LOG_FILE="/var/log/oracle_network_monitor.log"
while true; do timestamp=$(date '+%Y-%m-%d %H:%M:%S')
# Test basic connectivity if nc -z -w5 $DB_HOST $DB_PORT; then echo "$timestamp: Connection to $DB_HOST:$DB_PORT successful" >> $LOG_FILE else echo "$timestamp: ERROR - Cannot connect to $DB_HOST:$DB_PORT" >> $LOG_FILE # Send alert fi
# Test TNS ping if tnsping ORCL > /dev/null 2>&1; then echo "$timestamp: TNS ping successful" >> $LOG_FILE else echo "$timestamp: ERROR - TNS ping failed" >> $LOG_FILE fi
sleep 300 # Check every 5 minutesdone
Database-Side Monitoring
Section titled “Database-Side Monitoring”-- Create monitoring tableCREATE TABLE network_connection_log ( log_time TIMESTAMP, event_type VARCHAR2(50), client_info VARCHAR2(200), error_message VARCHAR2(4000));
-- Monitor connection eventsCREATE OR REPLACE TRIGGER trg_logon_monitor AFTER LOGON ON DATABASEBEGIN INSERT INTO network_connection_log VALUES ( SYSTIMESTAMP, 'SUCCESSFUL_LOGON', SYS_CONTEXT('USERENV', 'HOST') || ':' || SYS_CONTEXT('USERENV', 'IP_ADDRESS'), NULL ); COMMIT;EXCEPTION WHEN OTHERS THEN NULL; -- Don't let monitoring affect loginEND;/
Proactive Health Checks
Section titled “Proactive Health Checks”-- Database connectivity health checkCREATE OR REPLACE PROCEDURE check_network_health AS v_count NUMBER;BEGIN -- Check current connections SELECT COUNT(*) INTO v_count FROM v$session WHERE type = 'USER';
IF v_count = 0 THEN DBMS_OUTPUT.PUT_LINE('WARNING: No user sessions detected'); END IF;
-- Check for network-related wait events SELECT COUNT(*) INTO v_count FROM v$session_wait WHERE event LIKE '%TCP%' OR event LIKE '%send%' OR event LIKE '%receive%';
IF v_count > 0 THEN DBMS_OUTPUT.PUT_LINE('WARNING: Network-related wait events detected: ' || v_count); END IF;
-- Check listener status FOR rec IN ( SELECT program FROM v$session WHERE program LIKE '%LISTENER%' ) LOOP DBMS_OUTPUT.PUT_LINE('Listener process active: ' || rec.program); END LOOP;END;/
Emergency Procedures
Section titled “Emergency Procedures”Quick Network Recovery
Section titled “Quick Network Recovery”#!/bin/bash# Emergency network recovery script
echo "Starting Oracle network recovery procedure..."
# Restart network servicesecho "Restarting network interface..."sudo ifdown eth0 && sudo ifup eth0
# Restart Oracle listenerecho "Restarting Oracle listener..."export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1export PATH=$ORACLE_HOME/bin:$PATHlsnrctl stopsleep 5lsnrctl start
# Test connectivityecho "Testing connectivity..."if tnsping ORCL; then echo "TNS connectivity restored"else echo "TNS connectivity still failing"fi
# Check database accessibilityif sqlplus -s / as sysdba <<< "SELECT 'DATABASE_OK' FROM dual;" | grep -q "DATABASE_OK"; then echo "Database accessible"else echo "Database access issues"fi
Connection Reset Procedure
Section titled “Connection Reset Procedure”-- Reset problematic connectionsBEGIN FOR rec IN ( SELECT sid, serial# FROM v$session WHERE status = 'INACTIVE' AND last_call_et > 3600 -- Inactive for more than 1 hour AND program NOT LIKE '%background%' ) LOOP BEGIN EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION ''' || rec.sid || ',' || rec.serial# || ''' IMMEDIATE'; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Failed to kill session: ' || rec.sid); END; END LOOP;END;/
Performance Optimization
Section titled “Performance Optimization”Network Performance Tuning
Section titled “Network Performance Tuning”# TCP kernel parameters for Oracle (Linux)# Add to /etc/sysctl.confnet.core.rmem_default = 262144net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576net.ipv4.tcp_rmem = 4096 65536 4194304net.ipv4.tcp_wmem = 4096 65536 4194304
# Apply changessudo sysctl -p
Oracle Network Parameters
Section titled “Oracle Network Parameters”-- Database network optimizationALTER SYSTEM SET processes=500 SCOPE=BOTH;ALTER SYSTEM SET sessions=555 SCOPE=BOTH;
-- Connection timeout settingsALTER SYSTEM SET sqlnet.expire_time=10 SCOPE=BOTH;
Related Errors
Section titled “Related Errors”- TNS-12151: TNS received no data
- TNS-12152: TNS unable to send break message
- TNS-12571: TNS packet writer failure
- ORA-03113: End-of-file on communication channel
Best Practices
Section titled “Best Practices”- Implement connection retry logic in applications
- Monitor network connectivity continuously
- Configure appropriate timeout values
- Use connection pooling effectively
- Regular network infrastructure maintenance
- Implement proper firewall rules
Troubleshooting Checklist
Section titled “Troubleshooting Checklist”- Test basic network connectivity (ping)
- Verify Oracle listener is running
- Check firewall and port accessibility
- Validate TNS configuration files
- Test with tnsping and sqlplus
- Review Oracle and system logs
- Check network performance metrics
- Implement connection retry logic