Connecting the dots for the Oracle DBA

You are here:

Exploring the Oracle LOCAL_LISTENER Parameter

In my previous post, Registering the Oracle Database with the listener, I mentioned the role of the initialization parm LOCAL_LISTENER in dynamic registration of the database instance to the listener. Now I’d like to deliver on my promise to explore that piece of the puzzle.

To quickly recap that post, there are two methods by which a listener comes to know what databases it can service. In Oracle terminology, this is referred to as “registering with the listener.”

Static Instance Registration

The first – and older – method is static registration. In this method, the instance is listed in the SID_LIST section of the listener’s configuration file, “listener.ora”. Such a registration would show in the listener.ora like this:

At Fig. 2, line 24, the status is UNKNOWN because there is no mechanism to guarantee that the specified instance even exists. The listener just assumes that the instance will be there when a connect request is received. In fact, my database was down when I took the status shown in Fig. 2.

Dynamic Instance Registration

With version 9.0 Oracle introduced the concept of dynamic registration. With this, it is no longer necessary to list the database instance in the listener.ora file. Instead, the database instance contacts the listener directly and registers itself. We can observe the result of that in the listener status. First, I’ll “remove” my listner.ora by renaming it, then restart the listener and see what it says about itself. The listener is quite capable of running without a listner.ora file at all. It will simply start and run with all default values.

In Fig. 4, line 1, a tnsping proves that our tnsnames resolution is correct. But at line 23 we see that an actual attempt to connect to the service proves the listener doesn’t know anything about the service “tulsa”.

In Fig. 5 we observe that once the instance is started (line 9), when we re-check the listener (line 24) it now knows of service “tulsa”, with a status of READY (line 45). This obviously did not come from listener.ora as I had removed that file. Notice also that, unlike the static registration, this time the status is READY. The listener knows the instance is ready because the instance itself told the listener it was ready. And we can prove it by establishing a connection from a remote system:

The LOCAL_LISTENER initialization parameter

So we’ve seen that the listener is able to start up and successfully handle connection requests without a listener.ora configuration file. It does this by using all defaults (including the listener name and port) and the database instance is able to register itself with the listener.

How does the instance know how to contact the listener in order to register itself? It uses the initialization parameter LOCAL_LISTENER. From the Oracle® Database Reference 12c we read

LOCAL_LISTENER specifies a network name that resolves to an address or address list of Oracle Net local listeners

OK, so the instance is supposed to use LOCAL_LISTENER to locate the listener so that it (the instance) can register itself with the listener. But I don’t have LOCAL_LISTENER set to anything. Well, it so happens that LOCAL_LISTENER has a default value that dovetails nicely with the default settings of the listener. Again, from the Reference manual:

Default value: (ADDRESS = (PROTOCOL=TCP)(HOST=hostname)(PORT=1521)) where hostname is the network name of the local host.

I’ve seldom found a good reason NOT to run the listener with anything other the default name and port, but some people insist, and that’s when we need to adjust LOCAL_LISTENER to match up. So let’s set up a test case.

First, I’ll set my listener to use a non-default port. Notice I’ve also removed the SID_LIST section entirely.

At this point my listener is up, listening on the non-default port of 1522 (line 28) and knows of no services. With a default setup, I should be able to connect to the database and force a registration. Remember that at this point, my listener is using the non-default port of 1522, while the database is still trying to contact the listener on the default port of 1521.

In order to enable the instance to register with the non-default listener, we need to set LOCAL_LISTENER to an appropriate value. Remember from the documentation that “LOCAL_LISTENER specifies a network name that resolves to an address or address list of Oracle Net local listeners”. So let’s set it:

So by setting LOCAL_LISTENER to the values appropriate for the listener, it is again able to contact the listener and register its services.

Did it occur that the setting of LOCAL_LISTENER looks a lot like an entry in tnsnames.ora? Remember that the description of LOCAL_LISTENER “specifies a network name that resolves to an address …” (emphasis mine). As a matter of fact, we can use a tnsnames entry instead of hardcoding the address in LOCAL_LISTENER. To do this, we need to create a special entry in the tnsnames.ora file on the server, then set LOCAL_LISTENER to point to that entry. Unlike the usual tnsnames entry that points to a database service, this entry will point to the listener itself. (By the way, it is often said that the tnsnames.ora file is used only by client processes. This use of tnsames by the database instance is no exception. At this point the instance is acting in the role of a client, just as it does when using a database link to access data on another database.)

Let’s create the tnsnames entry, and test it with tnsping. I’ll add the entry FUBAR for this.

In reality I’d want to make the tnsnames alias something more meaningful, but here I wanted to use a name that would very obviously not be some reserved or default “magic” value. Notice that since FUBAR is used to locate the listener itself (rather than the services of a database instance) we do not need to include the CONNECT_DATA section.

Now that we have a tnsnames entry that points specifically to the listener, let’s prove it out.

Conclusion

I’ve shown how it is possible for the listener to operate without the use of the listener.ora configuration file. I have also shown how the database instance registers itself with the listener with both default and non-default settings, and how the instance uses the LOCAL_LISTENER initialization parameter and the tnsnames.ora file to locate the listener for self-registration.

I would also like to point out that for the purposes of this demo, I never mixed static and dynamic registrations. I did that to make it perfectly clear that the two are separate and distinct and not inter-related. However, I also need to point out that this does not mean that the two are mutually exclusive. It is actually rather normal to have both at the same time. When doing so, the listener will report both:

At this point I have covered just about the entire range of TNS configuration items that cause the vast majority of Oracle database connection issues. In previous posts I covered the “configuration chain” from the initial client connection request, through the network routing, through the listener, to the database instance. In this post I have shown the configuration issues that lead to the listener knowing what database instances it is supposed to be able to service. Hopefully, this series will be of help to those faced with the original question, “Why can’t I connect to my database?”

25 Comments

Thanks for your blog on local_listener, particularly your comment on default value of local_listener. With the help of your blog, I was able to start another listener.ora with different port#, create tnsnames entry, set it to local_listener and issue alter system register. It allowed me to access different services which were already created for different pdbs I was experimenting with.

I’m glad you found it helpful. I am a bit curious as to why you want an additional listener with a different port. A single listener is quite capable of –i indeed, was designed to — service multiple databases of multiple versions running from multiple homes. I know there are a few cases where it might be desirable to have multiple listeners, but they are very, very few. I’d be happy to discuss your reasoning and see if there’s something we can both learn from it.

Excellent article! Thank you. I’m a long-time Oracle DBA, but I’ve just been struggling with getting a single listener working as desired on a new, single-node (non-RAC) 12c container database server that uses ASM. I had no ASM experience before this, so I wasn’t used to having the listener in the Grid_home and the database running from a separate Oracle_home. Your article clearly explains how this can work. The important parts are: a tnsnames.ora entry for the listener, setting the “local_listener” parameter to that tns entry, then running the “alter system register” command.

Mark – I’m glad you found the article helpful.
Actually, you don’t really need the tnsnames entry. If you’ll notice, all that really resolves to is a host (ip address) and a port. The database registration doesn’t know or care which ORACLE_HOME the listener is running out of. It just sends a request to the specified port on the specified host. If there is a listener on that host, listening on that port, we’re good to go. And by default, if there is no value for LOCAL_LISTENER, the instance will send the registration notice to port 1521. I really don’t know why Oracle specifies that the listener should run from the GI home, but since they do, I do.

Another excellent article. As an Oracle developer not DBA I am still required to undertake these tasks and find it frustrating. In my case I needed to read the previous 2 articles and this one in order to diagnose the problem. This is the clearest explanation I have seen. It really shows the inadequacies of Oracle diagnostics and their refusal to provide out of the box solutions. It all starts broken and works if you are lucky, At last some clarity.

I’m glad my articles could help clarify things. I won’t get into a debate over your comments about Oracle itself. Just keep in mind that it is implemented on multiple, disparate platforms (Windows, multiple unix/linux, IBM Z-OS, etc.) and as such is not developed with a Windows-centric view of the world. I will admit that sometimes I find the official docs to be a bit of “you have to understand everything to be able to understand anything”. But that comes from providing everything. I find MS documentation to be at the opposite end of the spectrum. I see their approach one of “click here. If the action we built into the icon doesn’t do what you want, then you want the wrong thing. Don’t ask what it’s doing under the covers. You don’t need to know. It just works.” Until it doesn’t “just work”. 🙂

Well there is a teensy it of a debate afoot all the same, I shall be brief. I can see the other point of view, including multiple platforms and configurations,and agree MS i the other extreme. You can;t roll your sleeves up and call for the hot water and towels when that does wrong. Yet what you have provided here is somewhat at odds with your defence of our giant corporation. You have worked examples, diagnostics, and an inclusion of all relevant context as oppose to being tossed into another document, for which I commend you.

I am suddenly getting error “TNS: listener does not currently know of service…” whatever I do. I tried to follow exercises in this article but the error is always there – e.g. for: sqlplus / as sysdba. It is on Oracle DB Developer VM box with default cdb1 instance and orcl. They are not registering with listener. How can I tell that oracle is running at all?
Thank you for any help.

You should not be getting any listener errors for a simple ‘sqlplus / a sysdba’. That connection syntax is requesting a bequeath connection that does not use the listener. You say you are “suddenly” getting this error. When was the last time it worked and what has changed since? Since you say this is an “Oracle DB Developer VM box” I assume it is running Linux. With that, you can tell the db is at least in START mode by issuing ‘ps -ef | grep pmon ‘. That should list the pmon process for any started databases. I could tell more if you would show the output of that command, as well as the following:

====
There were no software changes from last time it was working, last thing I was copying a database from other VM using SQL Developer, no issue that I am aware of, then I was not using it for a few months just now

The only way I can reproduce a tns error with a simple ‘sqlplus / as sysdba” (not specifying a net service name) is if I also export the variable TWO_TASK. See my article Another Ora-12514 and TWO_TASK.

Hello,
db is not registered against listener and there is no process indicating oracle db is running.
Look at /etc/oratab for the name of db/instance.
If you are in RAC env, you have to connect to each instance (instance name included instance number).
set ORACLE_HOME with what you find (db_name or instance_name)
issue “. oraenv”
try you sqlplus / as sysdba
Kind regards.

I’ve never relied on dbstart to startup my databases. My feeling is that if I’ve had to shut down a server, I want to check things out after the restart, before I start the databases. But giving that script a cursory look, I’m inclined to believe that the problem stems from having set TWO_TASK, as mentioned in my previous reply. It will take me some time to try to work out a definitive answer.

Thanks for the concise information. After reading this article, I no longer have to stumbled through my TNS configuration steps; and I just might be better at troubleshooting these kind of things in the future.

Thanks. Helped me in diagnosing a 12cR2 installation where I’d got (not sure, yet, if it was me or the installer) a value in LOCAL_LISTENER pointing at a TNS entry, which was obviously hard coded to the local host and which, when I cloned the container (I run various containers on Proxmox), it didn’t work. I don’t think I had to do anything special on 12cR1 to get this to work, so I’m wondering if things changed between R1 and R2 of 12.

Anyway, by blanking out the LOCAL_LISTENER value I got things to work nicely, so thank you.

I’ve not seen 12.2 and haven’t dipped my toes into 12.1 very much, but I can’t imagine any of this changing there. I haven’t seen it change anywhere across any of the other versions I’ve worked with. Glad the article helped. Without being able to observe everything you did along the way, it would be hard to speculate on why it didn’t work the first time.

Disclaimer

The views expressed here are my own and do not necessarily reflect the views of any other individual, business entity, or organization. The views expressed by visitors on this blog are theirs solely and may not reflect mine.