By: Alan Cranfield | Comments (8) | Related: 1 | 2 | 3 | > Error Logs
Problem
I manage a team of Oracle and SQL Server DBAs and what often strikes me are the differing tools, methodologies and processes that are used in performing DBA tasks between and Oracle and SQL DBAs. In some cases I find SQL Server more efficient and in some cases Oracle is the clear winner. The Oracle DBAs in my team are touch typists and perform most of their tasks through multiple command line PuTTY windows whereas the SQL Server DBAs perform most of their tasks through Management Studio or other GUIs.
A really useful UNIX command which I often see the Oracle DBAs use is "tail -f". Tail is a command-line tool that displays a user-specified number of the last lines of a text file in a console window. This makes Tail great for watching log files.
Solution
You can find a Windows version of the UNIX Tail command in the Windows Server 2003 Resource Kit which you can download for free from Microsoft. Once the Windows Server 2003 Resource Kit is installed the tail command will be in your path and you'll be able to utilize it from the command line to read from the end of large error log files.
Tail for Windows syntax
tail [/?] {[/n] [/f] [[Path]FileName]
Parameters
/? - Displays command-line usage.
/n - Allows the user to specify the number of lines from the end of the file to display, where n is a decimal number. If /n is not specified, Tail shows the last 10 lines of the file.
/f - Shows the last 10 lines of the specified file name, then keeps checking for new lines. If a new line exists, it is displayed at the end of the output that is already on the screen. To exit, press CTRL+C.
Examples using Tail
Let say you have a really massive SQL Server Error Log file and its too slow to open using SSMS Log File Viewer or Notepad and you urgently need to check what the last entries were to give you and indication why it crashed. Tail can do this for you. Tail can handle very large files with ease. The following command will return the last 20 lines of the ERRORLOG.1 file:
C:\Documents and Settings\alanc>tail -20 "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG.1"
SQL Server was re-started and you're waiting for a database to recover fully. You can tail the current SQL Error Log to get an idea of the progress. Usually you would leave this running in a window on your workstation so you could keep an eye on it. The following command will return the last 10 lines of the ERRORLOG file and display any new entries as and when they get written to the error log:
C:\Documents and Settings\alanc>tail -f "\\SERVER1\C$\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG"
Next Steps
- Download the Windows version of the UNIX Tail command in the Windows Server 2003 Resource Kit for free
- Write a batch file to keep on your desktop which you can double click to spawn multiple windows 'tailing' your SQL Error Logs
- Schedule a job to output application specific performance data on a regular basis and then use tail to monitor this file
- There are a number of more advanced freeware Tail utilities out there which provide string searching and color coding functionality
- For more detailed interrogation of Microsoft's logs check out Log parser which is a powerful tool that provides universal query access to text-based data such as SQL Error Logs
- Check out these related tips:
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips