Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Transaction Log Growing Despite Simple Recovery Expand / Collapse
Author
Message
Posted Monday, April 19, 2010 1:40 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:31 AM
Points: 419, Visits: 725
The easiest way seems to be looping based on an identity key. I've broken up the transaction into groups of 50,000 rows, and a CHECKPOINT is issued manually (just to be sure) after each load. The first part of the transaction seems to take up the most log space, at slightly over 1G. The remaining data groups seem to take only a few hundred megs of log space. It's certainly a great deal better than 9G. Thank you all for your help.

An interesting thing I've learned from this - the dramatic effect of file resizes on query perforance. Typically, the stored procedure runs in 6-9 minutes (when there is enough log space to accomidate it). When I was forcing it to resize the log space (1G at a time), it took 16-20 minutes, and that's just 8 resizes. Imagine if my resize were set to 10%!! I could be waiting an hour for that to complete. File resizes truly do kill a query. You will notice the difference.
Post #906314
Posted Monday, April 19, 2010 1:46 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:00 PM
Points: 22,992, Visits: 31,470
Here is a guess at why you see a larger growth from stage to production than from source to stage: indexes on the production table(s). Do you currently drop and recreate the indexes or are they in place during the transfer?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #906317
Posted Monday, April 19, 2010 1:51 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:31 AM
Points: 419, Visits: 725
Lynn Pettis (4/19/2010)
Here is a guess at why you see a larger growth from stage to production than from source to stage: indexes on the production table(s). Do you currently drop and recreate the indexes or are they in place during the transfer?


Ah ha! It all make sense now. I keep the indexes online. I had considered drop/recreate, but up until now could see no specific reason to do so. The process itself didn't take that long, so I didn't think I'd really get much of a performance boost from dropping/recreating indexes. There are about twenty indexes on the fact table. Most are INTs, but still the index space for the table is nearly as much as the data space.

On the other hand, there are virtually no indexes on the intermediate table. Only a identity key added today.
Post #906320
Posted Monday, April 19, 2010 1:57 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:00 PM
Points: 22,992, Visits: 31,470
I wrote a set of procedures for a previous employer that dropped and recreated the indexes and foreign key references on specified tables that were used before and after the load process into their data warehouse. Since it dynamically captured the index information when run there was no need to maintain drop and create scripts so if a new index was created on a table, it was automagically captured during the next load.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #906325
Posted Monday, April 19, 2010 2:02 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:31 AM
Points: 419, Visits: 725
Lynn Pettis (4/19/2010)
I wrote a set of procedures for a previous employer that dropped and recreated the indexes and foreign key references on specified tables that were used before and after the load process into their data warehouse. Since it dynamically captured the index information when run there was no need to maintain drop and create scripts so if a new index was created on a table, it was automagically captured during the next load.


I'll try it out and see what the results are. This seems like it might actually give me a performance boost, whereas breaking up the query is almost certainly a performance hit.
Post #906328
Posted Tuesday, April 20, 2010 7:40 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:31 AM
Points: 419, Visits: 725
I had trouble removing the clustered index on InvoicedDate (it was taking a long time), but I was finally able to do it. I tested the stored procedure with all indexes removed except InvoicedDate, and the log file still jumped to 7G. Once I removed the InvoicedDate index, the log file only reached slightly over 2G. It is interesting to see how much of an impact the clustered (non-unique) index had on the transaction log.

I still have a identity key that I was not able to remove without removing the field itself. The identity key is required as the data provided no guaranteed unique keys. The primary key is non-clustered because it's order means nothing. I instead opted to cluster on the InvoicedDate field. The primary key doesn't appear to have a significant impact on the transaction log. Slightly over 2G is consistant with the other steps, which use slightly over 1G of log space. The extra log space can easily be accounted for by the increased number of rows, as well as the increase row size (the additional of several fields via lookup).

My preference is to get it under 2G, with enough room to spare that I don't have to worry about it growing. So, it looks like I may still have to break the data into smaller chunks. So now it becomes a matter of which provides the best performance. From what I'm seeing, recreating indexes seems expensive. However, building the data in chunks took over twice as long as building the data all at once. It looks like the difference in performance will be pretty nominal. Since building the data in chunks is simpler overall than some hybrid solution, looks like seperating the data is the way to go.

Thanks again for all your help!
Post #906839
Posted Tuesday, April 20, 2010 9:32 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 3:31 PM
Points: 33,051, Visits: 15,159
Thanks for the update, and I am surprised at the difference in the log with the clustered index removal. I would tend to agree that it doesn't necessarily make sense.

I'm wondering in terms of your timing and chunking, could you insert the data differently? Maybe do something to avoid page splitting?

Likely this is a challenging problem, and I'd actually encourage you to start another thread and post some code, see what suggestions people might have for sections to try and change the way it's being load in the proc.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #906982
Posted Tuesday, April 20, 2010 10:12 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 15, 2014 8:31 AM
Points: 419, Visits: 725
Well, ultimately breaking it into blocks gives me complete control over the transaction log size. In this specific case, disk space is more important than performance. I can trade performance for disk space by reducing the block size. Also, the fixed block size means that the transaction log will not increase in size as a result of more source data. This solution seems to be acceptable.

I ended up with this:
DECLARE @i INT, @max INT, @blocksize INT
SET @i = 0
SET @blocksize = 50000
SELECT @max = MAX(id) FROM temp.OrderPrep

WHILE @i <= @max
BEGIN

IF @debug = 1 SELECT @i AS , @max AS [MAX]

INSERT INTO fact.CustomerOrder
SELECT
-- SELECT List removed for brevity and privacy
FROM
temp.OrderPrep OP
LEFT JOIN dim.Customer C on C.CustomerID = OP.CustomerID
OUTER APPLY Lookup.dbo.fn_SalesRegion(
CASE
WHEN C.CustomerType = 'OEM-N' then 'NAT'
WHEN C.Channel = 'EXPORT' then 'EXP'
ELSE ShipToState
END, ShipToCountry) SR
OUTER APPLY Lookup.dbo.fn_IRRegion(ShipToState, ShipToZipcode, ShipToCountry) IRR
WHERE OP.[id] <= @i AND (OP.[id] > @i - @blocksize)

IF @debug = 1 PRINT 'Checkpoint ' + CAST(@i AS VARCHAR(50))

CHECKPOINT

SET @i = @i + @blocksize

END

Which really isn't much more code than the original script. It's not the most elegant solution in the world, but it works. Frankly, I've already spent too much time on this. File bloat, however, can become serious, so it was imperative that I spend however much time was needed to solve it the problem.

Besides SSIS, I can't think of any other ways of moving the data. I've avoided SSIS for a couple of reasons. The first is because I am unsure about the OUTER APPLY capabilities via the UDFs. The other is because this code [i]works
, and I want to minimize the possibility of introducing new bugs. That second reason applies to any other method of moving data.
Post #907025
Posted Sunday, February 20, 2011 11:22 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 4, 2014 7:44 AM
Points: 115, Visits: 646
I agree doing this in a loop or in chunks will give complete control. I too have experienced same problem.

I have a question here : bcp will log or NOT, while inserting data to a table?
Post #1066928
Posted Monday, February 21, 2011 12:29 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 42,434, Visits: 35,488
There is no such thing as an unlogged operation. Every data modification will log.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1066944
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse