Help Center> Relational Database Service> Best Practices> RDS for SQL Server> Microsoft SQL Server Publication and Subscription
Updated on 2023-12-18 GMT+08:00

Microsoft SQL Server Publication and Subscription

The publication and subscription function provided by Microsoft SQL Server uses the replication technology for data synchronization. This function makes it possible to split data read and write operations and synchronize offline and online data.

This section describes how to use SQL Server Management Studio (SSMS) to configure publication and subscription. You can create publications and subscriptions for RDS for SQL Server instances on the console. For details, see Creating a Publication.

Preparations

Environments

  1. Local environment: a local database running Microsoft SQL Server 2014 Standard Edition in Windows
  2. Online environment:
    • One single DB instance with 2 vCPUs and 16 GB of memory running Microsoft SQL Server 2014 Standard Edition, bound with an EIP
    • One primary/standby DB instance with 4 vCPUs and 8 GB of memory running Microsoft SQL Server 2014 Standard Edition, bound with an EIP

Environment Setup

  • Publisher: maintains source data and distributes specific data to the distributor. In this example, use the local server as the publisher.
    1. Use SSMS to log in to the local database as user sa. Right-click the Replication folder and then click Configure Distribution. You can use your local server as the distributor or use another server as the distributor. Click Next.
      • sa is the administrator account.
      • The login account must have the sysadmin permission. Otherwise, publication and subscription cannot be configured.
    2. Specify a root snapshot folder and click Next.

      Related agent permissions must be configured for the publication so that the agent account has the permissions to read from and write to the folder.

    3. Specify the names and directories of the distribution database and log files, and click Next.
    4. Specify the distributor for the publisher and then click Next.
    5. Click Finish to complete the configuration.
  • Configuring the agent account control file
    1. You need to add the agent account to the control property of the snapshot folder according to the folder directory. Otherwise, an error message will be displayed, indicating that the access is denied.
    2. Open the local SQL Server Configuration Manager, right-click the corresponding agent, choose Properties from the shortcut menu, and copy the account name.
    3. Return to the directory of the snapshot folder. Right-click the folder and choose Properties from the shortcut menu. In the displayed dialog box, choose Security > Edit > Add. Select the local path and agent account name, click OK, and select all permissions.
  • Distributor: distributes data to specific subscribers. In this example, the distributor and publisher share the same server. Therefore, no extra configuration is required. For more information, see Configure Distribution at the official website.
  • Subscriber: receives data from the distributor. Subscription includes push subscription and pull subscription.
    • Push subscription: The publisher propagates changes to a subscriber without a request from the subscriber. Changes can be pushed to subscribers continuously or on a frequently recurring schedule.
    • Pull subscription: The subscriber requests changes made at the publisher. The data is usually synchronized on demand or on a schedule rather than continuously. RDS for SQL Server instances do not support pull subscription. In this example, only push subscription can be configured.

    Before the subscription, ensure that the RDS for SQL Server instance can be accessed from the local server.

    Before configuring the local subscription, you need to configure the RDS instance information on the local server.

    1. Configure an alias name for the subscriber on the local server. The subscription service does not support IP address-based access. Therefore, you need to map the EIP of the RDS DB instance to an alias name. To obtain the alias name, log in to the RDS DB instance and run the following SQL statement:
      select  @@SERVERNAME
    2. After obtaining the alias name, open the local SQL Server Configuration Manager, select the native clients, right-click Aliases, and choose New Aliases from the shortcut menu.
    3. Enter related information and click OK.
      Table 1 Parameter description

      Parameter

      Description

      Alias Name

      Alias name configured in 1

      Port No

      Port number of the RDS instance

      Server

      EIP bound to the RDS instance

    4. In C:\Windows\System32\drivers\etc, open the host file and add a mapping:
      Server_address MSSQL-177FFD84\MSSQL2014STD

Creating a Publication

  1. Create a publication.

    Expand the Replication folder, and then right-click the Local Publications folder. Click New Publication.

  2. Select Transactional publication.
  3. Select a table as the publication object.
  4. Add the object to be filtered for personalized publication.
  5. Create a snapshot to replicate the current state of the table. You can also set up a snapshot agent to execute the plan.
  6. Configure the agent security. You need to set the login account to the local sa account.
  7. Configure the publication name and click Finish.

  8. Check whether the publication is created by using the replication monitor.

Creating a Subscription

  1. Right-click the publication for which you want to create one or more subscriptions, and then select New Subscriptions.
  2. Configure the required parameters and click Next.
  3. Select push subscription and click Next.
  4. Click Add Subscriber. Both the SQL Server engine and non-SQL Server engine can be used as subscribers. In this example, use the RDS for SQL Server instance as the subscriber.
  5. Select a database as the subscription object.
  6. Configure the connection to the subscriber.
  7. Use a database account that is valid for a long time to ensure the subscription validity. You can use the account for logging in to the RDS for SQL Server instance. Then, click OK.
  8. Check whether the subscription is created successfully.
  9. Move the cursor to the publication to view the subscription information.