MS SQL的日志信息/日志记录,可能对你来说,既熟悉又陌生,熟悉是因为你可能一直都在使用,查看、关注一些日志信息/记录,例如,作业历史记录;陌生是因为你可能从不关注日志信息/记录的管理,这里我一直用日志信息/记录这个词,而没有用日志文件这个词来阐
MS SQL的日志信息/日志记录,可能对你来说,既熟悉又陌生,熟悉是因为你可能一直都在使用,查看、关注一些日志信息/记录,例如,作业历史记录;陌生是因为你可能从不关注日志信息/记录的管理,这里我一直用日志信息/记录这个词,而没有用日志文件这个词来阐述,是想让大家把它和事务日志文件(ldf)区分开来,香港服务器租用,网上你用日志文件做搜索关键词,可能搜出来的都是事务日志相关的信息。其实它真的也叫日志文件,这篇文章我大概从日志记录分类、如何查看日志记录、日志记录的位置、日志记录的设置、为什么错误日志会暴增、如何清除日志记录等方面来讲述。
日志记录分类
按日志文件查看器,习惯将错误日志归为SQL SERVER、 SQL SERVER 代理, Windows应用程序日志,数据库邮件等四类错误日志记录。如果还考虑维护计划、远程维护计划、作业历史记录日志信息,总共是7类日志信息文件。
其中Windows应用程序日志类型又分为系统日志(System)、安全日志(Security)、应用程序日志(Application), PatchLink日志等几种,我在服务器(Windows Server 2008 R2 Standard)上打开SSMS,居然发现又多了HardwareEvents, Internet Explorer、Windows PowerShell等日志文件。这些都是系统的日志文件。你不必太纠结有多少种。
日志记录位置
SQL SERVER日志记录、 SQL SERVER代理记录的位置如下所示, SQL SERVER日志记录一般存储在ERRORLOG.n(n为数字)文件里, SQL SERVER代理日志记录位于SQLAGENT.n这类的文件里。当然这跟数据库的版本也有关系:
版本
路径
SQL SERVER 2005
Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG
SQL SERVER 2008
Program Files\Microsoft SQL Server\MSSQL10.实例名\MSSQL\LOG
SQL SERVER 2008 R2
Program Files\Microsoft SQL Server\MSSQL10_50.实例名\MSSQL\LOG
SQL SERVER 2005,默认情况下,错误日志位于 Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG 和 ERRORLOG.n 文件中。其中MSSQL.n的区分为:
MSSQL.1:SQLSERVER
MSSQL.2:SSAS
MSSQL.3:SQLExpress
MSSQL.4:SSRS
所以,一般情况下,你只需要关注MSSSQL.1目录下的日志文件
那么,数据库邮件日志记录位于哪里呢?作业历史记录日志信息、Windows应用程序日志又位于哪里呢?是不是从没考虑过这些?
数据库邮件日志记录信息可以从视图msdb.dbo.sysmail_event_log查询得到,实质保存在[dbo].[sysmail_log]表里面。
sysmail_event_log
作业历史记录日志信息都保存在msdb.dbo.sysjobhistory的表里面,其中run_status字段代表作业执行状态
0 = 失败
1 = 成功
2 = 重试
3 = 已取消
4= 正在进行
所有Windows应用程序日志其实都位于同一位置%SystemRoot%\System32\Winevt\Log。像Application日志文件位于%SystemRoot%\System32\Winevt\Logs\Application.evtx,如下所示,
查看日志记录
查看日志记录可以确保进程(例如,备份和还原操作、批处理命令或其他脚本和进程)成功完成。此功能可用于帮助检测任何当前或潜在的问题领域,包括自动恢复消息(尤其是在 SQL Server 实例已停止并重新启动时)、内核消息或其他服务器级错误消息。
方式1: 查看错误日志文件
对SQL SERVER、SQL SERVER AGENT日志记录信息,你可以直接去log目录下找到ERRORLOG、SQLAGENT日志文件,直接打开查看;而像Windows应用程序日志记录,去到%SystemRoot%\System32\Winevt\Log目录,找到对应的日志文件,直接打开查看。
方式2:通过SSMS来查看日志记录
查看与常规 SQL Server 活动相关的日志
查看与作业相关的日志
查看与维护计划相关的日志
方式3:用脚本查看
3.1 对于SQL SERVER日志文件,可以通过下面脚本查看:
--查看日志文件的存档号
EXEC master.dbo.sp_enumerrorlogs
用这个命令可以查看日志文件的大小,这个非常有用,你可以把大小异常的文件给排查出来。
--根据存档号查看该档日志内容
EXEC master.dbo.xp_readerrorlog 1
--根据job_id查看SQL SERVER日志记录
SELECT * FROM msdb.dbo.sysjobhistory WHERE job_id='36E9232B-CD5B-4646-9BED-B8242090FFF9'
3.2 对于作业历史记录日志信息,你既可以通过下面存储过程查看,也可以直接查询对应的表。
例如,服务器空间,我要查看作业“ServerDiskCapacityCheck”的历史记录
Code Snippet
3.3数据库邮件记录查看
SELECT * FROM msdb.dbo.sysmail_event_log;
日志记录管理
设置最大错误日志文件数
1:在对象资源管理器中,连接到 SQL Server 数据库引擎实例,再展开该实例。

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Dreamweaver Mac version
Visual web development tools
