SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Seeking advice on database maintenance and transation log


Seeking advice on database maintenance and transation log

Author
Message
cheetahkatsu
cheetahkatsu
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 20
We have database maintenance procedures which, in addition to performing backups, remove records older than a user-specified time limit in order to lower the size of the database files on disk. I have a number of questions regarding improving the operation of the "pruning" tasks in regard to the transaction log. The database recovery model is currently set to Simple.

First, there is a requirement to allow the pruning/delete operations while the database is fully user-accessible. As a safety measure, I wrap these operations in a transaction. Is this the best approach? Should I be adamant that the database be placed in single user mode or taken offline?

Second, I find that the transaction log grows from about 3K to 60GB after the pruning is performed on a 4 GB database. I've tried batching the deletes into groups of around 10,000 records, and this improved matters, but the transaction log still ended up at around 40GB.

Here is a general outline of how the deletions proceed:
1. Delete from sub-table where timestamps in master table records are older than X.
(This is due to integrity constraints.)
2. Delete from master table where record timestamps are older than X.
3. Delete from other sub-tables where foreign key in master table is no longer found.
4. Delete from further sub-tables where timestamps are older than X.

I am using sub or nested queries in steps 1 and 3 (delete from sub-table where record ID in select... from master), (delete from sub-table where not in select ... from master).
Is there a more transaction-log-friendly way to go about this?

If the transaction log growth after deletion is expected behavior, I have noticed that I can back up the database after pruning and then shrink the file with DBCC SHRINKFILE.
Further questions:
1. The prune/backup/shrinkfile approach just mentioned above would necessitate locking down the database (single user mode or offline) to prevent the loss of user transactions during this set of operations, correct?
2. Would it be better to employ a Full Recovery model and start backing up/shrinking the transaction log instead?
Thank you for any advice.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95943 Visits: 38977
One, you really don't want to shrink your database on a regular basis, it will result in both index and file fragmentation will affect performance. regarding the transaction log, may I suggest reading this article:

http://www.sqlservercentral.com/articles/Administration/64582/

Cool
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)
SQL Show
SQL Show
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1529 Visits: 1078
Shrinking Log file is not recommended until you run out of drive space. If your disk can hold 60GB log file, you can leave as of now.

Also when the pruning activity happens? Off -peak time?
Kenneth Fisher
Kenneth Fisher
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6397 Visits: 2060
You might consider looking into partitioning. Partition your table so that the rows you want to get rid of are in their own partition then use SWITCH to put them into a whole different table, then drop that table. I've read about doing this several times although right now I can't think where. You should be able to find it easily enough. You might consider looking at Kimberly Tripps blog, she does a lot on partitioning.

The last half of this article seems to do what you are looking for.
http://www.sqlskills.com/BLOGS/KIMBERLY/post/Clarifying-LEFT-and-RIGHT-in-the-defintion-of-a-PARTITION-FUNCTION-in-SQL-Server-2005.aspx

Kenneth FisherI strive to live in a world where a chicken can cross the road without being questioned about its motives.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/Link to my Blog Post --> www.SQLStudies.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search