Oracle Instant Client,tnsping,tnsnames.ora and Oracle_home

Source: Internet
Author: User
Tags echo command

To connect to the Oracle database remotely, but not to fully install the Oracle client on its own computer, the lightweight client instant clients were downloaded to the Oracle website. This thing does not have a graphical interface, all rely on sqlplus remote connection server, so does not occupy the place, just satisfies me this kind of pursue "the simple is good" the obsessive-compulsive patient needs.

However, it may be that the server does not open the listening port, I tried various configurations on my own machine, including Tnsnames.ora,sqlnet.ora, and so on, the remote connection failed. In order to troubleshoot the problem, I first ping the server's external network address, found that no problem. Online said, light ping is not enough, but also to tnsping a bit.

Tnsping, just look at the name, it seems to be a kind of ping. However, this tool is only included in the full Oracle client, and if you install the instant client, you will not be able to use tnsping. I happen to use instant client, is it tragic? However, when I visited the Otn community, I found tnsping was not so mysterious. There's a post on the OTN community that says Tnsping, and I'm going to say it. the original post in https://community.oracle.com/thread/2434899?start=0&tstart=0, interested can see.

What tnsping can do is read the host and port parameters from the TNS connection string, open a socket connection, and then send a ping to the listener, and the listener responds with a pong. Tnsping cannot allow other parameters in the TNS connection string to take effect, determine the availability of the DB instance and database service, or determine whether parameters such as SIDs, SERVICE_NAME, or instance_name are valid. As can be seen, tnsping has never been a high-end tool, and many people use it to test the TNS connection string, which is just rotten.

Instant client does not have tnsping tools? It doesn't matter, because you can use Telnet

The front has been saying tnsping read the host and port parameters, the question is: Where are these parameters? To solve this problem, you have to mention a critical configuration file: Tnsnames.ora.

Tnsnames.ora is a configuration file that defines the various addresses that are required to establish a connection to a database. If you have a complete Oracle client installed, the configuration file should be located in the Oracle_home\network\admin directory. The form is as follows:

<addressname> = (DESCRIPTION = (   address_list = (     ADDRESS = (PROTOCOL = TCP) (Host = 

a complete Tnsnames.ora example is as follows:

ORA11 = (DESCRIPTION = (    address_list = (     ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1) (PORT = 1521))   (Connec T_data =   (service_name = ORA11)))

of course, if you install the instant client, the file does not exist, but you can completely build a Tnsnames.ora in a specific directory. tNsnames.ora has one copy on both the client and server side. I refer to the Http://orafaq.com/wiki/Tnsnames.ora for more detailed instructions. So, what did Tnsnames.ora do?

In fact, this configuration file is a bit like the hosts file inside our computer. This file is actually a configuration file, the role is to set some common URL domain name and its IP address mapping, when you enter a Web address in the browser domain name, press ENTER, the system first automatically from the Hosts file to find the IP address of the domain name, find and then open the address corresponding to the Web page If the corresponding IP address is not found, the system will submit the URL to the DNS domain name resolution server, the server resolves the corresponding IP address .

The Hosts file resolves the memory-friendly URLs to IP addresses, and tnsnames.ora the easy-to-remember TNS aliases to the connection strings. The format of the connection string is typically "(discription= (address=<address details>) (Connect_data=<database details>)". Comparing the Tnsnames.ora example given above, it can be seen that the Tnsnames.ora actually contains the so-called connection string. So when you use the Sqlplus telnet database, you can have two ways. One way is to completely write out the connection string, as follows:

Sqlplus Scott/[email protected] "(Description= (address= (protocol=tcp) (host=my-dev.mydomain.com) (port=1521)) ( Connect_data= (Sid=orcldev) (server=dedicated))) "

The other is to write the TNS alias directly, taking the Tnsnames.ora given above as an example:

Sqlplus Scott/[email protected]
Obviously, the second way is simpler. Especially when you need to log into the database frequently, with the configuration file will undoubtedly make your efficiency greatly improved, this is like you to compile convenient and write makefile file is the same.

just said, if you installed the instant client, it does not have tnsping tools, it's okay, you just understand what tnsping is doing on the line. In fact, it does only three things: 1. If you specify a TNS alias, it resolves the alias to a connection string (skip this step if you are using the full connection string directly when you log in); 2. Test the IP address of the listener you want to connect to based on the host parameter of the connection string; 3.

instant client also has a inconvenient place, mentioned earlier, that is, it did not bring Tnsnames.ora files. However, as I said earlier, you can build yourself a tnsnames.ora file. So, how does the Oracle client find the file? This will require you to add an environment variable named Tns_admin, save tnsnames.ora address. The system will find the corresponding tnsnames.ora file.

Finally, briefly oracle_home. This variable represents an Oracle installation directory, or an environment variable that points to the Oracle installation directory. Under Windows, if you want to see the current oracle_home, use the echo command. To add or set orfacle_home environment variables, use the SET command. Of course, Oracle_home can also be found in the registry, where the Hkey_local_machine\software\oracle may be. More specific content can be referenced in Http://orafaq.com/wiki/ORACLE_HOME.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.