title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | ms.custom | helpviewer_keywords | dev_langs | monikerRange | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Upgrade replication scripts (Replication SP) |
Learn how to use Replication Stored Procedures to upgrade the scripts used to programmatically configure a replication topology. |
MashaMSFT |
mathoma |
09/25/2024 |
sql |
replication |
how-to |
|
|
|
=azuresqldb-mi-current||>=sql-server-2016 |
[!INCLUDEsql-asdbmi] [!INCLUDEtsql] script files can be used to programmatically configure a replication topology. For more information, see Replication System Stored Procedures Concepts.
Important
Although you are not required to upgrade scripts that are executed by members of the sysadmin role, we recommend that you modify existing scripts as described in this topic. Specify an account that has minimum permissions for each replication agent as described in the "Permissions Required By Agents" section of the topic Replication Agent Security Model.
These security improvements, which enable more control over permissions by allowing you to explicitly specify the [!INCLUDEmsCoName] Windows accounts under which replication agent jobs are executed, affect the following stored procedures in existing scripts:
-
sp_addpublication_snapshot:
You should now supply the Windows credentials as
@job_login
and@job_password
when executing sp_addpublication_snapshot (Transact-SQL) to create the job under which the Snapshot Agent runs at the Distributor. -
sp_addpushsubscription_agent:
You should now execute sp_addpushsubscription_agent (Transact-SQL) to explicitly add a job and supply the Windows credentials (
@job_login
and@job_password
) under which the Distribution Agent job runs at the Distributor. In versions of [!INCLUDEssNoVersion] before [!INCLUDEssVersion2005], this was done automatically when a push subscription was created. -
sp_addmergepushsubscription_agent:
You should now execute sp_addmergepushsubscription_agent (Transact-SQL) to explicitly add a job and supply the Windows credentials (
@job_login
and@job_password
) under which the Merge Agent job runs at the Distributor. In versions of [!INCLUDEssNoVersion] before [!INCLUDEssVersion2005], this was done automatically when a push subscription was created. -
sp_addpullsubscription_agent:
You should now supply the Windows credentials as
@job_login
and@job_password
when executing sp_addpullsubscription_agent (Transact-SQL) to create the job under which the Distribution Agent runs at the Subscriber. -
sp_addmergepullsubscription_agent:
You should now supply the Windows credentials as
@job_login
and@job_password
when executing sp_addmergepullsubscription_agent (Transact-SQL) to create the job under which the Merge Agent runs at the Subscriber. -
sp_addlogreader_agent:
You should now execute sp_addlogreader_agent (Transact-SQL) to manually add the job and supply the Windows credentials under which the Log Reader Agent runs at the Distributor. In versions of [!INCLUDEssNoVersion] before [!INCLUDEssVersion2005], this was done automatically when a transactional publication was created.
-
sp_addqreader_agent:
You should now execute sp_addqreader_agent (Transact-SQL) to manually add the job and supply the Windows credentials under which the Queue Reader Agent runs at the Distributor. In versions of [!INCLUDEssNoVersion] before [!INCLUDEssVersion2005], this was done automatically when a transactional publication that supported queued updating was created.
In the security model introduced in [!INCLUDEssVersion2005], replication agents always make connections to the local instance of [!INCLUDEssNoVersion] with Windows Authentication using the credentials supplied in @job_name
and @job_password
. For information about the requirements of Windows accounts used when running replication agent jobs, see Replication Agent Security Model.
Important
When possible, prompt users to enter security credentials at runtime. If you store credentials in a script file, ensure that the file itself is secured.
-
In the existing script, before sp_addpublication (Transact-SQL), execute sp_addlogreader_agent (Transact-SQL) at the Publisher on the publication database. Specify the Windows credentials under which the Log Reader Agent runs for
@job_name
and@job_password
. If the agent will use [!INCLUDEssNoVersion] Authentication when connecting to the Publisher, you must also specify a value of 0 for@publisher_security_mode
and the [!INCLUDEssNoVersion] login information for@publisher_login
and@publisher_password
. This creates a Log Reader Agent job for the publication database.[!NOTE]
This step is only for transactional publications and is not required for snapshot publications. -
(Optional) Before sp_addpublication (Transact-SQL), execute sp_addqreader_agent (Transact-SQL) at the Distributor on the distribution database. Specify the Windows credentials under which the Queue Reader Agent runs for
@job_name
and@job_password
. This creates a Queue Reader Agent job for the Distributor.[!NOTE]
This step is only required for transactional publications that support queued updating subscribers. -
(Optional) Update the execution of sp_addpublication (Transact-SQL) to set any non-default values for parameters that implement new replication functionalities.
-
After sp_addpublication (Transact-SQL), execute sp_addpublication_snapshot (Transact-SQL) at the Publisher on the publication database. Specify
@publication
and the Windows credentials under which the Snapshot Agent runs for@job_name
and@job_password
. If the agent will use [!INCLUDEssNoVersion] Authentication when connecting to the Publisher, you must also specify a value of 0 for@publisher_security_mode
and the [!INCLUDEssNoVersion] login information for@publisher_login
and@publisher_password
. This creates a Snapshot Agent job for the publication. -
(Optional) Update the execution of sp_addarticle (Transact-SQL) to set any non-default values for parameters that implement new replication functionalities.
-
After executing the stored procedure that creates the subscription, ensure that you execute the stored procedure that creates a Distribution Agent job to synchronize the subscription. The stored procedure that you use will depend on the type of subscription.
-
For a pull subscription, update the execution of sp_addpullsubscription_agent (Transact-SQL) to supply the Windows credentials under which the Distribution Agent runs at the Subscriber for
@job_name
and@job_password
. This is done after the execution of sp_addpullsubscription. For more information, see Create a Pull Subscription. -
For a push subscription, execute sp_addpushsubscription_agent (Transact-SQL) at the Publisher. Specify
@subscriber
,@subscriber_db
,@publication
, Windows credentials under which the Distribution Agent runs at the Distributor for@job_name
and@job_password
, and a schedule for this agent job. For more information, see Specify Synchronization Schedules. This is done after the execution of sp_addsubscription. For more information, see Create a Push Subscription.
-
-
(Optional) In the existing script, update the execution of sp_addmergepublication (Transact-SQL) to set any non-default values for parameters that implement new replication functionalities.
-
After sp_addmergepublication (Transact-SQL), execute sp_addpublication_snapshot (Transact-SQL) at the Publisher on the publication database. Specify
@publication
and the Windows credentials under which the Snapshot Agent runs for@job_name
and@job_password
. If the agent will use [!INCLUDEssNoVersion] Authentication when connecting to the Publisher, you must also specify a value of 0 for@publisher_security_mode
and the [!INCLUDEssNoVersion] login information for@publisher_login
and@publisher_password
. This creates a Snapshot Agent job for the publication. -
(Optional) Update the execution of sp_addmergearticle (Transact-SQL) to set any non-default values for parameters that implement new replication functionalities.
-
After executing the stored procedure that creates the subscription, ensure that you execute the stored procedure that creates a Merge Agent job to synchronize the subscription. The stored procedure that you use will depend on the type of subscription.
-
For a pull subscription, update the execution of sp_addmergepullsubscription_agent (Transact-SQL) to supply the Windows credentials under which the Merge Agent runs at the Subscriber for
@job_name
and@job_password
. This is done after the execution of sp_addmergepullsubscription. For more information, see Create a Pull Subscription. -
For a push subscription, execute sp_addmergepushsubscription_agent (Transact-SQL) at the Publisher. Specify
@subscriber
,@subscriber_db
,@publication
, the Windows credentials under which the Merge Agent at the Distributor runs for@job_name
and@job_password
, and a schedule for this agent job. For more information, see Specify Synchronization Schedules. This is done after the execution of sp_addmergesubscription. For more information, see Create a Push Subscription.
-
The following is an example of a [!INCLUDEssVersion2000] script that creates a transactional publication for the Product table. This publication supports immediate updating with queued updating as failover. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_1.sql":::
The following is an example of upgrading the previous script, which creates a transactional publication, to run successfully for [!INCLUDEssVersion2005] and later versions. This publication supports immediate updating with queued updating as failover. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_2.sql":::
The following is an example of a [!INCLUDEssVersion2000] script that creates a merge publication for the Customers table. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_3.sql":::
The following is an example of the previous script, which creates a merge publication, upgraded to run successfully for [!INCLUDEssVersion2005] and later versions. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_4.sql":::
The following is an example of a [!INCLUDEssVersion2000] script that creates a push subscription to a transactional publication. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_5.sql":::
The following is an example of the previous script, which creates a push subscription to a transactional publication, upgraded to run successfully for [!INCLUDEssVersion2005] and later versions. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_6.sql":::
The following is an example of a [!INCLUDEssVersion2000] script that creates a push subscription to a merge publication. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_7.sql":::
The following is an example of the previous script, which creates a push subscription to a merge publication, upgraded to run successfully for [!INCLUDEssVersion2005] and later versions. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_8.sql":::
The following is an example of a [!INCLUDEssVersion2000] script that creates a pull subscription to a transactional publication. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_7.sql":::
The following is an example of the previous script, which creates a pull subscription to a transactional publication, upgraded to run successfully for [!INCLUDEssVersion2005] and later versions. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_9.sql":::
The following is an example of a [!INCLUDEssVersion2000] script that creates a pull subscription to a merge publication. Default parameters have been removed for readability.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_10.sql":::
The following is an example of the previous script, which creates a pull subscription to a merge publication, upgraded to run successfully for [!INCLUDEssVersion2005] and later versions. Defaults for new parameters have been explicitly declared.
Note
Windows credentials are supplied at runtime using sqlcmd scripting variables.
:::code language="sql" source="../codesnippet/tsql/upgrade-replication-scri_11.sql":::