During a recent troubleshooting, we came across a requirement where we wanted to know what all locations does Oracle searches tnsnames.ora ? So writing this quick post for the analysis that we did and the results we reached during this exercise.
You might already aware of tnsnames.ora in path defined by TNS_ADMIN variable and default $ORACLE_HOME/network/admin path but are these the only 2 locations (Spoiler Alert, there are 4..!!) and what’s the order in which Oracle searches for tnsnames.ora in case both these locations had a different versions of tnsnames.ora file present.
For our exercise, we set the TNS_ADMIN variable as /home/oracle/nitish but did not created any tnsnames.ora file and similarly ensured that there is no tnsnames.ora in $ORACLE_HOME/network/admin path too. And then ran a strace on TNSPING:
strace tnsping TEST
I am just using an excerpt of the output below in our discussion but you can download the complete output to see what all is happening in the background.
Excerpt from strace output:
- access(“/home/oracle/nitish/sqlnet.ora”, F_OK) = -1 ENOENT (No such file or directory)
- access(“/apps/oracle/server/126.96.36.199/dbhome_1/network/admin/sqlnet.ora”, F_OK) = -1 ENOENT (No such file or directory)
- access(“/home/oracle/.tnsnames.ora”, F_OK) = -1 ENOENT (No such file or directory)
- access(“/home/oracle/nitish/tnsnames.ora”, F_OK) = -1 ENOENT (No such file or directory)
- access(“/etc/tnsnames.ora”, F_OK) = -1 ENOENT (No such file or directory)
- access(“/apps/oracle/server/188.8.131.52/dbhome_1/network/admin/tnsnames.ora”, F_OK) = -1 ENOENT (No such file or directory)
Observations from strace excerpt:
- In Line 1, Server Process first checks for sqlnet.ora in the path set by TNS_ADMIN variable but did not find the file.
- In Line 2, it checks for sqlnet.ora in $ORACLE_HOME but did not find the file.
- In Line 3, it then looks for tnsnames.ora in /home/oracle/.tnsnames.ora (Software Owner’s home directory) still doesn’t find the file.
- In Line 4, it then looks for tnsnames.ora in the path specified by TNS_ADMIN variable and as expected still doesn’t find the file.
- In Line 5, It then looks for tnsnames.ora in /etc/tnsnames.ora and again didn’t find the file.
- In Line 6, it then finally looks for tnsnames.ora in $ORACLE_HOME/network/admin.
So, the sequence in which Server Process looks for tnsnames.ora is:
- Oracle Software Owner’s home directory. (but the filename is .tnsnames.ora (hidden file) )
- Path specified by TNS_ADMIN variable.
Hope you find this post helpful, please let us know in comments if you have any further questions on this post or tnsnames.ora.