search
HomeDatabaseMysql TutorialSQLServer日常维护事项

SQLServer日常维护事项

Jun 07, 2016 pm 03:51 PM
sqlserverdailyPurposemaintain

1. 目的 1.1.1. 监控数据库的当前运行状况,确保数据库稳定运行 1.1.2. 监控数据库的备份 /HA状况,减少问题发生时的风险和责任 1.1.3. 监控数据库的整体运行状况,对数据库的性能进行调整,确保数据库高效运行 1.1.4. 尽可能减少紧急故障发生频率 1.1.5. 尽

1.      目的

1.1.1.  监控数据库的当前运行状况,确保数据库稳定运行

1.1.2.  监控数据库的备份/HA状况,减少问题发生时的风险和责任

1.1.3.  监控数据库的整体运行状况,对数据库的性能进行调整,确保数据库高效运行

1.1.4.  尽可能减少紧急故障发生频率

1.1.5.  尽早发现系统存在的潜在问题,使可能的故障消除在萌芽状态

2.      操作系统环境监控

2.1.       检查系统日志

2.1.1.  使用“事件查看器”,查看系统日志,关注错误信息排查错误。

2.1.2.  重点关注与SQLServer相关的日志信息。

2.1.3.  及时备份与清理过期的日志信息。

2.2.       检查磁盘空间

2.2.1.  检查数据文件所在的磁盘空间使用情况

2.2.2.  检查日志文件所在的磁盘空间使用情况

2.2.3.  检查备份的磁盘空间使用情况

3.      数据库性能监控

3.1.       内存

3.1.1.  dbcc memorystatus

 

dbcc memorystatus
  /*
 
重点查看buffer counts部分
 
其中committed memorytarget memory最重要。
  Committed memory
表示sql server已经得到的内存数量
  target memory
表示有效运行所需的内存数量。
 
当两个存在差别过大,说明可能存在内存压力
  */

3.1.2.  SQLServer:Buffer Managerà       Page Life Expectancy显示数据页在缓冲池中驻留的时间长度(单位是秒)。值越大,系统越健康。如果存在内存瓶颈,这个值会低于300s或者更少。

3.1.3.  SQLServer:Buffer Managerà       Buffer cache hit ratio显示数据库内存命中率,所请求的数据或者说页面在缓冲池被找到的次数,如果很低说明内存不足,此值一般大于98%

3.1.4.  SQLServer:Buffer Managerà       Stolen pages当这个指标与目标内存页面数比例较大时可能存在问题。

3.1.5.  SQLServer:Buffer Managerà       Memory Grants Pending显示等待内存授权的进程队列。这个指标值为0时理想状态。

3.1.6.  SQLServer:Buffer Managerà       Checkpoint pages/sec显示检查点操作每秒写入磁盘的脏页数目。如果这个值很高,说明缺少内存。

3.1.7.  SQLServer:Buffer Managerà       Lazy writes/sec显示每秒将脏页从内存写到磁盘的次数。这个值应该尽可能接近0,当大于20或者更多,确信缓冲池不够。

3.2.       磁盘

3.2.1.  PhysicalDiskàAVG.Disk Aueue Length显示每一个磁盘的队列长度。不要选择_TOTAL对象,而是查看某驱动盘符的队列长度,如果参数值持续大于2,则可能影响性能。

3.2.2.  PhysicalDisk?AVG.Disk sec/Read显示每次读取的平均磁盘时间,理想情况下值小于10毫秒。

3.2.3.  PhysicalDisk?AVG.Disk sec/Write显示每次写入的平均磁盘时间,理想情况下值小于10毫秒。

3.2.4.  SQL Server?Access Methods?Fullscans/sec显示每秒请求完全索引扫描或者全表扫描的数目,如果扫描频率每秒大于1,那么说明索引缺少或者索引比较差。

3.2.5.  SQL Server?Access Methods?PageSplits/sec显示每秒页面拆分的次数。可以通过适当的索引维护或者好的填充因子来避免发生。

3.3.       CPU

3.3.1.  System?Processor Queue Length显示系统队列长度,如果平均值大于3,那么说明cpu存在瓶颈

3.3.2.  Processorà%Privilege Time显示操作系统内部操作所花费的时间。

3.3.3.  SQL ServeràSQL StatisticsàSQL Compilations/sec显示查询计划的编译次数。

3.3.4.  SQL ServeràSQL StatisticsàSQL Re-Compilations/sec显示查询计划的重编译次数。

3.3.5.  SQL Compilations/sec和SQL Re-Compilations/sec次数过高的话,说明可能未使用绑定变量导致计划重新编译,或者说重新编译次数比编译次数过高的话,那么说明存在应用上的瓶颈。

4.      数据库维护

4.1.       主数据库(业务数据库)

4.1.1.  查看数据库的增长情况,每周增长量应该处平稳状态,如果出现异常增长,则需要注意查看原因。

4.1.2.  注意数据文件所在磁盘的空间,保证至少有一周的增长量空间。

4.1.3.  查看每个日志文件的增长情况,每周增长量应该处平稳状态,如果出现异常增长,则需要注意查看原因

4.1.4.  注意日志文件所在磁盘的空间,保证至少有一周的增长量空间。

4.1.5.  日志文件超大后,可考虑是否进行清理,如果清理使用备份日志然后收缩日志文件。

4.2.       镜像数据库

4.2.1.  除日志清除外步骤同主数据库

4.2.2.  镜像数据库日志文件超大后,可以在主数据库上进行日志清理操作。

4.3.       辅助数据库(Log Shipping)

4.3.1.  除日志清除外步骤同主数据库

4.3.2.  备用数据库日志文件超大后,可以在主数据库上进行日志清理操作。

4.4.       查看作业运行状况

可以通过以下脚本查看作业状况或者通过图形界面“作业活动监视器”查看

 

--0:Fail 1:Succ 3:Cancel 5:First run and msdb.dbo.syscategories.category_id not between 10 and 20
 
select 
      category = jc.name, category_id = jc.category_id, job_name = j.name, 
      job_enabled = j.enabled, 
      last_run_time = 
cast(js.last_run_date as varchar(10)) + '-' + cast(js.last_run_time as varchar(10)), 
      last_run_duration = js.last_run_duration, 
      last_run_status = js.last_run_outcome, 
      last_run_msg = js.last_outcome_message + 
cast(nullif(js.last_run_outcome,1as varchar(2)), 
      job_created = j.date_created, 
      job_modified = j.date_modified 
 
from msdb.dbo.sysjobs j 
 
inner join msdb.dbo.sysjobservers js on j.job_id = js.job_id 
 
inner join msdb.dbo.syscategories jc on j.category_id = jc.category_id 
 
where j.enabled = 1 and js.last_run_outcome in (0,1,3,5

4.5.       查看镜像状态

可以通过以下脚本查看镜像状态或者通过“镜像监视器”查看

 

select 
      dm.mirroring_partner_instance,
 
dm.mirroring_role,
 
dm.mirroring_state,
 
dm.mirroring_witness_state,
      dm.mirroring_safety_level,
 
dm.mirroring_witness_name 
 
from
 
sys.database_mirroring dm
 
join sys.databases d on (dm.database_id=d.database_id)
 
where (d.name=N'dbname'and mirroring_guid is not null

4.6.       查看Log Shipping状态

可以通过以下脚本在监视服务器上执行查看日志传送状态

 

use master
 
go
 
exec sp_help_log_shipping_monitor
 
go
 
exec sp_help_log_shipping_monitor_primary 'TestServer1','Northwind'
 
go
 
exec sp_help_log_shipping_monitor_secondary 'TestServer2','Northwind'
 
go

4.7.       查看备份状况

4.7.1.  查看备份是否成功

4.7.2.  验证备份集(RESTORE VERIFYONLY )

4.7.3.  定期做数据库灾难恢复的演练(其中包括备份还原,HA)

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment