Navigation Bar

Saturday, August 12, 2023

How scan listener works in RAC

 SCAN (single client access name) is the virtual hostname for all clients to connect to the cluster. SCAN is a domain name registered to at least one and upto three IP addresses. SCAN can be setup using either DNS or GNS. Thus client sends a connection request with a scan name, which first hits the DNS server. SCAN listeners are simply used for redirecting requests from the client to the local listeners. This is a lightweight process as compared to the functioning of NODE VIP listeners which fork a new process to establish a database connection. DNS server resolves this SCAN name to the first available IP and port whose default name is LISTENER_SCAN1. Since all cluster services and DB instances are registered by PMON with the  SCAN listener and the local listener on each node, the listener SCAN1 uses details from the load balancing advisory (LBA) to identify the least loaded node which can provide the required service to the client, and thus redirects the client request to the local listener on that node which spawns a process to establish a connection between the client and the node.




By default the name used by the SCAN is the same as the name used for the cluster and must be unique. For the installation to succeed, the SCAN must resolve to at least one IP address. There can be a maximum of 3 IP addresses that can be used for a SCAN.                                    

 The SCAN VIP must be on the same sub net as the virtual IP address and the public IP address.

SCAN IP addresses and SCAN listeners are managed as resources in Oracle clusterware. For high availability and scalability oracle recommends you use 3 SCAN IP addresses in a round robin manner.

SCAN listeners are started from the GRID ORACLE HOME and not the Database ORACLE HOME.

Prior to Oracle 11g, the details of each node would be added to the tnsnames.ora. So when a client makes a database connection request, the request would be sent to any one of the host names in the ADDRESS_LIST parameter.

Sample tnsnames.ora file for RAC prior to Oracle 11g

orac =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = host1-vip.localhost.com)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = host2-vip.localhost.com)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = host3-vip.localhost.com)(PORT = 1521))
      (LOAD_BALANCE = yes)
    )
    (CONNECT_DATA =
      (SID = orac)
    )
  )
The host name is resolved either from the hosts file or the DNS server file. Once the VIP of the host is known, the request is sent to the local listener on that host which forks a new connection. In this method, each time a node is added/deleted, both the tnsnames.ora file and the hosts file on each client has to be modified which is a cumbersome process.
To avoid this Oracle has introduced the concept of SCAN from Oracle 11g onwards.
Below is a sample tnsnames.ora file with SCAN 
orac =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = scan.localhost.com)(PORT = 1521))
      (LOAD_BALANCE = yes)
    )
    (CONNECT_DATA =
      (SID = orac)
    )
  )
The host in ADDRESS_LIST is resolved to any of 3 ip addresses. (in DNS or hosts file) with which the SCAN listeners are registered. These ips are selected in a round robin manner. In all there are 3 SCAN listeners running on any of the nodes in the cluster. So in a 2 node system 2 listeners will be running on one node and 1 listener on the second node. Some useful commands related to SCAN are given below
$nslookup scan.localhost.com
Output of this will give the 3 vip addresses registered with SCAN.
SQL>show parameter local_listener

SQL>show parameter remote_listener
$srvctl config scan
gives the scan names and vip related information
$srvctl config scan_listener
gives the listener scan names and ips
$crsctl stat res -w "TYPE=ora.scan_listener.type"
gives the name, type and status of each SCAN listener.
$ps -ef | grep tnsl
gives the background processes associated with both the local LISTENER and the SCAN LISTENER. If multiple scan listeners are running on that node both will get displayed.
$lsnrctl status LISTENER_SCAN1
Benefits 
Scan makes it possible to add or remove nodes from the cluster without needing to reconfigure the clients. This is because SCAN is associated with the cluster as a whole and not to any individual node.

References 

Thought for the day
Nothing will work unless you do
Maya Angelou

God's Word for the day 

  Foul language
There is a manner of speaking comparable to death;
  may it never be found in the inheritance of Jacob!
Such conduct will be far from the godly, and they
  will not wallow in sins. Do not accustom your
mouth to coarse, foul language, for it involves
  sinful speeck.
Sirach 22:27, 23:1-6

Gospel teachings of Jesus

Peter's declaration about Jesus
Now when Jesus came came into the district
  of Caesarea Philippi, he asked his disciples,
"Who do people say the Son of Man is? And
  they said, "Some say John the Baptist, but 
others Elijah, and still others Jeremiah, or one
  of the prophets." He said to them, "But who 
do you say that I am? Simon Peter answered,
  "You are the Messiah, the Son of the living
God." And Jesus answered him, "Blessed are
  you Simon, Son of Jonah! For flesh and 
blood has not revealed this to you, but my 
  Father in heaven. And I tell you, you are
Peter, and on this rock I will build my Church,
  and the gates of hades will not prevail against
it. I will give you the keys of the Kingdom of
  Heaven, and whatever you bind on Earth will
be bound in heaven, and whatever you loose on
  Earth will be loosed in Heaven." Then he 
sternly ordered the disciples not to tell anyone
  that he was the Messiah.
Mathew 16:13-20

No comments:

Post a Comment