Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Relational Database Service/ Best Practices/ RDS for SQL Server/ Using DAS to Create and Configure Agent Job and DBLink on the Master and Slave Databases for RDS for SQL Server Instances

Using DAS to Create and Configure Agent Job and DBLink on the Master and Slave Databases for RDS for SQL Server Instances

Updated on 2024-11-21 GMT+08:00

Scenarios

Data Admin Service (DAS) is a one-stop database management platform that allows you to manage databases on a web console. It offers database development, O&M, and intelligent diagnosis, facilitating your database usage and maintenance. Currently, DAS supports primary/standby switchover of RDS for SQL Server databases, facilitating synchronization between master and slave databases.

Logging In to DAS

  1. Log in to the management console.
  2. Click in the upper left corner and select a region.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. On the Instances page, locate the target DB instance and click Log In in the Operation column.

    Alternatively, click the instance name on the Instances page. On the displayed Basic Information page, click Log In in the upper right corner of the page.

  5. On the displayed login page, enter the correct username and password and click Log In.

Creating a Job for Data Synchronization to the Slave Database

  1. Create a job on the master database.

    On the DAS console, choose SQL Operations > SQL Query on the top menu bar. In the msdb database, run the following commands to create a job:

    NOTE:

    If a job has been created on the master database, skip this step.

    USE [msdb]
    GO
    DECLARE @jobId BINARY(16)
    EXEC  msdb.dbo.sp_add_job @job_name=N'hwtest', 
                       @enabled=1, 
                       @notify_level_eventlog=0, 
                       @notify_level_email=2, 
                       @notify_level_page=2, 
                       @delete_level=0, 
                       @category_name=N'[Uncategorized (Local)]', 
                       @owner_login_name=N'rdsuser', @job_id = @jobId OUTPUT
    select @jobId
    GO
    EXEC msdb.dbo.sp_add_jobserver @job_name=N'hwtest', @server_name = N'*******'
    GO
    USE [msdb]
    GO
    EXEC msdb.dbo.sp_add_jobstep @job_name=N'hwtest', @step_name=N'select orders', 
                       @step_id=1, 
                       @cmdexec_success_code=0, 
                       @on_success_action=1, 
                       @on_fail_action=2, 
                       @retry_attempts=0, 
                       @retry_interval=0, 
                       @os_run_priority=0, @subsystem=N'TSQL', 
                       @command=N'select * from orders;', 
                       @database_name=N'test', 
                       @flags=0
    GO
    USE [msdb]
    GO
    EXEC msdb.dbo.sp_update_job @job_name=N'hwtest', 
                       @enabled=1, 
                       @start_step_id=1, 
                       @notify_level_eventlog=0, 
                       @notify_level_email=2, 
                       @notify_level_page=2, 
                       @delete_level=0, 
                       @description=N'', 
                       @category_name=N'[Uncategorized (Local)]', 
                       @owner_login_name=N'zf1', 
                       @notify_email_operator_name=N'', 
                       @notify_page_operator_name=N''
    GO

    Run the following SQL statements to check whether the job has been created:

    use [msdb]

    select * from msdb.dbo.sysjobs where name ='hwtest';

  2. Switch to the slave database.

    NOTE:

    Currently, RDS for SQL Server does not support job synchronization between the master and slave databases. Therefore, you need to create a job on the slave database and synchronize the job. Click Switch SQL Execution Node next to Master to switch to the slave database.

  3. Run the commands in 1 to create a job on the slave database.

    Alternatively, use SQL Server Management Studio (SSMS) to export the created job to the editor window, copy the job to the SQL query window, and then run the commands in 1 to create a job on the slave database.

    If the job fails to be created, you are advised to delete the job first and then create the job again.

    Figure 1 Exporting a job
    Figure 2 Using the DAS console to create a job on the slave database

    Run the following SQL statements to delete the job:

    USE [msdb]

    GO

    EXEC msdb.dbo.sp_delete_job @job_name=N'hwtest', @delete_unused_schedule=1

    GO

Creating a DBLink for Data Synchronization to the Slave Database

DAS allows you to create linked servers to synchronize data between master and slave databases.

NOTE:

Check whether the MSDTC is configured by referring to Creating a Linked Server for an RDS for SQL Server DB Instance.

  1. Create a DBLink on the master database.

    USE [master]

    GO

    EXEC master.dbo.sp_addlinkedserver @server = N'TEST', @srvproduct=N'mytest', @provider=N'SQLOLEDB', @datasrc=N'abcd'

    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'TEST', @locallogin = NULL , @useself = N'False', @rmtuser = N'rdsuser', @rmtpassword = N'********'

    GO

    After the creation is successful, the corresponding DB instance or databases can be linked to view data verification. Run the following statements to query databases:

    SELECT name FROM [TEST].master.sys.databases ;

    GO

    Figure 3 Database query

  2. Create a DBLink on the slave database.

    On the DAS console, click Switch SQL Execution Node next to Master and run the SQL statement for creating a DBLink.

    NOTE:

    If the current DB instance and the interconnected database are not in the same VPC or distributed transactions are enabled with an EIP bound to the primary DB instance, the query statement cannot be executed on the standby DB instance. This step is used only to synchronize the DBLink configuration. After a switchover or failover, the DBLink can be used.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback