介绍 (Introduction)

This article is the third I am writing about Microsoft SQL system databases.

本文是我正在撰写的有关Microsoft SQL系统数据库的第三篇文章。

  • The first article Configuration, operations and restrictions of the tempdb SQL Server system database was about the tempdb database
  • 第一篇文章tempdb SQL Server系统数据库的 配置,操作和限制与 tempdb 数据库有关
  • SQL Server system databases – the master database was about the master database. SQL Server系统数据库–主数据库是关于主数据库的。

In this article, I will focus only on the msdb database, one of the four system databases that exist in any MSSQL instance:

在本文中,我将仅关注msdb数据库,该数据库是任何MSSQL实例中存在的四个系统数据库之一:

msdb的用法 (msdb usage)

The msdb database is mostly known as “the SQL Server Agent database” because it stores information of all SQL Agent jobs as their configuration and their execution history.

msdb数据库通常被称为“ SQL Server代理数据库”,因为它存储所有SQL代理作业的信息作为其配置和执行历史记录。

But it is not dedicated mainly to SQL Server Agent. Features like the Service Broker or the Database Mail also stores data in msdb database.

但是它不是主要用于SQL Server代理。 Service Broker或数据库邮件之类的功能也将数据存储在msdb数据库中。

The msdb database it is also used to store information about all backups and restores that are executed, no matter if they were executed by a SQL Agent job or ran by SSMS, sqlcmd or any other application (e.g. backup solutions as NetBackup), msdb will keep track of all related operations.

msdb数据库还用于存储有关已执行的所有备份和还原的信息,无论它们是由SQL Agent作业执行还是由SSMS,sqlcmd或任何其他应用程序(例如,备份解决方案,如NetBackup)运行, msdb都会跟踪所有相关操作。

的角色 (Roles)

One particularity of the msdb is that is the only system database that has pre-defined database roles besides the regular fixed database roles ones. Besides the members of the sysadmin fixed server role that are able to perform any operation in the MSSQL instance, only members of the following database roles are able to execute the related operations (for better understanding I have grouped these database roles):

msdb的一个特殊性是,除了常规的固定数据库角色之外,它是唯一具有预定义数据库角色的系统数据库。 除了能够在MSSQL实例中执行任何操作的sysadmin固定服务器角色的成员之外,只有以下数据库角色的成员才能执行相关的操作(为了更好地理解,我将这些数据库角色分组了):

Group name Database role name Notes
Database mail DatabaseMailUserRole Only members of this database role are able to send mails through SQL Server.
Integration Services Roles db_ssisadmin
db_ssisltduser
db_ssisoperator
Only members of this database role are able to work with SSIS packages.
Data Collector dc_operator
dc_admin
dc_proxy
Used to implement the Data Collector Security.
Policy-Based Management PolicyAdministratorRole Only members of this database role are able to manage a SQL Server instance Policies.
Server Group ServerGroupAdministratorRole
ServerGroupReaderRole
Only members of these database roles can administer and use registered server groups.
SQL Server Agent Fixed Database Roles SQLAgentUserRole
SQLAgentReaderRole
SQLAgentOperatorRole
Only members of one of these database roles can use SQL Server Agent.
Multiserver Environment TargetServersRole Used to work with a Multiserver Environment.
Server Utility UtilityCMRReader
UtilityIMRWriter
UtilityIMRReader
Used to work with the Server Utility.
团队名字 数据库角色名称 笔记
数据库邮件 DatabaseMailUserRole 只有该数据库角色的成员才能通过SQL Server发送邮件。
集成服务角色 db_ssisadmin
db_ssisltduser
db_ssisoperator
只有该数据库角色的成员才能使用SSIS包。
资料收集器 dc_operator
dc_admin
dc_proxy
用于实现数据收集器安全性。
基于策略的管理 PolicyAdministrator角色 只有该数据库角色的成员才能管理SQL Server实例策略。
服务器组 ServerGroupAdministrator角色
ServerGroupReaderRole
只有这些数据库角色的成员才能管理和使用注册的服务器组。
SQL Server代理固定数据库角色 SQLAgentUserRole
SQLAgentReaderRole
SQLAgentOperatorRole
这些数据库角色之一的成员只能使用SQL Server代理。
多服务器环境 TargetServersRole 用于与多服务器环境一起使用。
服务器实用程序 UtilityCMRReader
UtilityIMRWriter
UtilityIMRReader
用于服务器实用程序。

Below is an image showing all the default database roles for msdb database after a new MSSQL instance has been installed:

下图显示了在安装新的MSSQL实例后msdb数据库的所有默认数据库角色:

容量规划 (Capacity Planning)

msdb database disk space requirements depend on what features (e.g. Service Broker and Database Mail) will be used by the MSSQL instance as well the number of jobs executions that will be stored and also the number of backups and restores that will occur in a regular basis. Usually, as more databases the MSSQL instance has, the more disk space will be needed by the msdb database.

msdb数据库磁盘空间要求取决于MSSQL实例将使用哪些功能(例如Service Broker和数据库邮件)以及将存储的作业执行数量以及定期进行的备份和还原数量。 通常,随着MSSQL实例拥有的数据库越多, msdb数据库将需要更多的磁盘空间。

Database Mail

数据库邮件

When using the SQL Server Database Mail feature, msdb database is used to store copies of the mails and their attachments as also to store the Database Mail event log. To avoid msdb database growing to a non-wanted size, a good solution is to archive old messages. Microsoft has a good article that shows how the archive can be implemented with a SQL Server Agent Job.

使用SQL Server数据库邮件功能时, msdb数据库用于存储邮件及其附件的副本,也用于存储数据库邮件事件日志。 为了避免msdb数据库增长到不需要的大小,一个好的解决方案是存档旧消息。 Microsoft有一篇很好的文章,展示了如何使用SQL Server代理作业实现存档 。

Job history

工作经历

One good way to keep control on the msdb database size is to limit the maximum number of rows for the job history and run a regular purge task. For that in SSMS, right-click on the SQL Server Agent icon and choose Properties:

保持对msdb数据库大小的控制的一种好方法是限制作业历史记录的最大行数,并运行常规的清除任务。 对于SSMS中的内容,请右键单击SQL Server Agent图标,然后选择Properties

Select the History page and change the necessary parameters as you desire (for purge purposes configure the “Remove agent history”):

选择“ 历史记录”页面并根据需要更改必要的参数(出于清除目的,配置“ 删除代理历史记录 ”):

Alternatively the same can be done with T-SQL. Example:

或者,可以使用T-SQL进行相同的操作。 例:


USE [msdb]
GO
EXEC msdb.dbo.sp_set_sqlagent_properties @jobhistory_max_rows=1000,
@jobhistory_max_rows_per_job=100
GO
EXEC msdb.dbo.sp_purge_jobhistory @oldest_date='2017-06-01T00:00:00'

The above is only for a one time only execution. To have the purge running in a regular basis, create a SQL Server agent job and add a job step to run the purge with a dynamic date. The following is an example of keeping only the last 15 days (2 weeks) history in the database:

以上只是一次只能执行一次。 若要定期运行清除,请创建一个SQL Server代理作业,并添加一个作业步骤以动态日期运行清除。 以下是仅在数据库中保留最近15天(2周)历史记录的示例:


USE [msdb]
GO
DECLARE @OldestDate DATE-- Keep the last 15 days
SET @OldestDate = GETDATE() - 15
EXEC MSDB.DBO.SP_PURGE_JOBHISTORY @Oldest_date=@OldestDate

运作方式 (Operations)

Permissions

权限

By default, users do not have access to the msdb database. If you need to provide access to a user in msdb database, is recommended to use the pre-defined database roles already explained on the Roles section in this article.

默认情况下,用户无权访问msdb数据库。 如果需要提供对msdb数据库中用户的访问权限,建议使用本文“ 角色”部分中已经说明的预定义数据库角色。

Note: A user that does not have access to msdb database will not be able to see the SQL Server Agent from the SQL Server Management Studio (SSMS).

注意:无法访问msdb数据库的用户将无法从SQL Server Management Studio(SSMS)查看SQL Server代理。

Backups

后备

Like any other system database, it is also not recommended to create user objects in the msdb database.

与任何其他系统数据库一样,也不建议在msdb数据库中创建用户对象。

A change in msdb database occurs automatically when one of the following actions occurs:

当发生以下操作之一时, msdb数据库中的更改会自动发生:

  • Creation, modification or deletion of a SQL Server Agent job 创建,修改或删除SQL Server代理作业
  • Backup and Restore of any existing database in the MSSQL instance 备份和还原MSSQL实例中的任何现有数据库
  • SQL Server native Replication tasks SQL Server本机复制任务

That is why is recommended to have regular backups of the msdb database since it will be very useful to perform a restore when the msdb database becomes unusable.

因此,建议定期备份msdb数据库,因为在msdb数据库变得不可用时执行还原将非常有用。

Note: The msdb database is by default configured for Simple Recovery Model but if for some reason you decide to change it for a Full Recovery Model then do not forget to add the respective transaction log backup jobs for the msdb Backup Plan.

注意:默认情况下,为简单恢复模型配置了msdb数据库,但是如果出于某种原因您决定将其更改为完全恢复模型,那么请不要忘记为msdb备份计划添加相应的事务日志备份作业。

Move database file locations

移动数据库文件位置

Like any regular database, msdb data and transaction log files can be moved to any other location if and when needed to. Below is a T-SQL code example for moving the default data and transaction log files to a new location in S:\SysDB folder:

与任何常规数据库一样,如果需要,可以将msdb数据和事务日志文件移动到任何其他位置。 下面是一个T-SQL代码示例,用于将默认数据和事务日志文件移动到S:\ SysDB文件夹中的新位置:


ALTER DATABASE msdb
MODIFY FILE (NAME = MSDBData, FILENAME = 'S:\SysDB\Data\ MSDBData.mdf');
GO
ALTER DATABASE msdb
MODIFY FILE (NAME = MSDBLog, FILENAME = 'S:\SysDB\Log\ MSDBLog.ldf');

After running the above command, stop the respective MSSQL instance service and copy the msdb current files to the new location. After the copy finishes successfully, start the respective SQL Server service and verify if there are no issues by checking the database status, the SQL Server Agent service and jobs and if the database mail is being used then perform a simple sending mail test.

运行上述命令后,停止相应的MSSQL实例服务,然后将msdb当前文件复制到新位置。 复制成功完成后,启动相应SQL Server服务,并通过检查数据库状态,SQL Server代理服务和作业以及是否正在使用数据库邮件来验证是否没有问题,然后执行简单的发送邮件测试。

How to send a test e-mail in SSMS:

如何在SSMS中发送测试电子邮件:

When everything is correctly verified and there are no issues to solve then the old msdb data and transaction log files can be deleted from the old location.

如果所有内容均已正确验证且没有问题要解决,则可以从旧位置删除旧的msdb数据和事务日志文件。

限制条件 (Restrictions)

msdb has many restrictions which are described below.

msdb具有许多限制,如下所述。

Drop database

删除数据库

The msdb database cannot be deleted. When trying to delete it the respective error that a system database cannot be deleted will be raised:

无法删除msdb数据库。 尝试将其删除时,将引发无法删除系统数据库的相应错误:

Set offline

设为离线

msdb cannot be set to offline. When trying to do it the respective error stating that will be raised:

msdb不能设置为脱机。 尝试执行此操作时,将出现相应的错误说明:

Change Data Capture (CDC)

更改数据捕获(CDC)

Change Data Capture (CDC) cannot be enabled for msdb. When trying to do it the respective error informing that CDC cannot be enabled on a system database will be raised:

无法为msdb启用更改数据捕获(CDC)。 尝试执行此操作时,将引发相应错误,提示无法在系统数据库上启用CDC:

Other restrictions

其他限制

There are some more restrictions that are applied in general to all MSSQL system databases and they are listed below:

通常,对所有MSSQL系统数据库有一些其他限制,它们在下面列出:

  • msdb database and it primary file group cannot be renamed; msdb数据库及其主文件组无法重命名;
  • msdb database primary file group status cannot be set to READ_ONLY; msdb数据库主文件组的状态不能设置为READ_ONLY;
  • msdb database’s guest user cannot be deleted; msdb数据库的来宾用户不能删除;
  • msdb database’s default collation is the MSSQL instance collation and cannot be changed; msdb数据库的默认排序规则是MSSQL实例排序规则,不能更改。
  • msdb database cannot participate on a database mirroring solution. msdb数据库不能参与数据库镜像解决方案。

Other articles in this series:

本系列的其他文章:

  • Configuration, operations and restrictions of the tempdb SQL Server system database tempdb SQL Server系统数据库的配置,操作和限制
  • SQL Server system databases – the master database SQL Server系统数据库–主数据库
  • SQL Server system databases – the model database SQL Server系统数据库–模型数据库

参考资料 (References)

  • msdb database msdb数据库
  • Backup History and Header Information 备份历史记录和标题信息
  • Rebuild System Databases 重建系统数据库

翻译自: https://www.sqlshack.com/sql-server-system-databases-msdb-database/

SQL Server系统数据库– msdb数据库相关推荐

  1. SQL Server系统数据库–模型数据库

    介绍 (Introduction) This is my fourth article about SQL Server system databases. In previous articles ...

  2. SQL Server系统数据库–主数据库

    介绍 (Introduction) There are at least 4 system databases in any SQL Server instance as shown by the f ...

  3. tempdb SQL Server系统数据库的配置,操作和限制

    介绍 (Introduction) tempdb is one of the 4 system databases that exists in all SQL Server instances. T ...

  4. Sql Server系统数据库的作用

    Sql Server系统数据库的作用 一.  系统数据库 Sql Server的系统数据库分为:master.model.msdb和tempdb,这四个数据库在SQL Server中各司其职,作为研发 ...

  5. SQL Server系统数据库介绍

    文章目录 一.基本介绍 1.1 数据库组成 1.2 数据文件 1.数据文件 2.日志文件 1.3 五大系统数据库 二.master数据库 2.1 基本信息 2.2 限制 2.3 使用建议 三.msdb ...

  6. (转)SQL Server:在 SQL Server 2005 中配置数据库邮件,发送邮件

    SQL Server:在 SQL Server 2005 中配置数据库邮件,发送邮件 [作/译者]:鹏城万里    [日期]:2008-07-24    [来源]:本站原创    [查看]: 2031 ...

  7. Sql Server实用操作-无数据库日志文件恢复数据库两种方法

    数据库日志文件的误删或别的原因引起数据库日志的损坏 方法一 1.新建一个同名的数据库 2.再停掉sql server(注意不要分离数据库) 3.用原数据库的数据文件覆盖掉这个新建的数据库 4.再重启s ...

  8. Sql Server 性能分析4 –数据库大小,数据库表大小综合性分析报表输出

    Sql Server 性能分析4 –数据库大小,数据库表大小综合性分析报表输出 一:MS SQL Report Server 报表的制作. 1.打开Microsoft Visual Studio 20 ...

  9. 基于Sql Server 2008的分布式数据库的实践(五)

    基于Sql Server 2008的分布式数据库的实践(五) 原文 基于Sql Server 2008的分布式数据库的实践(五) 程序设计 ------------------------------ ...

最新文章

  1. 详细讲解设计LOGO思维方式和方法【转】
  2. Vue+Openlayer使用Draw实现交互式绘制多边形并获取面积
  3. OpenCV学习笔记(十七):图像修补:inpaint()
  4. 10亿数据量只需要100MB内存,redis的位存储为什么这么牛?
  5. C# 操作Gmap简单使用方法
  6. Mac上redis下载安装与配置详细版
  7. lm317扩流电路 (全集)
  8. python读取xml文件并修改_如何在Python中解析和修改XML?
  9. 视频教程-【深入理解计算机网络】入门计算机网络基础视频课程(下)-计算机网络
  10. 3D数学基础:向量运算
  11. 正则表达式之提取数字
  12. JAVA用Math 给pi赋值_导入Math.PI作为参考或值
  13. Unity3D - 使用天空盒子(Using Skyboxes)
  14. 采购招标系统源码 一站式全流程采购招标系统
  15. table-responsive响应式表格,手机端表格自适应
  16. 虚幻4连接mysql蓝图教程_ue4商城资源MySQL Integration数据库集成插件
  17. 计算机网络营销发展有哪些方面,《网络营销》(PPT124).ppt
  18. 对于木马的一些介绍(预防木马)
  19. 用计算机如何画柳条,柳条简笔画
  20. 什么是金融租赁?什么是融资租赁?

热门文章

  1. nginx 隐藏目录_Nginx学习之简单练习反向代理和负载均衡
  2. 修改Jmeter中乱码问题
  3. 灭顶之灾之网络电视精灵——S2 2.8
  4. cut point and bridge总结
  5. MVC控制器执行重定向
  6. poj 2417 Discrete Logging
  7. React实现类似淘宝tab居中切换效果
  8. 我的webpack路
  9. 纠正网上Mac 上使用Hbuilder运行夜神游模拟器,Hbuilder找不到模拟器
  10. 解决Vscode提示bodyparser已被弃用的问题