469,604 Members | 2,376 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

Locking Problem: SQL Server

Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #1
5 5298
Ray
Ritesh,

ReadPast only skips row level locks. sp_who2 will not show you the
granularity of the lock for that use sp_lock. You are correct that only
NoLock will read without blocking but it comes with a price of potentially
reading dirty pages. In SQL 2005 a new isolation level will be added called
SnapShot that will give you what you are looking for.

Ray

"Ritesh" <ri**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #2
Thanks Ray,

Can there be any solutions to SELECT statements not blocking Insert statements?

Regards,
Ritesh

"Ray" <so*****@nowhere.com> wrote in message news:<Ns*******************@newssvr33.news.prodigy .com>...
Ritesh,

ReadPast only skips row level locks. sp_who2 will not show you the
granularity of the lock for that use sp_lock. You are correct that only
NoLock will read without blocking but it comes with a price of potentially
reading dirty pages. In SQL 2005 a new isolation level will be added called
SnapShot that will give you what you are looking for.

Ray

"Ritesh" <ri**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #3
Pehaps you are asking the wrong question. I would be asking why the select
queries are running long enough to block the update queries. If applications
are written correctly then select queries should run quickly enough that
updates are not blocked for long.

Specifically in 2000 you can only use nolock or set the the isoation level
to dirty read for the query (does the same), you cannot guarantee to get
clean data if you do this. It will depend on what the users need if this is
acceptable.

Shared locks will block update locks this is correct and expected. Also SQL
2000 will only allow exclusive locks to be blocked 4 times (from memory) by
shared locks before it lets the exclusive locks through (this gives further
weight to the question as to why the select queries are taking so long)

Help this helps
Julian
"Ritesh" <ri**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #4
Ritesh,

Normally insert statement will not block on select statement. But there are
exceptions. For example, when the lock granularity of the insert is the
page level, then it can block on page lock held by select statement. If
this is the case, the force insert to take row lock using ROWLOCK will
remove the blocking. Or if the select statement is run under read repeatable
or serializable isolation level, then the select takes some kind of key
range lock which prevents insert into the range locked. If this is the
case, changebthe select isolation level to read committed will remove
blocking. Finally you may need to do some homework to find out which lock
the insert is blocked on by the select, which you can query sysprocesses and
syslockinfo to find out.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ritesh" <ri**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #5
Hi,

You are correct but the problem is my select queries are blocking
insert statements and select statements are running in default
isolation level. The problem is, I inheriated this design, which is
OLTP in nature but the DB is also queried extensively for newly
inserted records.

Can there be any way to completely avoid just inserting records
(showing in the query. It is acceptable for business logic, say
READPAST will do.) and also the query (same select query) not blocking
newly inserting records but not reading any dirty data? or I am asking
to much from SQL Server? :)

What do you say?

Thanks & Regards,
Ritesh Khanna

"Gang He [MSFT]" <ga**************@microsoft.com> wrote in message news:<42********@news.microsoft.com>...
Ritesh,

Normally insert statement will not block on select statement. But there are
exceptions. For example, when the lock granularity of the insert is the
page level, then it can block on page lock held by select statement. If
this is the case, the force insert to take row lock using ROWLOCK will
remove the blocking. Or if the select statement is run under read repeatable
or serializable isolation level, then the select takes some kind of key
range lock which prevents insert into the range locked. If this is the
case, changebthe select isolation level to read committed will remove
blocking. Finally you may need to do some homework to find out which lock
the insert is blocked on by the select, which you can query sysprocesses and
syslockinfo to find out.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ritesh" <ri**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by john smile | last post: by
2 posts views Thread by Randall Sell | last post: by
16 posts views Thread by Nid | last post: by
15 posts views Thread by z. f. | last post: by
7 posts views Thread by Shak | last post: by
3 posts views Thread by David C. Barber | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.