15.2 Using the TNSPING Utility to Test Connectivity from the Client

The TNSPING utility determines whether the listener for a service on an Oracle Net network can be reached successfully.

If you can connect successfully from a client to a server (or a server to another server) using the TNSPING utility, then it displays an estimate of the round trip time (in milliseconds) it takes to establish a SQLNET connection to the Oracle listener corresponding to the server.

If it fails, then it displays a message describing the error that occurred. This enables you to see the network error that is occurring without the overhead of a database connection.

Use the following command to test connectivity:
tnsping net_service_name count

In the preceding command, the following arguments are used:

  • net_service_name must exist in tnsnames.ora file or the name service in use, such as NIS.

  • count determines how many times the program attempts to reach the server. This argument is optional.

If the network service name specified is a database name, then TNSPING attempts to contact the corresponding listener. It does not actually determine whether the database is running. Use SQL*Plus to attempt a connection to the database.

The following are some examples of TNSPING.

Note:

Different platforms may have different interfaces, but the program accepts the same arguments. Invoke TNSPING for the display of the proper interface requirements.

Example 15-1 is an example of checking a listener for a database using a network service name of sales using the TNSPING command.

Example 15-1 Checking a Listener with TNSPING

TNSPING sales

This produces the following message:

TNS Ping Utility for Linux: Version 23.4.0.0.0 - Production on 21-MAR-2024 

Copyright (c) 1997, 2024 Oracle Corporation.  All rights reserved.

Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL =
TCP)(HOST = sales-server)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME =
sales.us.example.com)))
OK (10 msec)

To determine whether the listener for the sales database is available, and to specify that TNSPING try to connect eight times and then give up, use the following syntax:

tnsping sales 8

This command produces the following message:

TNS Ping Utility for Linux: Version 23.4.0.0.0 - Production on 21-MAR-2024 

Copyright (c) 1997, 2024 Oracle Corporation.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL =
TCP)(HOST = sales-server)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME =
sales.us.example.com)))
OK (10 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
OK (10 msec)
OK (10 msec)
OK (10 msec)
OK (0 msec)

Example 15-2 is an example of TNSPING attempting to check using an invalid network service name.

Example 15-2 Checking an Invalid Net Service Name with TNSPING

tnsping badname

This attempt produces the following message:

TNS Ping Utility for Linux: Version 23.4.0.0.0 - Production on 21-MAR-2024 

Copyright (c) 1997, 2024 Oracle Corporation.  All rights reserved.

Used parameter files:

TNS-03505: Failed to resolve name

Example 15-3 is an example of output when using TNSPING to check a name that is valid, but resolves to an address where no listener is located, for example, the listener may not be started.

Example 15-3 Checking Valid Net Service Name but No Listener with TNSPING

tnsping sales

TNS Ping Utility for Linux: Version 23.4.0.0.0 - Production on 21-MAR-2024 

Copyright (c) 1997, 2024 Oracle Corporation.  All rights reserved.

Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL =
TCP)(HOST = 10.9.7.5)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME =
sales.us.example.com)))
TNS-12541: TNS:Cannot connect. No Listener at host 10.9.7.5 port 1521