Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server linked server performance

I am using SQL Server 2008 Enterprise. And I am using Linked Server technologies to link another SQL Server 2008 Enterprise instance from another server. I write TSQL to manipulate objects (e.g. tables) from both server instances.

My question is, for linked server, is there a big performance issue? If yes, what is the key performance bottleneck and best practice we should follow?

thanks in advance, George

like image 991
George2 Avatar asked Aug 08 '09 12:08

George2


People also ask

Is Openquery faster than linked server?

The OPENQUERY is faster than the linked server because when we use the linked server, the SQL Server breaks the query into local and remote queries. The local queries are executed on the local server, and remote queries will be sent to the remote server.

What is linked server in SQL Server?

Linked servers enable the SQL Server Database Engine and Azure SQL Managed Instance to read data from the remote data sources and execute commands against the remote database servers (for example, OLE DB data sources) outside of the instance of SQL Server.

What can I use instead of linked server?

The alternative to using Linked Servers is to use the OPENQUERY statement, also known as a pass through query. When using an OPENQUERY statement, the WHERE clause gets executed at the remote server and the resultant (mapped) records traverse over the wire instead of an entire sourced data set.

Are Linked servers secure?

Linked Servers are an easy way to connect between different SQL Server instances without too much hassle and application development overhead. But, if not configured correctly, they can also serve as a dangerous security vulnerability.


2 Answers

It depends on what you are doing.

If you are running queries that join between tables in the two server instances, and transferring large amounts of data, then you have a bottleneck that you need to be aware of.

If the servers are on their own subnet with a 1GB link, then you should not have to worry a great deal. I would be concerned if the two servers are connected by a shared, slow link.

like image 26
Mitch Wheat Avatar answered Sep 17 '22 15:09

Mitch Wheat


My question is, for linked server, is there a big performance issue? If yes, what is the key performance bottleneck and best practice we should follow?

Compared to what? For what queries? of course it all depends on what you are doing. For some queries the performance hit will be negligible for others massive.

There are a bunch of concerns you should keep in mind:

  • If you will be joining 2 tables from DB1 to 2 tables from DB2, and the tables are big, stuff can get ugly. At the end of the day, the queries will execute somewhere. The db will have to pull all the results in to the main DB and maintain transactional integrity on the main db. This can be really expensive.
  • If you start running distributed transactions stuff can get ugly, fast.
  • When joining stuff across servers your indexes on the remote server can be rendered useless. The data all has to move somewhere for the joins.
  • Linked server links can go down at unexpected times and lead to hard to diagnose bugs.

In the past I have found situations where it was a few orders of magnitude faster to move the remote data locally, and index it before joining into it.

like image 140
Sam Saffron Avatar answered Sep 18 '22 15:09

Sam Saffron