SQL DBA Cheatcode : 15 Things about SQL Server Error logs


Today I am writing about some good facts about SQL Server Error logs.

 

SQL Server maintains its own error logs that contain messages describing informational and error events. “Error logs” is just the name but it contains warnings, error, information messages.

1. How to View SQL Server Error Log file location

EXEC xp_readerrorlog 0,1,"Logging SQL Server messages in file";

2. You can change the default location of SQL Server error logs by using Startup parameter -e
“-e C:\Logs\NewLogs”

3. If you are not able to login to SQL Server but want to see the error logs location:
Open SQL Server Configuration Manager
Go to Start > All Programs > Microsoft SQL Server 2005 (or 2008) (or 2008 R2) > Configuration Tools > SQL Server Configuration Manager

4. To view the SQL Server error log using management studio –
Connect to SQL Server > In Object Explorer > Expand a server > Expand Management > and then Expand SQL Server Logs. Right-click a log and click View SQL Server Log.

5. By Default SQL Server maintains 6 Error log files only. Default settings can be changed to any number between 6-99.
To change the default settings
Connect to SQL Server > In Object Explorer > Expand a server > Expand Management > and Right-click > Configure > Check the Limit box and change.

3-Change-Error-log-settings
5. Using script, you can change SQL Server error log setting

 USE [master]
 GO
 EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', REG_DWORD, 6 --> 6 is default, change this number to anything between 6-99
 GO

6. There are problems with the size of error logs. One error log file can grow up to any limit if SQL server is not restarted since a long time. On the other hand, a file can be very small if SQL server is restarted frequently.

7. There is a problem of amount of information that a file may contain, this is also dependent on SQL Server restart/recycle time.

8. SQL Server error logs can not be recycled manually or using management studio like you can do for SQL Server agent error logs. You must use

 EXEC sp_cycle_errorlog

9. As a best practice – SQL Server error logs can be recycled by creating a SQL Job which runs at a regular interval. That’s how you can prevent the problems that were mentioned in point 6 and 7.

10. SQL Server error logs can give you information about machine type. Use the script below.

 EXEC xp_readerrorlog 0,1,"Manufacturer";

manu
11. SQL Server error logs can give you the port number which is used by SQL Server

 EXEC xp_readerrorlog 0,1,"Server is listening on";

12. SQL Server error logs can give you information about Startup Parameter that are used by SQL Server

 EXEC xp_readerrorlog 0,1,"Registry startup parameters";

13. SQL Server error logs can give you information about Dedicated admin connection is used by SQL Server

 EXEC xp_readerrorlog 0,1,"Dedicated admin connection support";

14. SQL Server error logs can give you information about OS Process ID used by SQL Server

 EXEC xp_readerrorlog 0,1,"This instance of SQL Server last reported using a process ID";

15. SQL Server error logs can give you information about SQL Server authentication Mode

 EXEC xp_readerrorlog 0,1,"Authentication mode";

One response to “SQL DBA Cheatcode : 15 Things about SQL Server Error logs”