Locks Caused By Long Lasting SELECT
Jan 16, 2008
Hi,
Let's assume the client code call a stored procedure which reads: SELECT * FROM myTable WHERE ID < 100. Let's assume that for whatever reason, the query becomes very slow and takes 60 seconds to complete. This 60 secs, could be the time for the DB engine to fetch all the rows (happening before returning the resultset to client code), or during the transfer of the resultset to client code (slow network throughput).
Question1: could this prevent another user from doing SELECT on myTable? (could be onn different ID or even overlapping the ID between 1 and 100).
Question2: could this prevent another user from performing write (UPDATE/DELETE) on the rows with ID between 1 and 100?
Question3: can another user perform a write (INS, DEL, UPD) on rows outside of the ID between 1 and 100?
Thanks in advance for any help.
View 6 Replies
ADVERTISEMENT
Jan 15, 2008
Hi,
Yesterday, we have had a sudden load in our SQL Server 2000 which resulted in several locks. There was not too much time to investigate as we had to rush. A team member had reviewed the processes in EM, Manegement, Current Activity. Looking for blocking processes and killed them.
She told me that as soon as the blocking SPID was killed, another one arose and she had to repeat the operation a dozen of time. When done, the server activity was back to normal. She noticed that more than half of the blocking processes showed that they executed the stored Proc "P_SearchProducts".
We don't own the server and the information on what had happened at that time (batches or resource intensive operations, etc.) is not available for now.
The team suggests that we set the Transaction Isolation Level to Read UNCOMMITTED for this SP. I would like to know better about locks before I go ahead.
P_SearchProducts returns 5 recordsets each one could contains from 1 to 200 rows. To achieve the results, it creates about 10 intermediate tables (SELECT ... INTO #TableX) these temp tables are then used progressively to arrive to the final results. Roughly the volume of these temp tables could be double than the final results. The developer who wrote this SP is not a guru in SQL, there is room for improvement. But here are my questions:
Q1. Could the series SELECT ... INTO #TableX in P_SearchProducts prevent or lock another connection from executing the same SP? If yes, under which conditions?
Q2. Let's assume that P_SearchProducts has a slow execution time. Could it prevent another connection from updating the Product table? And thus leading to a deadlock situation? Something like another transaction (by User2) has obtained lock on most of Product tables, except the Product table which were being slowly read by User1 executing P_SearchProducts. But User1 cannot read the other product tables b/c there are locks by User2.
Q3. If the contention issue was provoked by the slow execution time of many request to exec
P_SearchProducts (let's assume there were suddenly 50 users on the web hitting the search product feature at the same time). Could the Read Uncommitted magically resolve the contention issue, providing we accept the consequences of the dirty read.
Sorry for the long post and thank you in advance for any help.
View 2 Replies
View Related
Jul 20, 2005
HiThere is an application that runs on sql server.The application selects/updates some few tables frequentlyOnce there is even a select on this table .It blocks other userssometimes for very long.Is there anything that can be done to reduce this?The table has 18000 rows and does not seem to have an indexI thought indexing might help but 18000 rows without an index isno reason for 30 minutes of lock time.I will appreciate your help as usualVince
View 1 Replies
View Related
Oct 1, 2007
We have a web-based third-party application that has both background processes and user activity requests running in the same database (SQL Server 2005 SP2). The problem is that a background process will start a long-running transaction and hold an exclusive lock on a few rows in a given table (a small table, <100 rows). The web clients need to scan this same table, but when their "select *" statements get to those locked row(s), the web client queries stall waiting for that exclusive lock to be released. This effectively brings the entire web front end to a halt because all clients must hit this table for each user action. I realize that this is the classic lock condition that multiversioning databases like Oracle, PostgreSQL, SQL Server Compact Edition, and other databases do not suffer because they don't use shared read locks like SQL Server. But since we're on SQL Server for this app, what is the way to get around this problem? Modifying the clients to use WITH (NOLOCK) is not an option... there will be major consistency issues unless the clients run in Read Committed or higher. Any ideas? We could tweak this app if needed. Does SQL Server 2008 introduce multiversioning or at least some mechanism to get around this problem? I did not see it mentioned on the Microsoft site, but maybe I missed it. Thanks in advance.
Austin
View 6 Replies
View Related
Jun 17, 2004
Hey I have a terrible problem !!
I have a query, and It doesn't matter if it has finished, the table is still locked. Is there any clause to unlock the share mod lock (force) when the query has finished or any way to ensure that table has no locks to continue with another query or transaction ?
Could you give me any sentence ?
Thanks you !!
View 4 Replies
View Related
Dec 28, 2007
We have found deadlocks in our application. Deadlocks occure between SELECT and UPDATE. I get deadlock graph using profiler and find that SELECT makes SIU lock. Below you'll find SELECT statement:
select t1.*
from MyTable t1
--self join on field1 and field2
left outer join
(select field1, field2
[Code] ....
Why SIU lock is set?
View 9 Replies
View Related
Jun 17, 2004
Is anyone have already encountered such a problem :
When a table is locked by several locks (key, pag), either a SELECT request which does not need to lock any row cannot succeed.
In SQL Server Enterprise Manager, I see that my request is waiting for a lock "LCK_M_S" !!!
How I can avoid this kind of situation which seems to me completely abnormal.
I have never been faced with this kind of problem in Oracle.
Thanks for anyone who will help me to resolve this "bug".
View 4 Replies
View Related
Jul 12, 2006
Hi,
I want to make SQLTransaction as global and use it checking the State.
But then where there are Only Select queries are going to fire, it will open transaction.
So, Does it locks database/tables when Only Select query comes in SQLTransaction.
If you have another successful way of doing this, Please suggest.
Thanking you.
tats
View 8 Replies
View Related
Jul 16, 2015
I've got an INSERT that's selecting data from a linked server and attempting to push 10 million rows into the blank table. More or less, it looks like this:
insert into ReceivingTable (
Field1, Field2, Field3, Field4
, Field5, Field6, Field7, Field8
, Field9, Field10, Field11, Field12
, Field13, Field14, Field15
[code]...
The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. There are no other active users. I ran it again and monitored the following DMO to watch the growth of locks for that spid:
SELECT request_session_id, COUNT (*) num_locks
-- select *
FROM sys.dm_tran_locks
--where request_session_id = 77
GROUP BY request_session_id
ORDER BY count (*) DESC
The number of locks started small and held for a while around 4-7 locks, but at about 5 minutes in the number of locks held by that spid grew dramatically to more than 8 million before finally erroring again with the same message. Researching, I can't figure out why it's not escalating from row locks to table locks at the appropriate threshold. The threshold in was set to 0 at first (Server Properties > Advanced > Parallelism > Locks). I set it to 5000, and it still didn't seem to work. Rewriting the INSERT to include a WITH (TABLOCK) allows it to finish successfully in testing. My problem is that it's coming out of an ETL with source code that I can't edit. I need to figure out how to force it to escalate to locking the entire table via table or server level settings.
A colleague suggested that installing service packs may take care of it (the client is running SQL Server 2008 R2 (RTM)), but I haven't found anything online to support that theory.
View 9 Replies
View Related
Dec 2, 2014
I am trying to find a way to lock rows of data used in a SELECT query from being read by another SELECT query.
I could do a "begin tran - select - update - rollback" sequence but was wondering if there is a cleaner way to do this??
Tried UPDLOCK, ROWLOCK, TABLOCK, HOLDLOCK in multiple variations but none seem to block the select.
View 9 Replies
View Related
Aug 5, 2015
We are migrating our database(s) from ORACLE to SQL. In Oracle we were able to issue a SELECT statement and see all of the locks (Blocking and Non-Blocking) currently in the system. The query also included the Process ID of the process we needed to kill in order to get rid of the lock.
We now need to create the same type of query for Microsoft SQL Server 2012. I have seen postings on different sites saying that this info can be obtained using SP_WHO2 or using the SQL Server Management Studio Activity Monitor's PROCESSES tab, but we are looking for a SELECT statement that will give us similar information.
View 7 Replies
View Related
Aug 17, 2007
I have SELECT statement that is several thousands of characters long - i'm declaring many tables, columns, and I have many aliases to deal with as well. Is there any way I can break it up into multiple lines? The only two things I could think of were using " + " . . . " + " . . . " or simply doing nothing and just dividing it into separate the lines. By the way, is there a limit to how long a SQL statement can be. I have been finding different answers when searching online.
View 5 Replies
View Related
Mar 2, 2004
Actually it's not a long jump competition but this is the easiest way to visualize it. I've been playing in the SQL sandpit for too long on this one and frankly I'm stumped! Decided to take a leap and post the query here.
Athletes take several jumps, each recording a distance; hence a row in the table consist of athlete and distance, (number of attempts is irrelevant.)
I need a select statement that will return the top jumpers.
ie. here is the resulting top 3
8.65 John Green
8.53 Adam Brown
8.14 Ian White
I hope this makes sense. Any takers?
View 15 Replies
View Related
Jan 3, 2008
Hello..
The first problem:
I have 2 tables in MS SQL database: topicstbl and txtfilestbl. And every one have column topicID.
And in both I have fulltext column I want to search in it; but in the first one I want to search in the fulltext column (topicflds) and also in normal columns (topicname and topicsn)
I need to search in these tables and get the (topicID) column as result by 1 table without repeated results.
I tried this code:
SELECT topicID, KEY_TBL.RANK FROM (SELECT topicID, 255 as RANK FROM topicstbl WHERE topicname like '%search word%' or topicsn like '%search word%') AS KEY_TBL
UNION
SELECT topicID, KEY_TBL.RANK FROM topicstbl AS topicstbl INNER JOIN CONTAINSTABLE(topicstbl, topicflds, 'search NEAR word') AS KEY_TBL ON topicstbl.topicID = KEY_TBL.[KEY]
UNION
SELECT topicID, KEY_TBL.RANK FROM txtfilestbl AS txtfilestbl INNER JOIN CONTAINSTABLE(txtfilestbl, txtfile, 'search NEAR word') AS KEY_TBL ON txtfilestbl.txtfileID = KEY_TBL.[KEY] ORDER BY KEY_TBL.RANK DESC
But the problem is the result table has repeated records (same topicID, different Rank Value).
Also I used "SELECT DISTINCT" but same problem.
The second problem:
I want to merge the previous code with ROW_NUMBER code to get results between x and y.
Like this code:
WITH OrderedOrders AS (SELECT *, ROW_NUMBER()
OVER (order by topicID DESC) as RowNumber
FROM topicstbl)
SELECT * FROM OrderedOrders
WHERE RowNumber between 1 and 50
But without change the first order.
Now how to do all these??!
View 6 Replies
View Related
Oct 11, 2006
I have a table tblCustTrans which contains
custid int
transid int
startdate datetime
value int
the custid, transid and startid are composite primary key.
the table contains more than 10 million records. Now i want to fetch record for
select * from tblcusttrans where startdate > = 10/10/2006 10:00:000 and startdate <= 10/10/2006 11:00:000
This statement is taking more than 2 hours to fetch the data. is there a way to fetch the record with less time
Regards
View 4 Replies
View Related
Jul 20, 2005
Hi All,I am facing problem in MS SQL Server 2000. It is behaving slow forselect statements. It is even slower than MS ACCESS. For example, if iuse"Select count(*) from tbl;". i get the results after long time ifthere is more than 100k rows. What might be the possible reasons forthis??ThanksHoque
View 1 Replies
View Related
Jan 3, 2007
Using ADO.Net and SQL 2005, we have an exception handler in one of our .VB classes. We extract all the information from the exception and dump the stack into an email, but we would also like to see the query that caused the exception.
Is there an easy way to get the offending query without putting a try-catch around the hundreds of queries?
Thanks.
View 1 Replies
View Related
Apr 14, 2004
I am getting error
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
StackTrace> at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) at Galileo.Modules.Data.DBDeclare.RunProcedure(String sp, IDataParameter[] parameters) at GalileoModules.Data.PrivateAccomodation.Search3.Query(String[] values
If I don't cache this page, would that help?
Any other suggestions?
View 3 Replies
View Related
Mar 23, 2000
I just installed SQL7.0 on a windows 98 machine. When I go to register a new database, I get the following message.
MMC caused a general protection fault
I have rebooted the machine, removed & reinstalled the application.
Help - what else
View 1 Replies
View Related
Apr 22, 1999
Does anyone know of any SQL errors that will stop the SQLserve.exe service? I meant the error didn't hang the SQL server service, it stopped the service (from green light to red light).
Thanks in advice for any input or ideas.
Wing
View 1 Replies
View Related
May 7, 2014
I had a database in suspect mode this morning.
Fixed it by:
-placing in emergency mode.
-set single_user mode
-dbcc checkdb(N'dbname', REPAIR_ALLOW_DAT_LOSS)
-Rebuild the log.
-bring online.
DBCC Checkdb returned a bunch of errors:
Extent (3:394032) in database ID 7 is allocated by more than one allocation object. The error has been repaired.
Msg 8913, Level 16, State 1, Line 2
Extent (3:394032) is allocated to 'GAM' and at least one other object.The error has been repaired.
--Lots of these
Repair: Deleted off-row data column with ID 562825134080, for object ID 1076927654, index ID 1, partition ID 72057594039566336, alloc unit ID 72057594044153856 (type LOB data) on page (3:393971), slot 28.
Repair: Deleted off-row data column with ID 562825199616, for object ID 1076927654, index ID 1, partition ID 72057594039566336, alloc unit ID 72057594044153856 (type LOB data) on page (3:393971), slot 29.
Repair: Deleted off-row data column with ID 562825265152, for object ID 1076927654, index ID 1, partition ID 72057594039566336, alloc unit ID 72057594044153856 (type LOB data) on page (3:393971), slot 30.
Lots of these:
Msg 8945, Level 16, State 1, Line 2
Table error: Object ID 1076927654, index ID 1 will be rebuilt.
The error has been repaired.
Msg 8977, Level 16, State 1, Line 2
Table error: Object ID 1076927654, index ID 1, partition ID 72057594039566336, alloc unit ID 72057594044088320 (type In-row data). Parent node for page (3:394009) was not encountered.
The error has been repaired.
[code]....
View 9 Replies
View Related
Feb 25, 2006
Can somebody guive me alittle guidance in how to make this? I have like 4 lookups but some can throw errors, and I need to know what happened when I go to the office in the moorning.
Thanks
View 1 Replies
View Related
May 25, 2007
My program use the mutil-threads, each thread would use AppendChunk to insert a binary file into sqlserver. But program always stopped exceptionally , But I can not catch any exception. It looks like be killed by someone or system.
Can anyone hekp me?
Thanks a lot.
View 1 Replies
View Related
Feb 23, 1999
Hello:
We have, on a devlopment server, running a long_running transaction for
almost two days. It was still running. This morning I decided to look at
three of two backup devices under EM to see if any backups were made to
these devices during the last couple of days on a de,mand basis by anyone.
The first one had a backup and the second and third device did not.
Somehow, and for some unexplained reason, the following message was put
into the MSSQL error log (and pretty much the same message went into the NT
event viewer).
----------------------------------------------------------------------
99/02/23 10:05:45.81 kernel dbsvolopen: Backup device
'E:MSSQLBACKUPEaglePro2_run02.DAT' failed to open, operating system
error = 2(The system cannot find the file specified.)
99/02/23 10:05:48.48 kernel dbsvolopen: Backup device
'E:MSSQLBACKUPEaglePro2_run02.DAT' failed to open, operating system
error = 2(The system cannot find the file specified.)
99/02/23 10:05:49.17 kernel dbsvolopen: Backup device
'E:MSSQLBACKUPEaglePro2_run03.DAT' failed to open, operating system
error = 2(The system cannot find the file specified.)
---------------------------------------------------------------------
This error, I beleive, caused DR watson to kick off and we could only sopt
it and revive the long running transaction by rebooting the machine, of
course thus requiring us to restart the lon_running transaction.
It look like NT couldn't find the backup device and therefore activated the
drwatson executible or so it seems to me.
Has anyone experienced this error before? IS it caused by NT? Or that
perhaps a certain threshhold was reacched on NT and drwatson kicked in?Any
other ideas?
Any information that can be provided would be GREATLY appreciated. THanks.
David Spaisman
View 1 Replies
View Related
May 2, 2006
I just updated MDAC on one of my machines and I'm now having trouble accessing my SQL server. It's a local connection using SQLOLEDB in a VB dll. It was working fine before the update and now I get:
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/cms25/CMS.asp, line 33
Most of the information I can find on this refers to TCP/IP connections but the SQL server is local. My connect function looks like this:
Public Sub ADOConnect()
With m_ADOConnection
.Provider = "SQLOLEDB"
.CursorLocation = adOpenStatic
.CommandTimeout = 20
.Mode = adModeReadWrite
.ConnectionString = "Data Source=" & m_strServer & ";Database=" & m_strName & ";" & m_strUsernamePassword
.open
End With
End Sub
On this server, m_strServer = "(local)". What am I missing? Thanks for any help in advance!
a.
View 3 Replies
View Related
Feb 28, 2007
Hi.I need to make a trigger which fires when after an UPDATE is done ontable A in database X. The trigger must perform a statement whichcopies some of the data from the update to table B in database Y onthe same server.My question is: Can I access the data which caused the trigger to fireor just get an indication of which entry in table A had been updated?Best RegardsJens Christian Andersen.
View 2 Replies
View Related
Mar 20, 2006
I am trying to import a fixed width file where some of the numeric columns are empty. The columns in question are defined as integer columns (of varying sizes) and I am guessing that "empty" columns come across as multiple spaces on the import.
Even though I have "Retain null values from source" checked off, I am still receiving the following error on these empty columns:
Error: 0xC02020A1 at Input Data, Flat File Source [1]: Data conversion failed. The data conversion for column "ToContractExpiryYear" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
Error: 0xC0209029 at Input Data, Flat File Source [1]: The "output column "ToContractExpiryYear" (51)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "ToContractExpiryYear" (51)" specifies failure on error. An error occurred on the specified object of the specified component.
Error: 0xC0202092 at Input Data, Flat File Source [1]: An error occurred while processing file "\Nastinus-01ClearingDataOCC20060320ser2mst.20060317" on data row 1.
If it is truly the system treating the column as spaces (and not trimming the value), then the only solution I can think off is to source everything as strings, perform a transform that executes a Trim() (Derived Column or Script ??), THEN perform a transform that converts data types, then do whatever else I need...
Am I missing something? Is this the correct solution?
View 2 Replies
View Related
Mar 23, 2007
I wanted to prevent ntbackup from locking my databases during the nightly backup, so I excluded the ...Data folder from the backup set. However, I think that ntbackup is backing up the databases during the volume shadow copy phase of the backup, even though their folder was excluded from the backup set (I verified this setting in the .bks file). Although the lock only lasts a few seconds, the error message is worrisome and I would prefer to skip the databases completely. How can I stop the volume shadow copy from doing this?
Below is the the sequence of events leading up to the error, most recent first:
Event Type: Error
Event Source: SQLVDI
Event Category: None
Event ID: 1
Date: 3/23/2007
Time: 3:01:49 AM
Description:
SQLVDI: Loc=CVDS::Cleanup. Desc=Release(ClientAliveMutex). ErrorCode=(288)Attempt to release mutex not owned by caller.
. Process=8684. Thread=7556. Client. Instance=. VD=.
Event Type: Information
Event Source: MSSQLSERVER
Event Category: (6)
Event ID: 18264
Date: 3/23/2007
Time: 3:01:48 AM
Description:
Database backed up. Database: master, creation date(time): 2007/03/12(15:08:23), pages dumped: 1, first LSN: 268:352:37, last LSN: 269:24:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'{66DC3082-FB76-4312-AD74-4BDAD9FC7209}1'}). This is an informational message only. No user action is required.
Event Type: Information
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 3198
Date: 3/23/2007
Time: 3:01:47 AM
Description:
I/O was resumed on database master. No user action is required.
Event Type: Information
Event Source: ESENT
Event Category: ShadowCopy
Event ID: 2003
Date: 3/23/2007
Time: 3:01:47 AM
Description:
lsass (956) Shadow copy 24 freeze stopped.
Event Type: Information
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 3197
Date: 3/23/2007
Time: 3:01:45 AM
Description:
I/O is frozen on database master. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.
Event Type: Information
Event Source: ESENT
Event Category: ShadowCopy
Event ID: 2001
Date: 3/23/2007
Time: 3:01:45 AM
Description:
lsass (956) Shadow copy 24 freeze started.
Event Type: Information
Event Source: NTBackup
Event Category: None
Event ID: 8018
Date: 3/23/2007
Time: 3:00:14 AM
Description:
Begin Operation
View 43 Replies
View Related
Feb 1, 2008
Hello
Am having a problem which started after I installed a databse with sqlexpress. I get this error when backing up "MSDEWriter" has reported an error 0x800423f4
I am running Windows 2003 SBS SP2.
I've checked to make sure that all of my databases are using simple in recovery mode.
Please help
Thanks
View 1 Replies
View Related
Feb 4, 2015
is it possible that this error during backup caused Sort Warning???
I sent to support of our Storage and he make result that this caused jobs which have Sort Warning....
if I checked this error on internet, i found problem with Storage or it can be also lot of fullscan and etc.
So it can be also that Order By caused some reading directly from disk and not from memory ? maybe if there is using tempdb right ?
View 3 Replies
View Related
Jan 30, 2007
Hi.I have an ancient preCambrian app that uses the db library to interface withsql server databases.It is written in c++.When testing it I noticed on one machine with sql server 2005 installed itruns fine, but on another it has some problems, notably.. it gets as a resultof a select statement with an order by clause the error:only fully keyset ddriven cursors can have 'order by', 'group by', or 'having'phrases.Error code 10080Can someone suggest a 'configuration' parameter that might be causing theotherwise identical systems to have this problem on one machine and not theother?ThanksJeffthanksJeffJeff Kish
View 1 Replies
View Related
Apr 5, 2007
Hi all,
Report:
-For instance 2 small tables (eg. width 10cm = 3 inch?)
-And one wide table (eg. width 30cm = 10 inch?)
All separated by "insert pagebreak after table".
Problem:
When rendered, the pages with the small tables on have a lot of white blank space at the right of the table. This is probably caused by the big table on page 3.
This report is distributed by email in Excell format. So on sheet 1 and 2 there are a lot of white cells on the right of the tables. When trying to print, they just want to use the "landscape" option and the "fit to page" option. Because of the empty white cells, the fit to page option reduces the first 2 tables to a very small table which covers only 50 % of the page width. The other 50 % is reserved for the empty cells.
Off course, I know that deleting the empty cells offers a solutions, but it would be a lot more handier if there were no empty cells in the first place.
Anybody with a solution?
View 2 Replies
View Related
May 29, 2007
Hello,
I created a test stored procedure in MS SQL 2000. When the problem in my app was fixed, I deleted this test stored procedure. But the backup job thinks this procedure still exist and so backup job would failed. How can I fix this problem?
Thank in advance for your assistance.
View 1 Replies
View Related