Category Archives: SQL Server

Troubleshoot Blocking

 Troubleshooting Blocking 

What is blocking? Blocking occurs when one connection to SQL Server locks one or more records, and a second connection to SQL Server requires a conflicting lock type on the record or records locked by the first connection. This causes the second connection to wait until the first connection releases its locks. By default, a connection will wait an unlimited amount of time for the blocking lock to go away. Blocking is not the same thing as a deadlock. 

How to avoid blocking

  1. Keep transaction as short as possible
  2. Use locking hints
  3. Follow best practices for Database Maintenance regularly
  4. Improve Query performance so it executes in seconds

Note:

By default, blocking locks do not time out.You can set blocking timeout using below SET statement.

SET LOCK_TIMEOUT timeoutPeriod

 How to find blocking

  1. SP_WHO2 and find the blkby column from output for blocking details
  2. Use SP_Lock to find out lock acquired by blocking query
  3. Select * from sysprocesses where blocked <>0
  4. You can get the blocking SQL Statement using DBCC INPUTBUFFER(SPID)
  5. SP_WHO2 SPID

kernel udopen: operating system error 2 in SQL Server 6.5

 

 

One of my blog reader encountered below error, I have given him the below solution which has resolved this issue.

Error: (SQL Server 6.5)

2009/07/15 19:42:26.89 spid1    Activating disk ‘ITEMPRICE_DATA1’

2009/07/15 19:42:26.89 kernel   udopen: operating system error 2(The system cannot find the file specified.) during the creation/opening of physical device F:\DATA\ITEMPRICE_DATA1.DAT

2009/07/15 19:42:26.89 kernel   udactivate (primary): failed to open device F:\DATA\ITEMPRICE_DATA1.DAT for vdn 42

2009/07/15 19:42:26.89 spid1    Activating disk ‘ITEMPRICE_DATA2’

2009/07/15 19:42:26.89 kernel   udopen: operating system error 2(The system cannot find the file specified.) during the creation/opening of physical device F:\DATA\ITEMPRICE_DATA2.DAT

2009/07/15 19:42:26.89 kernel   udactivate (primary): failed to open device F:\DATA\ITEMPRICE_DATA2.DAT for vdn 43

Solution

1) Rebuilding System Databases by running setup again from the SQL Server Install CD and do a rebuild master.

2) If it’s a 6.5 box, you can go to the console and view the sa password in the registry. run regedit from the console:
HKEY_CURRENT_USER
Software
Microsoft
MSSQLServer
SQLEW
Registered
SQL 6.5
ServerName

3) Check for the directory whether F:\ has Data directory or not

4) Check if the drive was corrupted

4) Check the SQL Server Service running on which account, check the permission of that account

5) http://support.microsoft.com/kb/180500

6) http://support.microsoft.com/kb/236989

7) Go through BOL on SQL Server 6.5 startup parameters

8) Try to login using command prompt and execute Sp_Resetstatus, DBCC CheckDB etc

sqlservr -c -f -T3608 -T4022

9) Check all the databases status from sysdatabases

 

How to find database restore history from MSDB?

MSDB database is used by SQL Server Agent for scheduling alerts and jobs and by other features such as Service Broker and Database Mail. Again SQL Server is using MSDB for storing the history of backup, restore, log-shipping details and more…

You can query the MSDB as below to get the details about the SQL Server restore history.

SELECT TOP 10 *
FROM restorehistory WITH (nolock)WHERE (destination_database_name = 'Database Name')ORDER BY restore_date DESC
All Databases

SELECT TOP 10 * FROM restorehistory WITH (nolock)ORDER BY restore_date DESC

How to improve TempDB performance?

How to improve TempDB performance? 

1) TempDB file size and physical placement on harddrive can affect the performance of a system

2) Set the tempdb recovery model to simple 

3) Do the capacity planning of the TempDB database and pre allocate the appropriate size to MDF files, which will improve performance for allocating size 

4) Put TempDB on fast I/O System 

5) Create as many tempdb data files by considering the number of cpu 

6) make all the tempdb data file size same

How to search error from SQL Server error log or SQL Server Agent Log?

How to search error from SQL Server error log or SQL Server Agent Log?

We can find the particular error or information from error log by passing below parameters to XP_ReadErrorLog extended procedure.


EXEC 
sys.xp_readerrorlog @p1,@p2,@p3,@p4

@P1 = Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc…

@P2 = Log file type: 1 or NULL = error log, 2 = SQL Agent log

@P3 = Search string 1: String one you want to search for

@P4 = Search string 2: String two you want to search for to further refine the results

Please note all the parameters are optional.