SQL SERVER operation and maintenance inspection series three - structure design

foreword

  Doing a good job in daily inspection is an important step in database management and maintenance, and it is necessary to register the date and results of each inspection, and may need to issue an inspection report.

  This series aims to address some common pitfalls:

  • I don't know what to check
  • I don't know how to check easily
  • Too many machines, check up trouble
  • Difficulty in generating reports and inability to visualize results

 

  The first two articles have inspected the server software and hardware configuration and database overview. Next, we will inspect some structural designs of the database. These inspections are mainly aimed at some unoptimized structural designs in the early stage of system development or when new functions are added or added to the system. Structural changes due to operational changes.

Physical structure overview

  Check the information of each database in [Check Items] - [All]. When the database structure fails the regular check, the platform will prompt a warning.

  Note: The check information mainly includes irregular tables, missing indexes, foreign keys without indexes, unused indexes, duplicate indexes, and aging indexes.

  

 

  

irregular table

  In [Database] - [Irregular Table], check whether the table in the system has irregular design. These irregular designs mainly include no clustered index, old data types are used, and the columns of the clustered index are randomly increased (GUID, uniqueidentifier type)

  Note:

  1. Microsoft recommends clustered indexes in all tables. In addition to improving query performance, clustered indexes can be regenerated or reorganized on demand to control table fragmentation.

  2. The ntext, text, and image  data types  will be removed in a future version of  Microsoft SQL  Server. Avoid using these data types in new development work, and consider modifying applications that currently use these data types. Use  nvarchar(max) , varchar(max),  and  varbinary(max) instead .

  3. The clustered index itself is to be sorted, and the GUID (uniqueidentifier type) causes too many page splits when inserting data.

  

 

缺失索引

  (图略)

  数据库设计中索引是性能的一大关键,当数据库缺失大量索引,那么也必然导致数据库的性能很差。

无索引外键

  (图略)

  • 对主表数据操作时(如删除),需要到外键表中查找校验,如果缺少外键索引可能导致全表扫描,严重影响性能。

  • 当在查询中组合相关表中的数据时,经常在联接条件中使用外键列,方法是将一个表的 FOREIGN KEY 约束中的列与另一个表中的主键列或唯一键列匹配。索引使 数据库引擎可以在外键表中快速查找相关数据,提升性能。

没有使用的索引

  (图略)

  随着开发和优化的进行,很多人会对数据库进行索引的创建操作,很多时候创建了一个较优的联合索引或者覆盖索引,会让原本单列的索引失去使用的场景,这部分索引会出现在,长时间未使用的索引中,建议删除。

重复索引

  (图略)

   随着开发和优化的进行,很多人会对数据库进行索引的创建操作,那么页难免会产生一些功能相近或相同的索引,索引本身也是有维护成本,在更新、插入、删除时会有一定的开销,那么重复的索引只会增加这部分维护开销。

老化的索引

  (图略)

  索引维护是配置常规维护任务之一,随着数据的不断写入和变更,会产生大量的索引碎片,缺少维护任务的索引,无法及时重新组织索引数据,导致索引低效,甚至失效。

 

程序设计结构概览

  1.在【检查项】-【结构设计】中查看会话信息和执行计划,当设计结构未通过常规检查,平台会提示出警告。

  注:检查信息主要会话隔离级别、是否存在带有事务的长时间会话、执行计划中是否存在隐式转换。

  

 

 会话信息

  1.在【会话】-【空闲会话】中查看会话信息。

  注:主要关注,长时间未关闭会话和长时间未关闭并带有事务的会话。长时间带有事务的会话可能是因为程序连接泄露导致,长时间带有事务会阻塞其他会话的正常进行,造成系统卡死等严重性能问题。

 

  2.在【会话】-【概览】页中查看会话详细信息,主要关注事务隔离级别。

  事务隔离级别简述:事务隔离级别主要控制查询(共享锁),隔离级别越高并发能力就越差。(详细信息请参见:平台技术资料,最佳配置)

  如果在程序中发现大量REPEATABLE_READ(可重复读)或SERIALIZABLE(可序列化),请检查程序是否有必要使用高级别的隔离级别,而导致阻塞等待增加,数据库并发能力下降。
  
  注:如果在系统中存在大量高级别的事务级别,请确认是否需要高的隔离级别而牺牲并发能力。

  

隐式转换

  存在隐式转换的执行计划:语句存在隐式转换导致性能消耗,或不能使用索引。

  注:隐式转换常发生在表设计的字段类型(varchar)优先级别低于程序传递的参数类型(nvarchar)

  在【执行计划】-【隐式转换】页中查看具体信息。

 

 

总结

  整个程序和数据库是否稳定、高效和结构设计的好坏密不可分,在巡检过程中,结构设计时比较重要的一部分。很多时候运维人员和设计人员、开发人员沟通不畅、专业技能有差距,所以结构设计常常出现问题。

Guess you like

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