[Capacity Improvement] Introduction to SQL Server Common Problems and Quick Solution Suggestions

foreword

  This article aims to help SQL Server database users understand common problems and quickly resolve them. These problems are the general management problems of the database, and provide a general common problem framework for many friends who do not have a deep understanding of the database.

  The following problems are common problems found in the diagnosis of nearly 1,000 database users. This article is divided into [Common Problems Diagnosis Process] - [Common Problems] - [Suggestions for Quick Solutions to Common Problems]

Common problem diagnosis process

  Overview Module - [Summary] Understanding the System

 

  1. Understand system performance (statement execution time, session waits)

 

 

Statement execution time: the abscissa is the time range, and the ordinate is the number of statements distributed within the range at the execution time.

(This example: There are 1103 statements with a statement execution time of 3-5 seconds during the collection time, and a large number of slow statements in 5-10 seconds and 10-20 seconds, indicating that the system statement execution is slow and the system has performance problems)

 

 

Session-waiting type: the horizontal axis is the waiting type, and the vertical axis is the waiting number.

(This example: a lot of waiting occurs in the system, indicating that there is a performance problem in the system)

  1. Understand system health metrics (CPU, memory, disk counters)

Diagnose system bottlenecks and bottleneck-generating resources through 3 main counters.

 

 

 

 

  1. Understand system request pressure (batch requests/second, connections)  

Understand the number of statements requested per second in the system and the number of connections opened by the system, and grasp the level of system pressure.

(Note: You can collect and analyze multiple times to master the system pressure fluctuation and processing capacity)

 

 

 

  1. Understand the severity of system problems (check items, SQL error log types)

Understand potential risks and defects in the system

(Red: high severity, all problems are recommended to be solved)

 

 

  [check item] module - [all] found system problems

 

 

The problems and hidden dangers of the system are presented from the aspects of the system, parameters, sessions, performance counters, query statements, jobs, logs, execution plans, tempdb, and business databases.

(Green: Configuration Standard, Blue: Low Severity, Orange: Medium Severity, Red: High Severity, Possible Risk)

common problem

 

 

  performance issues

  1. The performance parameter configuration is unreasonable: the hardware cannot exert the maximum performance
  2. Serious system waits: causing statements to run slowly
  3. High number of statements executed for more than 3 seconds: poor customer experience
  4. There is a missing index condition: causing the statement to run slowly and consuming too much system resources

  Environmental issues

  1. Disk Space Planning Issues: Insufficient Disk Space or Unable to Meet Future Businesses
  2. The patch is not up to date: some functions are abnormal due to bugs in the Microsoft version.

  backup problem

  1. 备份缺失:故障发生会导致全部数据丢失
  2. 备份计划不合理:导致性能问题或长时间数据丢失风险
  3. 备份文件与数据文件同盘:磁盘发生故障,导致数据与备份一起丢失或损坏

  可用性问题

  1. 数据库单点风险:发生故障会导致业务中断,故障导致数据丢失

  安全问题

  1. 缺少数据一致性检查(checkdb):不能及时发现数据损坏而最终导致数据库故障和数据丢失
  2. 大量登录失败:检查系统是否受到攻击或是否程序修改导致大量登录失败

  结构设计问题

  1. 超过10分钟会话并带有事务:长时间存在不提交事务,会导致程序阻塞,检查应用程序是否有连接泄露
  2. 存在隐式转换:导致不能使用索引(例:表字段定义varchar,程序传参类型为nvarchar)
  3. 表缺少聚集索引:导致性能问题
  4. 表上外键缺失索引:导致性能问题

快速解决问题与常规建议

快速解决性能问题

   配置系统参数

查看不合理参数—点击操作按钮

 

 

在弹出页查看当前运行值,与建议值。

 

 

弹出优化配置脚本—如需修改复制文本—在服务器运行即可修改

  添加缺失索引

在【数据库】模块的【缺失索引】中,创建数据库的缺失索引。

 

 

注:并非所有提示的索引都需要创建,根据【平均影响百分比】【平均用户开销百分比】【用户查找次数】情况综合评价,建立系统中缺失的重要索引。并综合【相等列】【不等列】【包含列】创建包含多种情况的最优索引。

  根据执行频率和开销分析重点语句

在【查询语句】模块的【查询语句】-【汇总视图】中,通过【执行次数】或【cpu时间】【读次数】【写次数】【影响行数】等对重点语句,重点优化。

 

 

点击语句可以进入【分类视图】,语句的详细执行信息页

 

 

 

在【分类视图】页面,可以点击语句进入【关联项】查看每条语句执行的具体信息及执行计划,等待等信息。

 

 

环境问题的建议

  磁盘规划

  1. 按照文件类型划分:数据文件、日志文件、tempDB文件、备份文件,分别放在一个物理磁盘(4块物理磁盘)
  2. 按照数据库划分:不同的业务数据库(压力大的)分别放在一个物理磁盘,tempDB和备份文件各一个物理磁盘。(大型业务库数+2)

  操作系统与版本

  1. 建议使用64位操作系统和SQL SERVER软件
  2. 建议SQL SERVER补丁为最新补丁

备份问题的建议

  1. 中小数据库备份方案:每天全备份、一小时一次日志备份。
  2. 大型数据库备份方案:每周全备份、每天差异备份、一小时一次日志备份。
  3. 备份文件与数据文件放置在不同物理磁盘
  4. 备份文件拷贝异地(容灾)

可用性建议

任何数据库为了保证业务的连续性和高可用性,以及数据的安全性,都必须采用高可用方案规避单点的风险。

数据库主流的高可用技术:Always On可用性组,SQL故障转移群集,日志传送技术,镜像技术,及moebius负载均衡集群

安全问题建议

  账号安全与权限管理

通常的情况下,我们都是通过sa进行设置密码的,而且在config文件里面明文的写上我们的帐号和密码,这样的设计存在很大的安全隐患,无论是受攻击还是误删除都会给系统带来严重的后果,建议对用户进行权限规划,账号划分等安全措施。

  维护任务CHECKDB保证数据安全

接触过上百家客户因为没有及时发现数据页损坏而导致的数据库不可用或数据丢失,建议每周运行及时发现数据库损坏。

结构设计的建议

  聚集索引与外键索引

在表结构设计中建议表中都有聚集索引,外键添加索引,以提升性能。

  隐式转换

在数据库物理设计和程序调用设计时字段类型不匹配(程序传入的类型转换优先级高于数据库中字段类型,如表中varchar 而程序传入nvarchar)会发生隐式转换,隐式转换增加数据库性能消耗,还会使索引无法使用而导致严重的性能问题。

通过工具语句的【执行计划】中找到对应的隐式转换处,分析程序传入和数据库表设计综合解决。

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326391305&siteId=291194637