sqlserver執行計劃怎么看,如何在多個SQL Server上執行作業

 2023-10-18 阅读 29 评论 0

摘要:介紹 (Introduction) In earlier chapter, we explained how to run queries in multiple SQL servers using the SQL Central Management Server. In this new chapter, we will show how to propagate a job from a SQL Server Master Agent Job to a target server. 在前面

介紹 (Introduction)

In earlier chapter, we explained how to run queries in multiple SQL servers using the SQL Central Management Server. In this new chapter, we will show how to propagate a job from a SQL Server Master Agent Job to a target server.

在前面的章節中,我們解釋了如何使用SQL Central Management Server在多個SQL服務器中運行查詢。 在這一新的章節中,我們將展示如何將作業從SQL Server主代理作業傳播到目標服務器。

sqlserver執行計劃怎么看, This feature is called Multiserver Administration. In a multiserver administration, you need a Master Server and one or more target servers. In the master server, you create a copy of the job and then it is copied and executed in the target servers.

此功能稱為多服務器管理。 在多服務器管理中,您需要一個主服務器和一個或多個目標服務器。 在主服務器中,創建作業的副本,然后將其復制并在目標服務器中執行。

The jobs are scheduled to run and are executed in each Target Server.

第一個執行SQL十八, 作業計劃運行,并在每個目標服務器中執行。

要求 (Requirements)

  • SQL Server Installed (2 SQL Servers or 2 SQL Server Instances).

    已安裝SQL Server(2個SQL Server或2個SQL Server實例)。
  • 2 SQL Server Agents running.

    2個SQL Server代理正在運行。

入門 (Getting started)

  1. Open the regedit, to edit the Windows registry and change the registry \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft?SQL?Server\<instance_name>\SQL?Server?Agent\AllowDownloadedJobsToMatchProxyName to 1 in the master and target Servers.

    打開注冊表編輯器,以編輯Windows注冊表,并將主服務器和目標服務器中的注冊表\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ <instance_name> \ SQL Server Agent \ AllowDownloadedJobsToMatchProxyName更改為1。

    dbeaver執行sql文件。



    Figure 1. Registry圖1.注冊表
  2. 使用sql查看服務器上的所有數據庫? In the SQL Server Management Studio go to the SQL Server Agent, right click and select the Multi Server Administration and select the Make this a Master option.

    在SQL Server Management Studio中,轉到SQL Server代理,右鍵單擊并選擇“多服務器管理”,然后選擇“ 使它成為主服務器”選項


    sql執行錯誤。

    Figure 2. The Multi Server option圖2.多服務器選項
  3. The wizard to create the master server will be displayed. Press Next.

    將顯示創建主服務器的向導。 按下一步。

    sqlserver中最重要的管理工具,



    Figure 3. The Master Server Wizard圖3.主服務器向導
  4. The next window is the Master Server Operator. The operator can receive notification using email, pager address or with a net send address. Specify the address of your preference and press next.

    下一個窗口是主服務器操作員。 操作員可以使用電子郵件,尋呼機地址或網絡發送地址接收通知。 指定您的首選項地址,然后按下一步。



    Figure 4. The address of the operator圖4.操作員的地址
  5. In the Target Server window, we will select all the target servers. In this example, we only have one target server, but in the real-life, we may have several. Press the Add connection button to add a new target server.

    在“目標服務器”窗口中,我們將選擇所有目標服務器。 在此示例中,我們只有一臺目標服務器,但實際上,我們可能有幾臺。 按添加連接按鈕以添加新的目標服務器。



    Figure 5. Target Servers圖5.目標服務器
  6. Connect to the SQL Server that will be used as a Target Server.

    連接到將用作目標服務器SQL Server。



    Figure 6. Connection information圖6.連接信息
  7. If everything is OK, you will receive a success message related to the compatibility between the 2 servers.

    如果一切正常,您將收到與兩臺服務器之間的兼容性有關的成功消息。



    Figure 7. Server Compatibility Check圖7.服務器兼容性檢查
  8. You can view the report, save the report in a file, in the clipboard or send the report by email. In this example, we will select the first option.

    您可以查看報告,將報告保存在文件中,剪貼板中或通過電子郵件發送報告。 在此示例中,我們將選擇第一個選項。



    Figure 8. Report options圖8.報告選項
  9. In this option, the report will show the result of the version compatibility between the master and target servers.

    在此選項中,報告將顯示主服務器與目標服務器之間版本兼容性的結果。



    Figure 9. Compatibility Report圖9.兼容性報告


  10. Figure 10. Actions to enlist the target server and create the MSX Operator.圖10.注冊目標服務器并創建MSX Operator的操作。
  11. You will notice that in the Master Server it says (MSX). It means that it is a Master Server. Right-click and select the New Job option.

    您會注意到,在主服務器中顯示為(MSX)。 這意味著它是一個主服務器。 右鍵單擊并選擇“ 新作業”選項。



    Figure 11. Creating a new job.圖11.創建一個新作業。
  12. We will create a backup in the target server. If you have several target servers, the backup will be created in all of them.

    我們將在目標服務器中創建一個備份。 如果您有多個目標服務器,則將在所有目標服務器中創建備份。
  13. The creation of a job will be similar to local jobs. You just need a name and optionally a description.

    職位的創建將類似于本地職位。 您只需要一個名稱和一個描述即可。



    Figure 12. Creating a backup圖12.創建一個備份
  14. Go to the Steps page and click the New button to create a new Job.

    轉到“步驟”頁面,然后單擊“新建”按鈕以創建新的作業。



    Figure 13. Creating new steps圖13.創建新步驟
  15. Specify the name and the command. In this example, we are backing up a database named db2 in the db2.bak file. You can modify the T-SQL sentences to your own needs:

    指定名稱和命令。 在此示例中,我們將在db2.bak文件中備份名為db2的數據庫。 您可以根據自己的需要修改T-SQL語句:

    BACKUP DATABASE [db2] TO DISK = N’C:\Backup\db2.bak’ WITH NO FORMAT
    GO

    備份數據庫[db2]到磁盤= N'C:\ Backup \ db2.bak',不帶格式



    Figure 14. The step to create backups圖14.創建備份的步驟
  16. This is the key section, go to the Targets page and select the target multiple servers where you want to run the job. In this example, we have one target server. Select the option target to multiple servers and check the target server(s) where you want to run the job.

    這是關鍵部分,請轉到“目標”頁面,然后選擇要在其中運行作業的目標多臺服務器。 在此示例中,我們有一臺目標服務器。 選擇多個服務器的目標服務器,然后檢查要在其中運行作業的目標服務器。



    Figure 15. Selecting Target servers圖15.選擇目標服務器


  17. Figure 16. Start Job at Step圖16.在步驟開始作業
  18. If everything is OK, you will receive a Success message that the job was posted remotely for execution.

    如果一切正常,您將收到一條成功消息,說明該作業已遠程發布以執行。



    Figure 17. Success execution message.圖17.成功執行消息。
  19. A new backup will be created in the target server(s). As you can see, working with master and target servers is a straightforward process.

    將在目標服務器中創建一個新的備份。 如您所見,使用主服務器和目標服務器是一個簡單的過程。



    Figure 18. The SQL Server backup created.圖18.創建SQL Server備份。

一些常見問題 (Some common problems)

A very common problem when you are creating the target server (step 10) is the following message:

創建目標服務器(步驟10)時,一個非常常見的問題是以下消息:


This error is related to the encryption between the master and target server.

此錯誤與主服務器和目標服務器之間的加密有關。

If you have this error, verify that the registry
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft?SQL?Server\<instance_name>\SQL?Server?Agent\MsxEncryptChannelOptions matches in the master and the target servers. If not, modify the registries. This registry controls the encryption between the master and target server. The value 0 means no encryption. 1 means to encrypt without a certificate and 2 with a certificate.

如果出現此錯誤,請驗證注冊表
\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ <實例名稱> \ SQL Server代理\ MsxEncryptChannelOptions在主服務器和目標服務器中匹配。 如果不是,請修改注冊表。 該注冊表控制主服務器和目標服務器之間的加密。 值0表示不加密。 1表示不使用證書進行加密,2表示使用證書。



一些管理選項 (Some administrative options)

In the master server (MSX), it is posible to administer the Multi server configuration. Right click on the SQL Server Agent and in the Multi Server Administration, select Manage Target Servers.

在主服務器(MSX)中,可以管理多服務器配置。 右鍵單擊SQL Server代理,然后在“多服務器管理”中選擇“ 管理目標服務器”。


The target server status tab shows the list of target servers, the local time

目標服務器狀態選項卡顯示目標服務器列表,本地時間

(the data and time of the target server in the local time) and the last time that the target server polled the master.

(目標服務器在本地時間中的數據和時間)以及目標服務器上次輪詢主服務器的時間。

The force poll button forces the poll of the selected target server to the master server. The Force Defection button allows defecting the target server and the post-instruction allows posting the instructions.

強制輪詢按鈕將選定目標服務器的輪詢強制到主服務器。 強制刪除按鈕可以使目標服務器損壞,而后指令則可以發布指令。


The Download Instruction shows the operations sent to the target servers, specifying the Object Name, Date posted and the Date that it was downloaded.

下載指令顯示發送到目標服務器的操作,并指定對象名稱,發布日期和下載日期。


需要代理時 (When the proxy is required)

If a proxy is necessary, you will need to create a credential and then associate it with the proxy. Make sure that the proxy name is the same in the Master and Target servers.

如果需要代理,則需要創建一個證書,然后將其與代理關聯。 確保主服務器和目標服務器中的代理名稱相同。

如何刪除目標服務器 (How to remove the target server)

The option to remove the target server from the Multi-Server. You can do that on the target server.

從多服務器中刪除目標服務器的選項。 您可以在目標服務器上執行此操作。

Go to the SQL Server Agent, right click and select Multi Server Administration>Defect

轉到SQL Server代理,右鍵單擊并選擇“多服務器管理”>“缺陷”


結論 (Conclusion)

As you can see, creating a master server and target servers is a straightforward process. Once configured, you can send jobs to multiple servers at the same time.

如您所見,創建主服務器和目標服務器是一個簡單的過程。 配置完成后,您可以同時將作業發送到多個服務器。

Some useful stored procedures:

一些有用的存儲過程:

  • sp_add_targetservergroup sp_add_targetservergroup
  • sp_delete_targetserver sp_delete_targetserver

Some useful system views:

一些有用的系統視圖:

  • dbo.sysdownloadlist dbo.sys下載列表
  • dbo.systargetservers dbo.systargetservers

翻譯自: https://www.sqlshack.com/how-to-execute-jobs-on-multiple-sql-servers/

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/144140.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息