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
sqlserver数据库中已存在名为的对象怎么解决sqlserver数据库中已存在名为的对象怎么解决Apr 05, 2024 pm 09:42 PM

对于 SQL Server 数据库中已存在同名对象,需要采取以下步骤:确认对象类型(表、视图、存储过程)。如果对象为空,可使用 IF NOT EXISTS 跳过创建。如果对象有数据,使用不同名称或修改结构。使用 DROP 删除现有对象(谨慎操作,建议备份)。检查架构更改,确保没有引用删除或重命名的对象。

sqlserver服务无法启动怎么办sqlserver服务无法启动怎么办Apr 05, 2024 pm 10:00 PM

当 SQL Server 服务无法启动时,可采取以下步骤解决:检查错误日志以确定根本原因。确保服务帐户具有启动服务的权限。检查依赖项服务是否正在运行。禁用防病毒软件。修复 SQL Server 安装。如果修复不起作用,重新安装 SQL Server。

怎么查看sqlserver端口号怎么查看sqlserver端口号Apr 05, 2024 pm 09:57 PM

要查看 SQL Server 端口号:打开 SSMS,连接到服务器。在对象资源管理器中找到服务器名称,右键单击它,然后选择“属性”。在“连接”选项卡中,查看“TCP 端口”字段。

sqlserver数据库在哪里sqlserver数据库在哪里Apr 05, 2024 pm 08:21 PM

SQL Server 数据库文件通常存储在以下默认位置:Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data可通过修改数据库文件路径设置来自定义数据库文件位置。

Java连接SqlServer错误如何解决Java连接SqlServer错误如何解决May 01, 2023 am 09:22 AM

问题发现这次使用的是SqlServer数据库,之前并没有使用过,但是问题不大,我按照需求文档的步骤连接好SqlServer之后,启动SpringBoot项目,发现了一个报错,如下:刚开始我以为是SqlServer连接问题呢,于是便去查看数据库,发现数据库一切正常,我首先第一时间问了我的同事,他们是否有这样的问题,发现他们并没有,于是我便开始了我最拿手的环节,面向百度编程。开始解决具体报错信息是这样,于是我便开始了百度报错:ERRORc.a.d.p.DruidDataSource$CreateCo

sqlserver英文安装怎么更改中文sqlserver英文安装怎么更改中文Apr 05, 2024 pm 10:21 PM

SQL Server 英文安装可通过以下步骤更改为中文:下载相应语言包;停止 SQL Server 服务;安装语言包;更改实例语言;更改用户界面语言;重启应用程序。

Win11无法安装SQL Server的原因及解决方案Win11无法安装SQL Server的原因及解决方案Dec 27, 2023 pm 07:48 PM

有网友反馈,在win11上无法安装sqlserver这款软件,不知道是怎么回事,根据目前的测试来看,win11存在硬盘问题,部分接口硬盘无法安装这款软件。win11为啥不能安装sqlserver:答:win11不能安装sqlserver是硬盘的问题。1、据了解,win11存在对于硬盘的检测bug。2、这导致sqlserver无法在“三星m.2接口”硬盘上安装。3、因此,如果我们要安装的话,需要准备一块其他硬盘。4、然后将该硬盘安装到电脑里,如果没有额外插槽的话就要换掉之前的硬盘。5、安装完成后,

sqlserver数据库日志怎么查询sqlserver数据库日志怎么查询Apr 05, 2024 pm 09:06 PM

可以通过以下步骤查询 SQL Server 数据库日志:1. 打开 SQL Server Management Studio,连接到数据库服务器;2. 展开“管理”节点,导航到“SQL Server 日志”;3. 选择要查询的日志文件,右键单击并选择“查看日志文件”;4. 浏览日志记录。其他查询日志方法:使用 Transact-SQL 查询、PowerShell Cmdlet。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment