Let's say you are a SQL Server database administrator working for a big corporation, which has hundreds of server instances. You have a bunch of agent jobs like the Ola's maintenance solution that you want to deploy on all the server instances in your company, and you like to manage those jobs across all the instances in a centralized master. Most database administrators believe it can only be done by 3rd party management tools. In fact, SQL Server Agent service has a built-in feature named Multi-server Administration (a.k.a. MSX/TSX) which was overlooked by most of you. In this blog post I would like to demonstrate how to use this feature to deploy and manage agent job in multiple target servers. For the sake of simplicity, I setup 3 server instances in my local PC: the default instance which will be the master server (MSX), while the other 2 instances named TargetSvr1 and TargetSvr2 will be the target servers (TSX). Let's start to see how to do it.
In the MSX, right-click SQL Server Agent > Multi Server Administration > Make this a Master.
Click Next in the welcome page, specify an operator email if you like, or just click Next to skip it.
Add the target servers, then click Next to continue.
It will check the server compatibility, click Close once all targets passed the checking.
Let this wizard to create the login in your master server if necessary. Next.
Review the configuration. Click Finish.
Oops! There's an error.
In order to overcome it, for simplicity let's modify the registry key as stated in the online document, for each of your target servers, set them to zero.
Do the above steps again. You should success.
Now we can try to create a multi-server job. In order to proof the job really being executed in all the target servers, let's create a simple table in a testing database on all the target servers first.
USE master
GO
CREATE DATABASE TestingDB
GO
USE TestingDB
GO
CREATE TABLE TestTable (col varchar(50));
GO
Refresh the SSMS Object Explorer, SQL Server Agent in master server becomes MSX, and those in target servers become TSX.
And there's a new folder, Multi-Server Jobs, inside the master server. Let's create a job there which insert a row into the testing table. Here's the job body:
DECLARE @s varchar(50) = CAST(GETDATE() AS varchar(50));
INSERT TestingDB..TestTable VALUES (@s);
In the target tab of the new job window, specify the target servers of this job.
The default polling interval of multi-server job is one minute, which means jobs will be deployed and executed in the target servers one minute after the deployment and job firing in master.
After one minute, refresh the object explorer, you will see the job is deployed in all targets.
Let's execute the job in the Master server.
After one minute, run a multi-server query in your targets, you should see the new row exists in all target servers.
You can also check the job history in the master server.
Please be reminded that MSX/TSX doesn't guarantee the job executions are at the same time among the targets.