Showing posts with label among. Show all posts
Showing posts with label among. Show all posts

Thursday, March 29, 2012

deadlocks when fetching

Hi!
We are developing cgi applications, using ODBC and (among else) MSSQL.
Now we are experiencing deadlocks on MSSQL only, and the problem is -
they occur not when the query is submitted, but when rows are fetched.
We don't use transactions with several statements, so basically every
query/update/insert is in its own transaction. This is because we need
to be compatible with transaction less database systems. Because of
this, we never encounter deadlocks either, except on MSSQL. It seems
that sometimes a select gets in the way of an update in progress or
something, and the select transaction is terminated. We handle this in
our app by just re-issuing the query if a deadlock was detected on query
submittal. However, when the deadlock occurs not when the query is sent,
but when the records are fetched, handling the event becomes much
harder. We'd rather have the query fail right away, than in the middle
of fetching rows.
Any ideas how to accomplish this, using either query hints, session
settings, etc?
Regards,
Erik KnudsenIt sounds like you are using a server side cursor. Have you tried using a
client side cursor instead?
Andrew J. Kelly SQL MVP
"Erik Knudsen" <erikk@.c2i.net> wrote in message
news:eHl7B$YHFHA.3076@.tk2msftngp13.phx.gbl...
> Hi!
> We are developing cgi applications, using ODBC and (among else) MSSQL.
> Now we are experiencing deadlocks on MSSQL only, and the problem is - they
> occur not when the query is submitted, but when rows are fetched.
> We don't use transactions with several statements, so basically every
> query/update/insert is in its own transaction. This is because we need to
> be compatible with transaction less database systems. Because of this, we
> never encounter deadlocks either, except on MSSQL. It seems that sometimes
> a select gets in the way of an update in progress or something, and the
> select transaction is terminated. We handle this in our app by just
> re-issuing the query if a deadlock was detected on query submittal.
> However, when the deadlock occurs not when the query is sent, but when the
> records are fetched, handling the event becomes much harder. We'd rather
> have the query fail right away, than in the middle of fetching rows.
> Any ideas how to accomplish this, using either query hints, session
> settings, etc?
>
> Regards,
> Erik Knudsen|||Erik
http://www.sql-server-performance.com/deadlocks.asp
"Erik Knudsen" <erikk@.c2i.net> wrote in message
news:eHl7B$YHFHA.3076@.tk2msftngp13.phx.gbl...
> Hi!
> We are developing cgi applications, using ODBC and (among else) MSSQL.
> Now we are experiencing deadlocks on MSSQL only, and the problem is -
> they occur not when the query is submitted, but when rows are fetched.
> We don't use transactions with several statements, so basically every
> query/update/insert is in its own transaction. This is because we need
> to be compatible with transaction less database systems. Because of
> this, we never encounter deadlocks either, except on MSSQL. It seems
> that sometimes a select gets in the way of an update in progress or
> something, and the select transaction is terminated. We handle this in
> our app by just re-issuing the query if a deadlock was detected on query
> submittal. However, when the deadlock occurs not when the query is sent,
> but when the records are fetched, handling the event becomes much
> harder. We'd rather have the query fail right away, than in the middle
> of fetching rows.
> Any ideas how to accomplish this, using either query hints, session
> settings, etc?
>
> Regards,
> Erik Knudsen|||Andrew J. Kelly wrote:

> It sounds like you are using a server side cursor. Have you tried using a
> client side cursor instead?
We basically use (ODBC):
--
1. SQLAllocStmt()
2. SQLExecDirect()
3. SQLFetch() (repetedly)
4. SQLFreeStmt()
--
We don't explicitly use cursors, and we don't want to because some of
our supported DBMS's don't support it.
I'd like to force the deadlock to happen at SQLExecDirect() or not at
all. I guess that would involve setting some stricter (not as
optimistic) locking policy or something. Any ideas?
Regards,
Erik Knudsen|||I am not familiar with programming at the base ODBC level so I may be
incorrect here but it seems to me if you are doing a Fetch you are using a
cursor. You can run profiler to see exactly what kinds of statements are
being executed on sql servers end. I am willing to bet you will see
sp_cursorpreparem sp_cursorfetch etc. and that usually indicates a server
side cursor. What isolation level are you running under? Make sure
something is not setting it to serializable and don't assume it is not.
Again you can check with profiler to see if there is a different isolation
level being set.
Andrew J. Kelly SQL MVP
"Erik Knudsen" <erikk@.c2i.net> wrote in message
news:%23oe2mrZHFHA.2356@.TK2MSFTNGP12.phx.gbl...
> Andrew J. Kelly wrote:
>
> We basically use (ODBC):
> --
> 1. SQLAllocStmt()
> 2. SQLExecDirect()
> 3. SQLFetch() (repetedly)
> 4. SQLFreeStmt()
> --
> We don't explicitly use cursors, and we don't want to because some of our
> supported DBMS's don't support it.
> I'd like to force the deadlock to happen at SQLExecDirect() or not at all.
> I guess that would involve setting some stricter (not as optimistic)
> locking policy or something. Any ideas?
>
> Regards,
> Erik Knudsen|||Erik Knudsen wrote:
> Andrew J. Kelly wrote:
>
> We basically use (ODBC):
> --
> 1. SQLAllocStmt()
> 2. SQLExecDirect()
> 3. SQLFetch() (repetedly)
> 4. SQLFreeStmt()
> --
> We don't explicitly use cursors, and we don't want to because some of
> our supported DBMS's don't support it.
> I'd like to force the deadlock to happen at SQLExecDirect() or not at
> all. I guess that would involve setting some stricter (not as
> optimistic) locking policy or something. Any ideas?
>
> Regards,
> Erik Knudsen
Not sure if this is related, but I believe SQLAllocStmt() has been
replaced with SQLAllocHandle(). In addition SQLFreeStmt() is not
recommended in ODBC 3.0 and later (replaced with SQLFreeHandle I think).
But as Andrew mentioned, check your cursor type. probably fastest to use
a forward-only, read-only, firehose cursor with ODBC. These types of
"cursors" are not cursors in the strictest sense. They are analogous to
SQL Server generating a result set (as it normally does) and pulling
that information into the application using ODBC.
David Gugick
Imceda Software
www.imceda.com

Sunday, March 11, 2012

Deadlock : What the meaning of associatedObjectId

In 2005, when 1222 trace flag is activated, I get in the error log file, among other very useful informations, this kind of message
keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=... id=lock13c50480 mode=S associatedObjectId=72057594039304192
or
pagelock fileid=X pageid=xxxx dbid=XX objectname=.... id=lock5f69480 mode=IX associatedObjectId=72057594378518528
What is the meaning of associatedObjectId?
It always starts with 72057594xxxxx and does not look like it is related to the locked object
In my case, OBJECT_NAME and OBJECT_ID did not return any relevant information
Thanks
Med
Hi
This should match a waitresource in the process list and in the waiter list,
you should also should also see that database id for this which is probably 2
ie tempdb.
Check out Bart Duncan Blog
http://blogs.msdn.com/bartd/archive/2006/09/09/Deadlock-Troubleshooting_2C00_-Part-1.aspx
John
"Med Bouchenafa" wrote:

> In 2005, when 1222 trace flag is activated, I get in the error log file, among other very useful informations, this kind of message
> keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=... id=lock13c50480 mode=S associatedObjectId=72057594039304192
> or
> pagelock fileid=X pageid=xxxx dbid=XX objectname=.... id=lock5f69480 mode=IX associatedObjectId=72057594378518528
>
> What is the meaning of associatedObjectId?
> It always starts with 72057594xxxxx and does not look like it is related to the locked object
> In my case, OBJECT_NAME and OBJECT_ID did not return any relevant information
> Thanks
> Med
>
|||Med,
I don't know if the associatedObjectId will help you any, although you do
have the dbid and the objectname to focus your attention. From the Books
Online article "Detecting and Ending Deadlocks"
http://msdn2.microsoft.com/en-us/library/ms178104.aspx :
associatedObjectId. Represents the HoBT (heap or b-tree) ID.
RLF
"Med Bouchenafa" <com.hotmail@.bouchenafa> wrote in message
news:%23znq0EVTIHA.5516@.TK2MSFTNGP02.phx.gbl...
In 2005, when 1222 trace flag is activated, I get in the error log file,
among other very useful informations, this kind of message
keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
id=lock13c50480 mode=S associatedObjectId=72057594039304192
or
pagelock fileid=X pageid=xxxx dbid=XX objectname=....
id=lock5f69480 mode=IX associatedObjectId=72057594378518528
What is the meaning of associatedObjectId?
It always starts with 72057594xxxxx and does not look like it is related to
the locked object
In my case, OBJECT_NAME and OBJECT_ID did not return any relevant
information
Thanks
Med
|||You're right...
That's the way it is documented in the books online.
To have the object name, I run a query like this
SELECT OBJECT_NAME(object_id) FROM sys.partitions WHERE partition_id =
@.associatedObjectId
and it worked
What surprised me is the fact that they all started with 72057594xxxxx
It looks like partion_id is a component of two or more values...
Thanks again
Med
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:uSgP$qVTIHA.5404@.TK2MSFTNGP03.phx.gbl...
> Med,
> I don't know if the associatedObjectId will help you any, although you do
> have the dbid and the objectname to focus your attention. From the Books
> Online article "Detecting and Ending Deadlocks"
> http://msdn2.microsoft.com/en-us/library/ms178104.aspx :
> associatedObjectId. Represents the HoBT (heap or b-tree) ID.
> RLF
> "Med Bouchenafa" <com.hotmail@.bouchenafa> wrote in message
> news:%23znq0EVTIHA.5516@.TK2MSFTNGP02.phx.gbl...
> In 2005, when 1222 trace flag is activated, I get in the error log file,
> among other very useful informations, this kind of message
> keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
> id=lock13c50480 mode=S associatedObjectId=72057594039304192
> or
> pagelock fileid=X pageid=xxxx dbid=XX
> objectname=.... id=lock5f69480 mode=IX
> associatedObjectId=72057594378518528
>
> What is the meaning of associatedObjectId?
> It always starts with 72057594xxxxx and does not look like it is related
> to the locked object
> In my case, OBJECT_NAME and OBJECT_ID did not return any relevant
> information
> Thanks
> Med
>
>

Deadlock : What the meaning of associatedObjectId

In 2005, when 1222 trace flag is activated, I get in the error log file, amo
ng other very useful informations, this kind of message
keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
id=lock13c50480 mode=S associatedObjectId=72057594039304192
or
pagelock fileid=X pageid=xxxx dbid=XX objectname=....
id=lock5f69480 mode=IX associatedObjectId=7205759437851852
8
What is the meaning of associatedObjectId?
It always starts with 72057594xxxxx and does not look like it is related to
the locked object
In my case, OBJECT_NAME and OBJECT_ID did not return any relevant informatio
n
Thanks
MedHi
This should match a waitresource in the process list and in the waiter list,
you should also should also see that database id for this which is probably
2
ie tempdb.
Check out Bart Duncan Blog
http://blogs.msdn.com/bartd/archive...
-1.aspx
John
"Med Bouchenafa" wrote:

> In 2005, when 1222 trace flag is activated, I get in the error log file, a
mong other very useful informations, this kind of message
> keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
id=lock13c50480 mode=S associatedObjectId=72057594039304192
> or
> pagelock fileid=X pageid=xxxx dbid=XX objectname=...
. id=lock5f69480 mode=IX associatedObjectId=72057594378518
528
>
> What is the meaning of associatedObjectId?
> It always starts with 72057594xxxxx and does not look like it is related
to the locked object
> In my case, OBJECT_NAME and OBJECT_ID did not return any relevant informat
ion
> Thanks
> Med
>|||Med,
I don't know if the associatedObjectId will help you any, although you do
have the dbid and the objectname to focus your attention. From the Books
Online article "Detecting and Ending Deadlocks"
http://msdn2.microsoft.com/en-us/library/ms178104.aspx :
associatedObjectId. Represents the HoBT (heap or b-tree) ID.
RLF
"Med Bouchenafa" <com.hotmail@.bouchenafa> wrote in message
news:%23znq0EVTIHA.5516@.TK2MSFTNGP02.phx.gbl...
In 2005, when 1222 trace flag is activated, I get in the error log file,
among other very useful informations, this kind of message
keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
id=lock13c50480 mode=S associatedObjectId=72057594039304192
or
pagelock fileid=X pageid=xxxx dbid=XX objectname=....
id=lock5f69480 mode=IX associatedObjectId=72057594378518528
What is the meaning of associatedObjectId?
It always starts with 72057594xxxxx and does not look like it is related to
the locked object
In my case, OBJECT_NAME and OBJECT_ID did not return any relevant
information
Thanks
Med|||You're right...
That's the way it is documented in the books online.
To have the object name, I run a query like this
SELECT OBJECT_NAME(object_id) FROM sys.partitions WHERE partition_id =
@.associatedObjectId
and it worked
What surprised me is the fact that they all started with 72057594xxxxx
It looks like partion_id is a component of two or more values...
Thanks again
Med
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:uSgP$qVTIHA.5404@.TK2MSFTNGP03.phx.gbl...
> Med,
> I don't know if the associatedObjectId will help you any, although you do
> have the dbid and the objectname to focus your attention. From the Books
> Online article "Detecting and Ending Deadlocks"
> http://msdn2.microsoft.com/en-us/library/ms178104.aspx :
> associatedObjectId. Represents the HoBT (heap or b-tree) ID.
> RLF
> "Med Bouchenafa" <com.hotmail@.bouchenafa> wrote in message
> news:%23znq0EVTIHA.5516@.TK2MSFTNGP02.phx.gbl...
> In 2005, when 1222 trace flag is activated, I get in the error log file,
> among other very useful informations, this kind of message
> keylock hobtid=xxxxxxx dbid=XX indexname=...objectname=...
> id=lock13c50480 mode=S associatedObjectId=72057594039304192
> or
> pagelock fileid=X pageid=xxxx dbid=XX
> objectname=.... id=lock5f69480 mode=IX
> associatedObjectId=72057594378518528
>
> What is the meaning of associatedObjectId?
> It always starts with 72057594xxxxx and does not look like it is related
> to the locked object
> In my case, OBJECT_NAME and OBJECT_ID did not return any relevant
> information
> Thanks
> Med
>
>