Interesting one today:
This is part of the series on Replication set up using T-SQL. The full list is here.
Today, we’ll go over setting up Distributor using T-SQL. This is the first step in our replication configuration process.
The major steps in setting up Distributor are:
- Configure an instance as Distributor
- Create Distributor database
- Add the instances that will use this instance as a distributor
For this example, we’ll move forward with remote distributor a.k.a. Publisher, Subscriber & Distributor are on dedicated instances.
To accomplish the above steps, we use the following T-SQL procedures:
- sp_adddistributor
- sp_adddistributiondb
- sp_adddistpublisher
1. sp_adddistributor
For setting up replication, the first step we need to configure is setting up Distributor. Go to the Distributor instance, and enable the instance as a Distributor.
--
-- Enable the instance as Distributor
--
use master
exec sp_adddistributor @distributor = N'InstanceName'
, @password = N'distributor_admin password'
GO
2. sp_adddistributiondb
Next step is to create Distribution database in the Distributor instance to hold all the replication traffic.
--
-- Create Distribution database
--
use master
exec sp_adddistributiondb @database = N'SalesDistribution'
, @data_folder = N'E:\MSSQL\Data'
, @data_file = N'SalesDistribution.mdf'
, @data_file_size = 4096
, @log_folder = N'E:\MSSQL\Data'
, @log_file = N'SalesDistribution.LDF'
, @log_file_size = 2048
, @min_distretention = 0
, @max_distretention = 120
, @history_retention = 120
, @security_mode = 1
GO
Most of the parameters are self-explanatory; So, we’ll look at brief descriptions.
Following set of parameters indicate the name of the Distribution database with location for its data & log files with initial sizes.
-
- @database
- @data_folder
- @data_file
- @data_file_size
- @log_folder
- @log_file
- @log_file_size
The next set of parameters, indicate the duration for retention of replication traffic (transactions & commands) and retention for history log entries.
-
- @min_distretention
- @max_distretention
- @history_retention
The last parameter, shows the authentication mechanism for communicating with the Distributor.
- @security_mode : 1 indicates Windows Authentication; 0 indicates Sql Authentication (default)
3. sp_adddistpublisher
Now that Distribution database is configured, lets inform the distributor about the Publishers that it will rely on it (this Distributor).
--
-- Associate Distributor with Publishers
--
exec sp_adddistpublisher @publisher = N'PublisherName'
, @distribution_db = N'SalesDistribution'
, @publisher_type = N'MSSQLSERVER'
, @working_directory = N'E:\MSSQL\ReplData'
, @security_mode = 1
, @thirdparty_flag = 0
GO
The first four parameters indicate the name of the Publisher instance; And if it is Sql Server Publisher (or Oracle, etc); Working directory indicates where the replication data is stored while being communicated between Publisher and Distributor; And the name of the Distribution database.
-
- @publisher
- @distribution_db
- @publisher_type
- @working_directory
The next two parameters indicate the authentication mechanism used by Replication Agents to communicate with Publisher (for Queued Updating Subscriptions); And
-
- @security_mode
- @thirdparty_flag : Indicates if Publisher is Sql Server or non-Sql Server instances (i.e. Oracle, etc)
Read Full Post »