查看 SQL Server 数据库 - Azure Arc

适用于:SQL Server

可以在 Azure 中清点和查看 SQL Server 数据库。

先决条件

在开始之前,请验证托管数据库的 SQL Server 实例是否满足以下条件:

  • 托管在运行 Windows 操作系统的物理计算机或虚拟机上。
  • 为 SQL Server 2014 (12.x) 或更高版本。
  • 已连接到 Azure Arc。请参阅将 SQL Server 连接到 Azure Arc
  • 已直接连接到或通过代理服务器连接到 Internet。
  • 确保数据库名称遵循命名约定,并且不包含保留字。 要获取保留字列表,请参阅 解决保留资源名称的错误
  • 要查看可用的数据库大小和空间,请提供以下权限:
    • 内置的 SQL Server 登录名 NT AUTHORITY\SYSTEM 必须是计算机上运行的所有 SQL Server 实例的 SQL Server sysadmin 服务器角色的成员。

清点数据库

  1. 在 Azure 门户中找到已启用 Azure Arc 的 SQL Server 实例。
  2. 选择 SQL Server 资源。
  3. 在“数据管理”下,选择“数据库”。

Azure 门户显示 SQL Server 数据库 - Azure Arc。使用此区域可查看属于该实例的数据库。

查看数据库属性

若要查看某个特定数据库的数据库属性,请在门户中选择该数据库。

创建、修改或删除数据库后,更改会在一小时内显示在 Azure 门户中。

Screenshot of Azure portal, SQL Server database properties.

在“数据库”页面上会看到以下信息:

  • 有关数据收集和上传的相关信息:
    • 上次收集的时间
    • 上传状态
  • 有关每个数据库的信息:
    • 名称
    • Status
    • 创建时间
    • 最早还原点

选择特定数据库时,会看到该数据库的所有属性,这些属性在 SQL Server Management Studio (SSMS) 中也可见。

Screenshot of full database property list.

如何使用 Azure Resource Graph 查询数据

下面是一些示例场景,演示如何使用“Azure Resource Graph”查询可通过查看已启用 Azure Arc 的 SQL Server 数据库版本获得的数据。

场景 1:获取 10 个数据库

获取 10 个数据库并返回可用于查询的属性:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| limit 10

要查询的许多最有趣的属性都在 properties 属性中。 若要浏览可用属性,请运行此查询,然后选择行上的“查看详细信息”。 此操作会在右侧的 json 查看器中返回属性。

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| project properties

可通过在属性 json 的每个级别之间使用句点来导航浏览属性 json 的层次结构。

方案 2:获取数据库选项 AUTO_CLOSE 设置为 ON 的所有数据库

| where (type == 'microsoft.azurearcdata/sqlserverinstances/databases' and properties.databaseOptions.isAutoCloseOn == true)
| extend isAutoCloseOn = properties.databaseOptions.isAutoCloseOn
| project name, isAutoCloseOn

场景 3:获取已加密与未加密的数据库计数

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| extend isEncrypted = properties.databaseOptions.isEncrypted
| summarize count() by tostring(isEncrypted)
| order by ['isEncrypted'] asc

场景 4:显示所有未加密的数据库

resources
| where (type == 'microsoft.azurearcdata/sqlserverinstances/databases' and properties.databaseOptions.isEncrypted == false)
| extend isEncrypted = properties.databaseOptions.isEncrypted
| project name, isEncrypted

场景 5:按区域和兼容性级别获取所有数据库

此示例返回兼容性级别为 160 的 westus3 位置中的所有数据库:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| where location == "westus3"
| where properties.compatibilityLevel == "160"

场景 6:显示 SQL Server 版本发行

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances'
| extend SQLversion = properties.version
| summarize count() by tostring(SQLversion)

场景 7:按兼容性显示数据库计数

此示例返回按兼容性级别排序的数据库数量:

resources
| where type == 'microsoft.azurearcdata/sqlserverinstances/databases'
| summarize count() by tostring(properties.compatibilityLevel)
| order by properties_compatibilityLevel asc

还可以创建图表并将其固定到仪表板

Diagram of a pie chart that displays the query results for the count of databases by compatibility level.

已知问题

本地删除的数据库可能不会立即在 Azure 上删除。 不会影响数据库CRUD操作在本地的执行方式。