SQLServer教程FG075-SQLServer云部署实战
本文档风哥主要介绍SQLServer数据库云部署相关知识,包括SQLServer数据库云部署选项、SQLServer数据库Azure SQL部署、SQLServer数据库Azure VM部署、SQLServer数据库云迁移策略等内容,风哥教程参考SQLServer官方文档Cloud Deployment内容编写,适合DBA人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。
Part01-基础概念与理论知识
1.1 SQLServer数据库云部署概念
SQLServer数据库云部署是指将SQLServer数据库部署在云计算平台上,利用云平台的弹性伸缩、高可用、灾备等特性,实现数据库的灵活部署和管理。云部署可以降低硬件投入成本,简化运维工作,提高系统的可用性和扩展性。更多视频教程www.fgedu.net.cn
- 弹性伸缩:根据业务需求动态调整资源
- 高可用性:内置高可用和灾备功能
- 降低成本:按需付费,减少硬件投入
- 简化运维:云平台提供自动化运维工具
- 快速部署:分钟级创建数据库实例
1.2 SQLServer数据库云部署选项
1. Azure SQL Database (PaaS)
特点:
– 完全托管的服务
– 自动备份和高可用
– 自动更新和补丁
– 内置智能功能
适用场景:
– 新应用开发
– SaaS应用
– 需要最小运维的场景
2. Azure SQL Managed Instance (PaaS)
特点:
– 接近100%兼容本地SQL Server
– 自动备份和高可用
– 支持跨数据库查询
– 支持SQL Agent
适用场景:
– 本地SQL Server迁移
– 需要实例级别功能
– 企业应用迁移
3. Azure Virtual Machines (IaaS)
特点:
– 完全控制SQL Server
– 支持所有SQL Server功能
– 自定义配置
– 操作系统级别访问
适用场景:
– 需要完全控制
– 特殊配置需求
– 无法迁移到PaaS的应用
4. 其他云平台
– AWS RDS for SQL Server
– 阿里云RDS for SQL Server
– 腾讯云SQL Server
– 华为云RDS for SQL Server
# 部署选项对比
选项 运维复杂度 功能完整性 成本控制 迁移难度
Azure SQL Database 低 中 好 高
Azure SQL Managed Inst 低 高 中 低
Azure VM 高 最高 差 最低
1.3 SQLServer数据库云架构设计
SQLServer数据库云架构设计要点:
- 高可用架构:配置自动故障转移、读写分离
- 灾备架构:跨区域部署、异地灾备
- 安全架构:网络安全、数据加密、访问控制
- 性能架构:合理配置资源、优化查询
- 成本架构:合理选择规格、利用预留实例
┌─────────────────────────────────────────────────────────────┐
│ 应用层 │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Web应用 │ │ API服务 │ │ 报表服务 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 数据库层 │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Azure SQL Database / VM │ │
│ │ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ 主数据库 │───▶│ 辅助副本 │ │ │
│ │ │ (读写) │ │ (只读) │ │ │
│ │ └─────────────┘ └─────────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 存储层 │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 数据文件 │ │ 日志文件 │ │ 备份存储 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
Part02-生产环境规划与建议
2.1 SQLServer数据库云部署规划
SQLServer数据库云部署规划要点:
1. 需求评估
– 数据库规模评估
– 性能需求评估
– 高可用需求评估
– 安全合规评估
2. 平台选择
– 云平台选择(Azure/AWS/阿里云等)
– 部署模式选择(PaaS/IaaS)
– 规格配置选择
3. 架构设计
– 高可用架构设计
– 灾备架构设计
– 安全架构设计
– 网络架构设计
4. 迁移规划
– 迁移方案设计
– 迁移工具选择
– 迁移时间计划
– 回滚方案准备
5. 运维规划
– 监控告警配置
– 备份恢复策略
– 安全管理策略
– 成本管理策略
# 资源规格规划
小型应用(并发<50):
- Azure SQL: S3标准系列
- VM: DS2_v2 (2核7GB)
中型应用(并发50-200):
- Azure SQL: P2高级系列
- VM: DS4_v2 (4核14GB)
大型应用(并发200-500):
- Azure SQL: P6高级系列
- VM: DS6_v2 (8核28GB)
超大型应用(并发>500):
– Azure SQL: P11/P15
– VM: E16s_v3 (16核128GB)
2.2 SQLServer数据库云平台选择
SQLServer数据库云平台选择建议:
- Azure:与SQLServer深度集成,功能最全,推荐SQLServer用户
- AWS:成熟稳定,功能丰富,适合多云策略
- 阿里云:国内服务好,合规性强,适合国内企业
- 腾讯云:性价比高,适合中小型企业
- 华为云:国产化支持,适合政企客户
2.3 SQLServer数据库云迁移策略
1. 迁移评估
– 使用DMA(Database Migration Assistant)评估
– 识别兼容性问题
– 评估迁移工作量
2. 迁移方法
方法 适用场景 停机时间
─────────────────────────────────────────────────────
在线迁移 大型数据库,要求最小停机 分钟级
离线迁移 小型数据库,可接受停机 小时级
备份恢复 中型数据库,标准迁移 小时级
数据同步 持续同步,平滑切换 分钟级
3. 迁移工具
– Azure Database Migration Service
– SQL Server Migration Assistant
– Data Migration Assistant
– BACPAC/DACPAC导入导出
– 原生备份恢复
4. 迁移步骤
步骤1: 评估源数据库
步骤2: 创建目标数据库
步骤3: 迁移数据库对象
步骤4: 迁移数据
步骤5: 验证数据一致性
步骤6: 切换应用连接
步骤7: 监控和优化
Part03-生产环境项目实施方案
3.1 SQLServer数据库Azure SQL部署实战
3.1.1 SQLServer数据库使用Azure CLI创建Azure SQL
az login
GO
[
{
“cloudName”: “AzureCloud”,
“homeTenantId”: “xxx-xxx-xxx”,
“id”: “xxx-xxx-xxx”,
“isDefault”: true,
“name”: “fgedu-subscription”,
“state”: “Enabled”,
“tenantId”: “xxx-xxx-xxx”
}
]
# 创建资源组
az group create –name fgedu-rg –location eastasia
GO
{
“id”: “/subscriptions/xxx/resourceGroups/fgedu-rg”,
“location”: “eastasia”,
“name”: “fgedu-rg”,
“properties”: {
“provisioningState”: “Succeeded”
},
“type”: “Microsoft.Resources/resourceGroups”
}
# 创建Azure SQL服务器
az sql server create \
–name fgedu-sqlserver \
–resource-group fgedu-rg \
–location eastasia \
–admin-user fgeduadmin \
–admin-password Fgedu@2026#Admin
GO
{
“administratorLogin”: “fgeduadmin”,
“fullyQualifiedDomainName”: “fgedu-sqlserver.database.windows.net”,
“id”: “/subscriptions/xxx/servers/fgedu-sqlserver”,
“location”: “eastasia”,
“name”: “fgedu-sqlserver”,
“state”: “Ready”,
“type”: “Microsoft.Sql/servers”
}
# 创建Azure SQL数据库
az sql db create \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedudb \
–service-objective S3 \
–max-size 100GB
GO
{
“collation”: “SQL_Latin1_General_CP1_CI_AS”,
“databaseId”: “xxx-xxx-xxx”,
“defaultSecondaryLocation”: “southeastasia”,
“edition”: “Standard”,
“id”: “/subscriptions/xxx/databases/fgedudb”,
“location”: “eastasia”,
“maxSizeBytes”: 107374182400,
“name”: “fgedudb”,
“requestedServiceObjectiveName”: “S3”,
“status”: “Online”,
“type”: “Microsoft.Sql/servers/databases”
}
# 配置防火墙规则
az sql server firewall-rule create \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name AllowAll \
–start-ip-address 0.0.0.0 \
–end-ip-address 255.255.255.255
GO
{
“endIpAddress”: “255.255.255.255”,
“id”: “/subscriptions/xxx/firewallRules/AllowAll”,
“name”: “AllowAll”,
“startIpAddress”: “0.0.0.0”,
“type”: “Microsoft.Sql/servers/firewallRules”
}
3.1.2 SQLServer数据库连接Azure SQL
sqlcmd -S fgedu-sqlserver.database.windows.net \
-U fgeduadmin \
-P ‘Fgedu@2026#Admin’ \
-d fgedudb
GO
1> SELECT @@VERSION;
2> GO
————————————————————————————————————————————————————————————————————————————————————————————————————–
Microsoft SQL Azure (RTM) – 12.0.2000.8
Apr 8 2026 10:00:00
Copyright (C) 2026 Microsoft Corporation
(1 rows affected)
# 创建测试表
1> CREATE TABLE dbo.fgedu_test (
2> id INT PRIMARY KEY IDENTITY,
3> name NVARCHAR(100),
4> create_time DATETIME DEFAULT GETDATE()
5> );
6> GO
1> INSERT INTO dbo.fgedu_test (name) VALUES (‘测试数据1’), (‘测试数据2’);
2> GO
(2 rows affected)
1> SELECT * FROM dbo.fgedu_test;
2> GO
id name create_time
———– ———- ———————–
1 测试数据1 2026-04-08 10:30:00.000
2 测试数据2 2026-04-08 10:30:00.000
(2 rows affected)
# 查看Azure SQL服务层级
1> SELECT DATABASEPROPERTYEX(‘fgedudb’, ‘Edition’) AS Edition,
2> DATABASEPROPERTYEX(‘fgedudb’, ‘ServiceObjective’) AS ServiceObjective;
3> GO
Edition ServiceObjective
———- ——————–
Standard S3
3.2 SQLServer数据库Azure VM部署实战
3.2.1 SQLServer数据库创建Azure VM
az vm create \
–resource-group fgedu-rg \
–name fgedu-sqlvm \
–image MicrosoftSQLServer:SQL2019-WS2019:Enterprise:latest \
–size Standard_DS4_v2 \
–admin-username azureuser \
–admin-password Fgedu@2026#VM \
–data-disk-sizes-gb 128 256 512
GO
{
“fqdns”: “”,
“id”: “/subscriptions/xxx/virtualMachines/fgedu-sqlvm”,
“location”: “eastasia”,
“macAddress”: “00-0D-3A-XX-XX-XX”,
“powerState”: “VM running”,
“privateIpAddress”: “10.0.0.4”,
“publicIpAddress”: “52.xxx.xxx.xxx”,
“resourceGroup”: “fgedu-rg”,
“zones”: “”
}
# 开放SQL Server端口
az vm open-port \
–resource-group fgedu-rg \
–name fgedu-sqlvm \
–port 1433 \
–priority 100
GO
{
“access”: “Allow”,
“destinationAddressPrefix”: “*”,
“destinationPortRange”: “1433”,
“direction”: “Inbound”,
“name”: “port_1433”,
“priority”: 100,
“sourceAddressPrefix”: “*”,
“sourcePortRange”: “*”
}
# 获取VM公共IP
az vm show \
–resource-group fgedu-rg \
–name fgedu-sqlvm \
–show-details \
–query publicIps \
–output tsv
GO
52.xxx.xxx.xxx
3.2.2 SQLServer数据库配置Azure VM SQL Server
ssh azureuser@52.xxx.xxx.xxx
GO
azureuser@fgedu-sqlvm:~$ sudo systemctl status mssql-server
● mssql-server.service – Microsoft SQL Server Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2026-04-08 10:00:00 UTC; 5min ago
# 配置SQL Server
azureuser@fgedu-sqlvm:~$ sudo /opt/mssql/bin/mssql-conf setup
Choose an edition of SQL Server:
1) Evaluation (free, no production use, 180-day limit)
2) Developer (free, no production use)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID) – CPU Core utilization restricted to 20 physical/40 hyperthreaded
7) Enterprise Core (PAID) – CPU Core utilization up to Operating System Limit
8) I bought a license through a retail sales channel and have a product key to enter.
Enter your edition(1-8): 6
Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
Configuring SQL Server…
This is an evaluation version. There are [180] days left in the evaluation period.
Setup has completed successfully. SQL Server is now starting.
# 验证SQL Server配置
azureuser@fgedu-sqlvm:~$ sqlcmd -S localhost -U sa -P ‘Fgedu@2026#SQL’
1> SELECT @@VERSION;
2> GO
————————————————————————————————————————————————————————————————————————————————————————————————————–
Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) – 15.0.4198.2 (X64)
Jan 12 2026 16:18:10
Copyright (C) 2019 Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Linux (Ubuntu 20.04.3 LTS)
(1 rows affected)
# 配置数据文件存储
azureuser@fgedu-sqlvm:~$ sudo mkdir -p /sqlserver/data /sqlserver/log /sqlserver/backup
azureuser@fgedu-sqlvm:~$ sudo chown mssql:mssql /sqlserver/data /sqlserver/log /sqlserver/backup
# 修改默认数据文件位置
1> USE master;
2> GO
1> ALTER DATABASE fgedudb
2> MODIFY FILE (NAME = fgedudb_data, FILENAME = ‘/sqlserver/data/fgedudb.mdf’);
3> GO
The file “fgedudb_data” has been modified in the system catalog. The new path will be used the next time the database is started.
3.3 SQLServer数据库云环境配置优化
3.3.1 SQLServer数据库Azure SQL性能优化
SELECT * FROM sys.dm_db_tuning_recommendations;
GO
name type reason state
——————- ——— ——————- ———
create_index_123 CREATE 缺少索引影响性能 PENDING
drop_index_456 DROP 未使用的索引 PENDING
# 查看查询性能统计
SELECT TOP 10
qs.query_hash,
qs.execution_count,
qs.total_logical_reads,
qs.total_elapsed_time / 1000000.0 AS total_elapsed_time_sec,
SUBSTRING(st.text, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset
END – qs.statement_start_offset)/2) + 1) AS query_text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY qs.total_elapsed_time DESC;
GO
query_hash execution_count total_logical_reads total_elapsed_time_sec query_text
———————————— ————— ——————- ———————- ——————–
0xABC123DEF456 125 45678 12.345 SELECT * FROM…
0x789GHI012JKL345 89 23456 8.765 UPDATE dbo…
# 查看数据库资源使用
SELECT
end_time,
avg_cpu_percent,
avg_data_io_percent,
avg_log_write_percent,
avg_memory_usage_percent
FROM sys.dm_db_resource_stats
ORDER BY end_time DESC;
GO
end_time avg_cpu_percent avg_data_io_percent avg_log_write_percent avg_memory_usage_percent
———————– ————— ——————- ——————— ————————
2026-04-08 10:30:00.000 45.23 23.45 12.34 67.89
2026-04-08 10:25:00.000 52.34 34.56 15.67 72.34
# 配置自动调优
ALTER DATABASE fgedudb SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = ON);
GO
Command(s) completed successfully.
# 查看自动调优配置
SELECT name, desired_state_desc, actual_state_desc
FROM sys.database_automatic_tuning_options;
GO
name desired_state_desc actual_state_desc
———————– —————— —————–
force_last_good_plan ON ON
create_index ON ON
drop_index ON ON
3.3.2 SQLServer数据库云备份配置
# 查看备份配置
SELECT
database_name,
backup_type,
backup_start_date,
backup_finish_date,
backup_size_mb
FROM sys.dm_database_backups
ORDER BY backup_start_date DESC;
GO
database_name backup_type backup_start_date backup_finish_date backup_size_mb
————- ———– ——————— ——————— ————–
fgedudb FULL 2026-04-08 02:00:00 2026-04-08 02:15:00 1024.5
fgedudb LOG 2026-04-08 01:00:00 2026-04-08 01:00:05 15.3
fgedudb LOG 2026-04-08 00:00:00 2026-04-08 00:00:05 12.8
# 配置长期备份保留
az sql db ltr-policy set \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedudb \
–weekly-retention P4W \
–monthly-retention P12M \
–yearly-retention P7Y \
–week-of-year 1
GO
{
“databaseName”: “fgedudb”,
“monthlyRetention”: “P12M”,
“weeklyRetention”: “P4W”,
“yearlyRetention”: “P7Y”
}
# 手动创建备份
az sql db export \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedudb \
–storage-uri “https://fgedustorage.blob.core.windows.net/backup/fgedudb.bacpac” \
–storage-key-type StorageAccessKey \
–storage-key “your-storage-key”
GO
{
“blobUri”: “https://fgedustorage.blob.core.windows.net/backup/fgedudb.bacpac”,
“databaseName”: “fgedudb”,
“operationId”: “xxx-xxx-xxx”,
“status”: “Succeeded”
}
Part04-生产案例与实战讲解
4.1 SQLServer数据库本地到云迁移案例
# 实施步骤:
# 1. 评估迁移兼容性
# 使用Data Migration Assistant(DMA)评估
dma.exe /Action=Assess /SourceConnectionString=”Server=local-sql;Database=fgedudb;Integrated Security=True” /TargetPlatform=AzureSqlDatabase /AssessmentReportPath=”C:\migration\report.html”
# 评估报告显示:
# – 兼容性: 95%
# – 不支持的功能: 3个
# – 建议的修复: 5个
# 2. 修复兼容性问题
— 本地SQL Server执行
USE fgedudb;
GO
— 修复不支持的功能
DROP PROCEDURE dbo.fgedu_old_proc;
GO
— 创建替代方案
CREATE PROCEDURE dbo.fgedu_new_proc
AS
BEGIN
SELECT * FROM dbo.fgedu_orders WHERE create_time > DATEADD(DAY, -30, GETDATE());
END;
GO
Command(s) completed successfully.
# 3. 使用Azure Database Migration Service迁移
az dms project create \
–resource-group fgedu-rg \
–service-name fgedu-dms \
–source-platform SQL \
–target-platform SQLDB \
–name fgedu-migration-project
GO
{
“id”: “/subscriptions/xxx/projects/fgedu-migration-project”,
“name”: “fgedu-migration-project”,
“sourcePlatform”: “SQL”,
“targetPlatform”: “SQLDB”
}
# 4. 创建迁移任务
az dms project task create \
–resource-group fgedu-rg \
–service-name fgedu-dms \
–project-name fgedu-migration-project \
–name fgedu-migration-task \
–source-connection-json ‘{“serverName”:”local-sql”,”authentication”:”WindowsAuthentication”,”databaseName”:”fgedudb”}’ \
–target-connection-json ‘{“serverName”:”fgedu-sqlserver.database.windows.net”,”authentication”:”SqlAuthentication”,”databaseName”:”fgedudb”,”userName”:”fgeduadmin”,”password”:”Fgedu@2026#Admin”}’
GO
{
“id”: “/subscriptions/xxx/tasks/fgedu-migration-task”,
“name”: “fgedu-migration-task”,
“state”: “Queued”
}
# 5. 监控迁移进度
az dms project task show \
–resource-group fgedu-rg \
–service-name fgedu-dms \
–project-name fgedu-migration-project \
–name fgedu-migration-task
GO
{
“name”: “fgedu-migration-task”,
“state”: “Running”,
“progress”: {
“databaseName”: “fgedudb”,
“appliedChanges”: 1234567,
“pendingChanges”: 0,
“percentComplete”: 100
}
}
# 6. 验证迁移结果
— Azure SQL执行
SELECT COUNT(*) AS TableCount FROM INFORMATION_SCHEMA.TABLES;
GO
TableCount
———–
45
SELECT SUM(row_count) AS TotalRows
FROM sys.dm_db_partition_stats;
GO
TotalRows
———–
12345678
4.2 SQLServer数据库云高可用配置案例
# 实施步骤:
# 1. 配置活动异地复制
az sql db replica create \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedudb \
–partner-server fgedu-sqlserver-dr \
–partner-resource-group fgedu-rg-dr \
–partner-location southeastasia
GO
{
“databaseName”: “fgedudb”,
“location”: “southeastasia”,
“replicationLinkType”: “GEO”,
“role”: “Secondary”,
“serverName”: “fgedu-sqlserver-dr”
}
# 2. 查看复制状态
SELECT
link_id,
partner_server,
partner_database,
replication_state_desc,
role_desc,
secondary_allow_connections_desc
FROM sys.dm_geo_replication_link_status;
GO
link_id partner_server partner_database replication_state_desc role secondary_allow_connections_desc
———————————— ——————— —————- ——————— ——— ——————————-
xxx-xxx-xxx fgedu-sqlserver-dr fgedudb CATCH_UP PRIMARY All
# 3. 配置故障转移组
az sql failover-group create \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedu-fog \
–partner-server fgedu-sqlserver-dr \
–partner-resource-group fgedu-rg-dr \
–add-db fgedudb \
–failover-policy Automatic \
–grace-period 1
GO
{
“databases”: [“fgedudb”],
“failoverPolicy”: “Automatic”,
“gracePeriod”: “PT1H”,
“name”: “fgedu-fog”,
“partnerServers”: [“fgedu-sqlserver-dr”],
“readOnlyEndpointPolicy”: “Disabled”,
“readWriteEndpointPolicy”: “Enabled”
}
# 4. 测试故障转移
az sql failover-group set-primary \
–resource-group fgedu-rg-dr \
–server fgedu-sqlserver-dr \
–name fgedu-fog
GO
{
“name”: “fgedu-fog”,
“replicationRole”: “Primary”,
“replicationState”: “CATCH_UP”
}
# 5. 验证故障转移结果
SELECT
DB_NAME() AS DatabaseName,
SERVERPROPERTY(‘ServerName’) AS ServerName,
SERVERPROPERTY(‘Edition’) AS Edition;
GO
DatabaseName ServerName Edition
———— ——————– ———-
fgedudb fgedu-sqlserver-dr Standard
# 6. 切换回主服务器
az sql failover-group set-primary \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedu-fog
GO
{
“name”: “fgedu-fog”,
“replicationRole”: “Primary”,
“replicationState”: “CATCH_UP”
}
4.3 SQLServer数据库云部署问题解决方案
# 问题1:连接超时
# 解决方案:检查防火墙规则和网络配置
— 查看当前连接
SELECT
session_id,
host_name,
program_name,
status,
last_request_start_time,
last_request_end_time
FROM sys.dm_exec_sessions
WHERE is_user_process = 1;
GO
session_id host_name program_name status last_request_start_time
———- ————- ————– ——– ———————–
51 APP-SERVER-01 .Net SqlClient running 2026-04-08 10:30:00.000
52 APP-SERVER-02 .Net SqlClient sleeping 2026-04-08 10:25:00.000
— 配置连接池优化
— 连接字符串添加:
— Connect Timeout=60;Connection Lifetime=600;Pooling=true;Min Pool Size=10;Max Pool Size=200
# 问题2:性能问题
# 解决方案:优化查询和配置
— 查看性能问题
SELECT TOP 10
qs.query_hash,
qs.execution_count,
qs.total_logical_reads,
qs.total_elapsed_time / 1000000.0 AS elapsed_time_sec
FROM sys.dm_exec_query_stats qs
ORDER BY qs.total_elapsed_time DESC;
GO
— 查看缺失索引
SELECT
mid.statement AS table_name,
mid.equality_columns,
mid.inequality_columns,
mid.included_columns,
migs.avg_user_impact
FROM sys.dm_db_missing_index_details mid
JOIN sys.dm_db_missing_index_groups mig ON mid.index_handle = mig.index_handle
JOIN sys.dm_db_missing_index_group_stats migs ON mig.index_group_handle = migs.group_handle
ORDER BY migs.avg_user_impact DESC;
GO
table_name equality_columns inequality_columns included_columns avg_user_impact
——————— —————– ——————- —————– —————
dbo.fgedu_orders customer_id order_date 98.5
dbo.fgedu_products category_id price name 95.2
# 问题3:存储空间不足
# 解决方案:清理数据或扩展存储
— 查看数据库大小
SELECT
name AS database_name,
size/128.0 AS size_mb,
size/128.0 – CAST(FILEPROPERTY(name, ‘SpaceUsed’) AS int)/128.0 AS free_space_mb
FROM sys.database_files;
GO
database_name size_mb free_space_mb
————- ———– ————-
fgedudb 102400.00 25600.00
fgedudb_log 25600.00 12800.00
— 扩展Azure SQL数据库
az sql db update \
–resource-group fgedu-rg \
–server fgedu-sqlserver \
–name fgedudb \
–max-size 200GB
GO
{
“maxSizeBytes”: 214748364800,
“name”: “fgedudb”
}
Part05-风哥经验总结与分享
5.1 SQLServer数据库云部署最佳实践
SQLServer数据库云部署最佳实践:
- 充分评估:迁移前充分评估兼容性和工作量
- 选择合适方案:根据需求选择PaaS或IaaS
- 配置高可用:配置自动故障转移和灾备
- 优化成本:合理选择规格,利用预留实例
- 加强安全:配置网络安全、数据加密
- 建立监控:配置完善的监控告警
5.2 SQLServer数据库云部署检查清单
1. 部署前检查
[ ] 需求评估是否完成
[ ] 平台选择是否合理
[ ] 规格配置是否合适
[ ] 成本预算是否确认
2. 部署配置检查
[ ] 资源组是否创建
[ ] 网络配置是否正确
[ ] 安全组规则是否配置
[ ] 存储配置是否合理
3. 数据库配置检查
[ ] 数据库是否创建成功
[ ] 字符集是否正确
[ ] 时区是否正确
[ ] 参数是否优化
4. 高可用配置检查
[ ] 备份是否配置
[ ] 复制是否配置
[ ] 故障转移是否测试
[ ] 灾备是否配置
5. 安全配置检查
[ ] 防火墙规则是否配置
[ ] 访问控制是否配置
[ ] 数据加密是否启用
[ ] 审计是否启用
6. 监控配置检查
[ ] 监控是否配置
[ ] 告警是否配置
[ ] 日志是否收集
[ ] 报表是否生成
5.3 SQLServer数据库云管理工具推荐
SQLServer数据库云管理工具推荐:
- Azure Portal:图形化管理控制台
- Azure CLI:命令行管理工具
- Azure PowerShell:PowerShell管理模块
- SSMS:SQL Server Management Studio
- Azure Data Studio:跨平台数据库管理工具
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
