Thursday , December 26 2024

Readable Secondary On SQL Server Always On Availability Group

 

In Always On Availability Group Architecture, you can read from the Secondary Server.

So how do you use it in your applications?

In this article we will be examining the details of this issue.

For example, you have two nodes SQLNODE01\INSTANCE01 and SQLNODE02\INSTANCE01.

And between these two nodes, an availability group named AG1 is defined.

Primary Instance is the SQLNODE01\INSTANCE01. The AG1 uses 1435 as a port.

First, you should execute the below script.

Open the cmd command line and type “ping SQLNODE01” and type the name you see on the command line instead of “SQLNODE01.mydomain.com”.

 

With the above script, we activated the read intent option and made the route operations.

You should add “ApplicationIntent = ReadOnly” at the end of the connection string for queries that are intended to be read from the application.

If you are going to connect via SSMS, you must first click on Options to add the database name you want to access to the Connect To Database section and add “ApplicationIntent = ReadOnly” to the Additional Connection Parameters section.

In this way read only connetions will be directed to the secondary server. In this way, you can distribute the select load or forward your report queries to your secondary server.

Before SQL Server 2016, if there are more than one replica, the Selects will go to the first read only replica. With SQL Server 2016, read operation can be done by distributing it to secondary servers in load balancing logic. You can configure it as follows.

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *