Wednesday, March 21, 2012
non-logged operations
We have a DB with the option "select into/bulk copy" set to true.
When non-logged operations happens, the backup of the transaction log fail, so we do a differential backup instead and everything is ok.
My questions are:
UPGRADING to SQL 2K,
1 Do we have to choose the "Bulk-Logged" recovery model?
and if so,
2 Do we still need to run differential backup because backup of t-log will fail as on SQL 7.0?
Can somebody help me with this?
TIA.
Franco
:cool:In BULK_LOGGED recovery mode certain bulk operations are only minimally logged increasing performance and decreasing log size. Performing builk operations do not require you to process backup, since they are actually logged thoughout BCM page. For every datafile there is one BCM page where one bit correspond to extent modification by minimally logged operation. When you perform tran log backup, sql scans BCM and backups these extents. As a result you are getting larger tranlog backups then in FULL mode.
HTH,
OBRP
Friday, March 9, 2012
NoLock vs ReadPast
I have been experiencing deadlock errors with two stored procs that I am using.
SP1 is a read query that gets all unprocessed orders (status = 0)
SP2 is an insert query that inserts new orders (Status = 0) uses a transaction.
I have a multithreaded application and once in a while the read query (SP1) will try to read a new row that has just been inserted but not committed yet hence the deadlock arises.
If i use a hint "With(NoLocks)" this will be a dirty read and still read the uncommitted insert from SP2 - is this correct?
Where as if I use hint "With(ReadPast)" this will now only read committed rows and hence the deadlock should not arise - it will not read any uncommitted rows - Correct?
So I think that it is better to use READPAST than NOLOCK. Any orders that have status = 0 not picked up will get picked up on the next round when SP1 is executed again.
Any thougths or suggestions are always appreciated.
Jawahar
I have a lot of experience with NOLOCK. The basic different in NOLOCK and READPAST is that NOLOCK will read the uncommitted data, preventing blocking because of that specific read. However, READPAST skips those rows. If you are updating a row, then NOLOCK reads the uncommitted data if the transaction is still open. If you use READPAST, it doesn't read the row at all, as I understand it.
Since I have a lot of experience with NOLOCK, I would suggest NOLOCK because I understand it a lot better.
I'm not all that convinced that your reads are causing DEADLOCKS however. I wonder if you are getting multiple inserts or updates that are blocking each other. The read locks (READ COMMITTED), by default, will just wait until the insert is done and then read the new inserted row. NOLOCK just tells it not to wait and reads UNCOMMITTED.
To test this, I would use NOLOCK and see if you still have the same problem.
|||I would almost never suggest you use NOLOCK in a production environment. You don't want to have any chance that you have two users fetching the same row to process. So I would suggest you use readpast to read only committed rows, but skip those that are being inserted, in case that row fails.
As for deadlocks, I can't exactly fathom why this is occurring from the limited information. It is possible that you have indexing problems, causing full table scans to occur on selects... Can you post the table structure and queries.
|||I disagree about the production comment. If you are pulling reports, you want to be able to pull the same record quickly--regardless of locks. As for selecting the same record by two users at the same time, that would occur anyway whether you use NOLOCK or not--assuming that there is not an open transaction modifying the situation.|||There is a possibility for rows to show up twice when using NOLOCK because of page splitting so beware of the hint unless you know exactly how your data is used. This does not mean you should never use NOLOCK of course, there are many situations in which it is completely sane to use it but just remember the consequences.|||Chris:
I think you have misunderstood what Louis means. I think here when he says "production" he means as part of a record-updating process -- in which case if you are reading a record for update you would never want a dirty read -- using a NOLOCK hint -- but always want a "clean" read of the data.
|||Dave
Dave,
I think you are correct. I agree with the statement in that case :)
|||
All thank you for your insight
Here are my two sp that cause the Deadlock to occur sometims - I have poseted the queries ony not the whole SP with input paramters etc but the queries are the guts of the SP. I did tunr on Deadlock tracing and these SP were identified as the cause of the deadlock situtation - Many thanks -Jawahar
SP 1 - Read (currently there are no hints) - PLEASE note the queries are not optimized and do not follow good coding standards)
BEGIN
set rowcount @.nMaxMessages
select A.* from MsgRequest A
where ProcessingCode = 0
and RequestID = ( select Min(RequestID) from MsgRequest B where A.ClientID= B.ClientID and B.ProcessingCode = 0 )
and A.ClientID NOT IN (select ClientID from MsgRequest where ProcessingCode = 1)
order by ReceiveDT ASC
END
SP 2 Insert (currently there are no hints) - PLEASE note the queries are not optimized and do not follow good coding standards)
BEGIN
BEGIN TRAN
insert into MsgRequest ( ReceiveDT, ClientID, CommandCode, ProcessingCode, MessageLen, QueryParameterString,
MessageData, ServiceOrderID, NewServiceOrderFlag, ClientVersionNumber)
Values ( getdate(), @.ClientID, @.CommandCode, @.ProcessingCode, @.MessageLen, @.QueryParameterString,
@.MessageData, @.ServiceOrderID, @.NewServiceOrderFlag, @.ClientVersionNumber)
if (@.@.error != 0)
BEGIN
RAISERROR 20001 'Error in csp_MsgRequestInsert'
ROLLBACK TRAN
RETURN(1)
END
COMMIT
return (0)
END
Jawahar:
Is the RequestID column unique in the MsgRequest table? That is, is the RequestID a key to this table? Also, is the data returned by this procedure used as a select list or is this potentially used as the basis for a record update?
|||Dave
Dave,
Yes the RequestID is the Primary key
The data from the select is processed row by row using a multithreaded system. We run a windows service (multithreaded) to process the data (new orders).
Jawahar
|||Jawahar:
There are a few other things that I need to know:
How many rows are in the MsgRequest table ?|||
You need to first determine the cause of the deadlock before trying to use locking hints. What version of SQL Server are you using? Did you enable trace flag # 1204? In SQL Server 2005, there is a new trace flag# 1222 and trace events that will help identify the cause. See link below for troubleshooting steps for SQL Server 2000:
http://support.microsoft.com/default.aspx/kb/832524/
|||Jawahar:
Umachandar is right about the need to fully understand your deadlock. But I went ahead and attempted to mock up your select query.
First, I created an index on the MsgRequest table based on (1) ProcessingCode, (2) ClientID and (3) requestID. I figured that the requestID component was not completely necessary but I wanted to avoid some bookmark lookups so I included. When I got all done testing I tried recreating the index without the requestID component and found that when I removed the requestID component from the index my logical reads increased from 38 to 4007 so I left it in.
I was able to improve on the performance of your select query by eliminating one of the scans through the MsgRequest table. The query I used was:
select A.*
from msgRequest A
inner join
( select clientId,
max (processingCode) as max_processingCode,
min (requestID) as min_requestID
from msgRequest p
where processingCode between 0 and 1
group by clientId
) b
on a.requestID = b.min_requestID
and max_processingCode = 0
order by ReceiveDT ASC
This query returned for me the same rows as your original query was returning and ran with far less logical IO. I don't like the A.* syntax, but like you said ... Sometimes you got what you you got. Hopefully, this query will provide (1) a smaller lock profile and (2) a much smaller IO profile.
|||Dave
Jawahar:
One thing that I failed to point out is that my test was based on a relatively low cardinality of the '0' and '1' processing codes compared to all other processing codes. I used a 1000000 row test table with 8000 rows in the 1 process state and 800 rows in the 0 process state because it looks to me like we are talking about a "new record" process.
|||Dave
Dave
Thanks for your new suggestion on the Selection query - sorry for the late reply
I am using SQL Sever 2000
I did run the trace DBCC Trace 1204 and 3605 and found that the two SP I have listed are the ones that are involved in the Deadlock. The Select SP being the victim each time. Currently I only have an index on the RequestID column, but adding the ClientID and Processing code is a good Idea.
Out table at present has 600, 000 records. 99.33 % of the records have already been processed and have a Processing code of = 2 and we never touch those records. At any given time we should not have more than 15 to 20 records of the Processing code = 0 and 15 to 20 records Processing code = 1.
would the DBCC trace be helpful to you?
Thanks again for your suggestions I will try yor revised query. Another process that I might add is to archive Rows that have already been processd to an archive table to help reduce the size of the request table.
-jawahar
Monday, February 20, 2012
No Transaction Log Backup after installing SP1
after installing SP1 for SQL Server 2005 the sql agent cant execute the
existing management job to backup the transaction log. even if the job is
created new by deleting it in the maintanance plans and recreate it the sql
agent job can not be executed (nor manually or scheduled) the job is always
interrupted in step 2 'Execute Job' with the error "The package execution
failed. The step failed."
Has anyone else an idea to resolve this problem or should i uninstall sp1
(=reinstall sql)
ThanksThe question is WHY is the step failing. There should be extended error
messages in the log files that are generated for the job execution. What
are those messages saying?
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.
"Sorcerer" <Sorcerer@.discussions.microsoft.com> wrote in message
news:52149920-7656-4419-A9C2-CA4A641EF232@.microsoft.com...
> Hello,
> after installing SP1 for SQL Server 2005 the sql agent cant execute the
> existing management job to backup the transaction log. even if the job is
> created new by deleting it in the maintanance plans and recreate it the
> sql
> agent job can not be executed (nor manually or scheduled) the job is
> always
> interrupted in step 2 'Execute Job' with the error "The package execution
> failed. The step failed."
> Has anyone else an idea to resolve this problem or should i uninstall sp1
> (=reinstall sql)
> Thanks
>|||Hello,
this is what is written to the log:
Date,Source,Severity,Step ID,Server,Job Name,Step
Name,Notifications,Message,Duration,Sql Severity,Sql Message ID,Operator
Emailed,Operator Net sent,Operator Paged,Retries Attempted
04/21/2006 08:20:00,TransactionLog
Sicherung,Error,0,RMCNAVI1\INSTANZ1,Tran
sactionLog Sicherung,(Job
outcome),,The job failed. The Job was invoked by Schedule 9 (20). The last
step to run was step 1 (Subplan).,00:00:11,0,0,,,,0
04/21/2006 08:20:00,TransactionLog
Sicherung,Error,1,RMCNAVI1\INSTANZ1,Tran
sactionLog
Sicherung,Subplan,,Executed as user: RMC-DE\cluster. The package execution
failed. The step failed.,00:00:11,0,0,,,,0
To be more specific to the problem:
the sp1 was installed on a cluster system (windows 2003 x64 R2 and sql 2005
x64) with three instances (two clustered and one local). after installing th
e
sp1 the agent job could not be executed any longer. on a test system (not
clustered, only one instance) the sp1 was installed and there is no problem
with the agent jobs...|||my fault: forgot to make an initial full backup of the database.
sorry for that.
"Sorcerer" wrote:
> Hello,
> after installing SP1 for SQL Server 2005 the sql agent cant execute the
> existing management job to backup the transaction log. even if the job is
> created new by deleting it in the maintanance plans and recreate it the sq
l
> agent job can not be executed (nor manually or scheduled) the job is alway
s
> interrupted in step 2 'Execute Job' with the error "The package execution
> failed. The step failed."
> Has anyone else an idea to resolve this problem or should i uninstall sp1
> (=reinstall sql)
> Thanks
>
No Transaction Log Backup after installing SP1
after installing SP1 for SQL Server 2005 the sql agent cant execute the
existing management job to backup the transaction log. even if the job is
created new by deleting it in the maintanance plans and recreate it the sql
agent job can not be executed (nor manually or scheduled) the job is always
interrupted in step 2 'Execute Job' with the error "The package execution
failed. The step failed."
Has anyone else an idea to resolve this problem or should i uninstall sp1
(=reinstall sql)
ThanksThe question is WHY is the step failing. There should be extended error
messages in the log files that are generated for the job execution. What
are those messages saying?
--
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.
"Sorcerer" <Sorcerer@.discussions.microsoft.com> wrote in message
news:52149920-7656-4419-A9C2-CA4A641EF232@.microsoft.com...
> Hello,
> after installing SP1 for SQL Server 2005 the sql agent cant execute the
> existing management job to backup the transaction log. even if the job is
> created new by deleting it in the maintanance plans and recreate it the
> sql
> agent job can not be executed (nor manually or scheduled) the job is
> always
> interrupted in step 2 'Execute Job' with the error "The package execution
> failed. The step failed."
> Has anyone else an idea to resolve this problem or should i uninstall sp1
> (=reinstall sql)
> Thanks
>|||Hello,
this is what is written to the log:
Date,Source,Severity,Step ID,Server,Job Name,Step
Name,Notifications,Message,Duration,Sql Severity,Sql Message ID,Operator
Emailed,Operator Net sent,Operator Paged,Retries Attempted
04/21/2006 08:20:00,TransactionLog
Sicherung,Error,0,RMCNAVI1\INSTANZ1,TransactionLog Sicherung,(Job
outcome),,The job failed. The Job was invoked by Schedule 9 (20). The last
step to run was step 1 (Subplan).,00:00:11,0,0,,,,0
04/21/2006 08:20:00,TransactionLog
Sicherung,Error,1,RMCNAVI1\INSTANZ1,TransactionLog
Sicherung,Subplan,,Executed as user: RMC-DE\cluster. The package execution
failed. The step failed.,00:00:11,0,0,,,,0
To be more specific to the problem:
the sp1 was installed on a cluster system (windows 2003 x64 R2 and sql 2005
x64) with three instances (two clustered and one local). after installing the
sp1 the agent job could not be executed any longer. on a test system (not
clustered, only one instance) the sp1 was installed and there is no problem
with the agent jobs...|||my fault: forgot to make an initial full backup of the database.
sorry for that.
"Sorcerer" wrote:
> Hello,
> after installing SP1 for SQL Server 2005 the sql agent cant execute the
> existing management job to backup the transaction log. even if the job is
> created new by deleting it in the maintanance plans and recreate it the sql
> agent job can not be executed (nor manually or scheduled) the job is always
> interrupted in step 2 'Execute Job' with the error "The package execution
> failed. The step failed."
> Has anyone else an idea to resolve this problem or should i uninstall sp1
> (=reinstall sql)
> Thanks
>