Skip to content

ORA-12170 TNS Connect Timeout - Complete Resolution Guide

Error Text: ORA-12170: TNS:Connect timeout occurred

The ORA-12170 error occurs when an Oracle client cannot establish a connection to the database server within the specified timeout period. This typically indicates network connectivity issues, firewall restrictions, or server unavailability. It’s one of the most common connectivity errors encountered in Oracle environments.

  • Network path between client and server is down
  • Routing problems or network congestion
  • VPN connection issues
  • DNS resolution failures
  • Firewall blocking Oracle listener port (typically 1521)
  • Security group rules in cloud environments
  • Network ACLs restricting traffic
  • Oracle listener not running
  • Database server is down or unreachable
  • Listener overloaded with connections
  • Wrong port or host configuration
  • Incorrect tnsnames.ora entries
  • Wrong hostname or IP address
  • Invalid port number
  • SQLNET.ORA timeout settings too low
Terminal window
# Test basic network connectivity
ping database-server-hostname
# Test specific port connectivity
# Linux/Mac
nc -zv database-server-hostname 1521
# Windows (PowerShell)
Test-NetConnection -ComputerName database-server-hostname -Port 1521
# Alternative: telnet
telnet database-server-hostname 1521
Terminal window
# Verify DNS resolution
nslookup database-server-hostname
# Check /etc/hosts if using local resolution
cat /etc/hosts | grep database-server
# Windows
ipconfig /displaydns

Step 3: Check Oracle Listener (Server-Side)

Section titled “Step 3: Check Oracle Listener (Server-Side)”
Terminal window
# Check listener status
lsnrctl status
# Check listener on specific port
lsnrctl status LISTENER_1521
# Check if listener process is running
ps -ef | grep tnslsnr # Linux
tasklist | findstr tnslsnr # Windows

Step 4: Verify TNS Configuration (Client-Side)

Section titled “Step 4: Verify TNS Configuration (Client-Side)”
Terminal window
# Test TNS name resolution
tnsping SERVICE_NAME
# Check tnsnames.ora location
echo $TNS_ADMIN # Linux
echo %TNS_ADMIN% # Windows
# View tnsnames.ora content
cat $TNS_ADMIN/tnsnames.ora
Terminal window
# Verify route to database server
traceroute database-server-hostname # Linux/Mac
tracert database-server-hostname # Windows
# Check for packet loss
ping -c 100 database-server-hostname | grep loss
# Verify firewall isn't blocking (Linux)
sudo iptables -L -n | grep 1521
# Check Windows Firewall
netsh advfirewall firewall show rule name=all | findstr 1521
# Correct tnsnames.ora entry format
MYDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db-server.example.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = mydb.example.com)
)
)
# Common issues to check:
# - Typos in hostname
# - Wrong port number
# - Incorrect SERVICE_NAME vs SID
# - Missing closing parentheses
# - Extra spaces or hidden characters
# sqlnet.ora - Increase connection timeout
# Location: $TNS_ADMIN/sqlnet.ora or $ORACLE_HOME/network/admin/sqlnet.ora
# TCP connection timeout (seconds)
SQLNET.OUTBOUND_CONNECT_TIMEOUT = 60
# Total connection establishment timeout
SQLNET.INBOUND_CONNECT_TIMEOUT = 60
# Send timeout for established connections
SQLNET.SEND_TIMEOUT = 60
# Receive timeout for established connections
SQLNET.RECV_TIMEOUT = 60
Terminal window
# Stop listener
lsnrctl stop
# Start listener
lsnrctl start
# Reload listener configuration (without restart)
lsnrctl reload
# Check listener log for errors
tail -100 $ORACLE_BASE/diag/tnslsnr/$(hostname)/listener/trace/listener.log
Terminal window
# Linux - Allow Oracle port through firewall
sudo firewall-cmd --permanent --add-port=1521/tcp
sudo firewall-cmd --reload
# Or using iptables
sudo iptables -A INPUT -p tcp --dport 1521 -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 1521 -j ACCEPT
# AWS Security Group (via AWS CLI)
aws ec2 authorize-security-group-ingress \
--group-id sg-xxxxxxxxx \
--protocol tcp \
--port 1521 \
--cidr 10.0.0.0/8
Terminal window
# Check Security Group rules
aws ec2 describe-security-groups --group-ids sg-xxxxxxxxx
# Check Network ACLs
aws ec2 describe-network-acls --network-acl-ids acl-xxxxxxxxx
# Verify RDS endpoint
aws rds describe-db-instances --db-instance-identifier mydb \
--query 'DBInstances[0].Endpoint'
Terminal window
# Check NSG rules
az network nsg rule list --nsg-name myNSG --resource-group myRG
# Verify database endpoint
az sql server show --name myserver --resource-group myRG \
--query fullyQualifiedDomainName
Terminal window
# Check Security List
oci network security-list get --security-list-id ocid1.securitylist...
# Verify DB System endpoint
oci db system get --db-system-id ocid1.dbsystem... \
--query 'data.hostname'
-- Check registered services
SELECT inst_id, service_name, network_name
FROM gv$active_services
ORDER BY inst_id, service_name;
-- Check listener endpoints
SELECT * FROM v$listener_network;
-- Check database service registration
SELECT name, network_name, creation_date, pdb
FROM v$services;
-- Current connection count
SELECT COUNT(*) as current_connections
FROM v$session
WHERE type = 'USER';
-- Connection history (if AWR enabled)
SELECT snap_id, stat_name, value
FROM dba_hist_sysstat
WHERE stat_name LIKE '%logon%'
ORDER BY snap_id DESC
FETCH FIRST 10 ROWS ONLY;
-- Check for connection storms
SELECT machine, COUNT(*) as connection_count
FROM v$session
GROUP BY machine
ORDER BY connection_count DESC;
ParameterDescriptionRecommended
SQLNET.OUTBOUND_CONNECT_TIMEOUTInitial TCP connection timeout30-60 seconds
SQLNET.INBOUND_CONNECT_TIMEOUTServer-side accept timeout60 seconds
SQLNET.SEND_TIMEOUTData send timeout60 seconds
SQLNET.RECV_TIMEOUTData receive timeout60 seconds
# listener.ora timeout settings
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver)(PORT = 1521))
)
)
# Connection timeout
INBOUND_CONNECT_TIMEOUT_LISTENER = 60
# Logging and tracing
LOGGING_LISTENER = ON
TRACE_LEVEL_LISTENER = OFF
  • Can ping database server
  • Can reach port 1521 (or configured port)
  • DNS resolves correctly
  • No firewall blocking
  • VPN connected (if required)
  • Listener is running
  • Database is open
  • Service is registered with listener
  • Listener log shows no errors
  • tnsnames.ora is correct
  • TNS_ADMIN points to right location
  • tnsping succeeds
  • sqlnet.ora timeouts appropriate
-- Use connection pooling to reduce connection overhead
-- Example: Oracle DRCP (Database Resident Connection Pooling)
-- Enable DRCP
EXEC DBMS_CONNECTION_POOL.START_POOL();
-- Configure pool
EXEC DBMS_CONNECTION_POOL.ALTER_PARAM('', 'MAX_CONNECTIONS_PER_SHARD', '20');
EXEC DBMS_CONNECTION_POOL.ALTER_PARAM('', 'MAX_SESSIONS', '500');
-- Create monitoring for connection issues
CREATE OR REPLACE PROCEDURE check_listener_health AS
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM v$session
WHERE status = 'ACTIVE'
AND event LIKE '%listener%';
IF v_count > 10 THEN
-- Send alert
DBMS_OUTPUT.PUT_LINE('WARNING: Multiple sessions waiting on listener');
END IF;
END;
/
# tnsnames.ora with multiple addresses for failover
MYDB =
(DESCRIPTION =
(LOAD_BALANCE = ON)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = db1.example.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = db2.example.com)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = mydb)
)
)
# Quick connectivity test script
#!/bin/bash
HOST="database-server"
PORT=1521
echo "=== Network Test ==="
ping -c 3 $HOST
echo "=== Port Test ==="
nc -zv $HOST $PORT 2>&1
echo "=== TNS Test ==="
tnsping SERVICENAME
echo "=== DNS Test ==="
nslookup $HOST
  1. Check if server is up - Contact server/cloud team
  2. Check recent changes - Network, firewall, or security updates
  3. Review listener log - Look for rejection messages
  4. Try alternate connection - Use IP instead of hostname
  5. Escalate - Involve network team if network layer issue confirmed