Answered by:
SQL Log File Growth rate

Question
-
I have two huge databases,
there is one stored procedure when it runs in A environment there is no problem
when it runs in B environment log file grows like 40 Gig per HOur.
how can i tackle this issue.
REgards
k
Monday, December 2, 2013 3:27 PM
Answers
-
Hi Humm
if both db is in full recovery and environment with issue doesn't have full recovery than you must check your transactions while you call your sp. You can use below query to check transaction which is filling your t-log file most.
Transaction Filling Log Space in Sql server
/************Transaction causing logspace filled most in database**************/ SELECT tst.[session_id], s.[login_name] AS [Login Name], DB_NAME (tdt.database_id) AS [Database], tdt.[database_transaction_begin_time] AS [Begin Time], tdt.[database_transaction_log_record_count] AS [Log Records], tdt.[database_transaction_log_bytes_used] AS [Log Bytes Used], tdt.[database_transaction_log_bytes_reserved] AS [Log Bytes Rsvd], SUBSTRING(st.text, (r.statement_start_offset/2)+1, ((CASE r.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE r.statement_end_offset END - r.statement_start_offset)/2) + 1) AS statement_text, st.[text] AS [Last T-SQL Text], qp.[query_plan] AS [Last Plan] FROM sys.dm_tran_database_transactions tdt JOIN sys.dm_tran_session_transactions tst ON tst.[transaction_id] = tdt.[transaction_id] JOIN sys.[dm_exec_sessions] s ON s.[session_id] = tst.[session_id] JOIN sys.dm_exec_connections c ON c.[session_id] = tst.[session_id] LEFT OUTER JOIN sys.dm_exec_requests r ON r.[session_id] = tst.[session_id] CROSS APPLY sys.dm_exec_sql_text (c.[most_recent_sql_handle]) AS st OUTER APPLY sys.dm_exec_query_plan (r.[plan_handle]) AS qp where DB_NAME (tdt.database_id) = 'tempdb'ORDER BY [Log Bytes Used] DESC; /***************************************************************************************************/ ------> Please modify database name
Thanks
Saurabh Sinha
http://saurabhsinhainblogs.blogspot.in/
Please click the Mark as answer button and vote as helpful if this reply solves your problem
- Marked as answer by '''HuuM''' Monday, December 9, 2013 8:00 PM
- Edited by Saurabh Sinha DBA Tuesday, December 9, 2014 6:40 PM
Friday, December 6, 2013 11:25 PM
All replies
-
Start by comparing the execution plans in the two environments.
David
David http://blogs.msdn.com/b/dbrowne/
Monday, December 2, 2013 3:39 PM -
-
Also, check the when was last index rebuild and stats updated. Issue might be due to fragmentation
Please click the Mark as answer button and vote as helpful if this reply solves your problem
Tuesday, December 3, 2013 1:30 AM -
I have two huge databases,
there is one stored procedure when it runs in A environment there is no problem
when it runs in B environment log file grows like 40 Gig per HOur.
how can i tackle this issue.
REgards
k
Check recovery model of both databases.I am sure one of them might be having simple or bulk logged recovery model.Now what is running in both databases can you provide information about the same.You just post question and vanish if you really require help please reply with full issue.Every body asked about recovery model and query.
Neha,
How can fragmentation directly cause log file to grow it will cause slowness not log file to grow out of control
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
- Proposed as answer by Fanny Liu Wednesday, December 4, 2013 10:58 AM
Tuesday, December 3, 2013 5:23 AM -
Hi HuuM
Behaviour of t-log is only controlled by recovery model. I am sure both db have differen recovery models.
Please also check what your procedures are doing exactly , theare is also a possibility that in both environment ammout of data processed by sp is different causing long running transaction in on of environment.
Neha : fragmentation can affect time consumed to get output or huge i/o activity, but ammout of t-log used is propotional to ammount of dml operations.
Thanks Saurabh Sinha
http://saurabhsinhainblogs.blogspot.in/
Please click the Mark as answer button and vote as helpful if this reply solves your problem
- Edited by Saurabh Sinha DBA Tuesday, December 3, 2013 8:29 AM
- Proposed as answer by Fanny Liu Wednesday, December 4, 2013 10:58 AM
Tuesday, December 3, 2013 8:29 AM -
Hello,
Log truncation occurs automatically after a checkpoint under the simple recovery model or log backup under the full recovery model or bulk-logged recovery model. You can discover what, if anything, is preventing log truncation by using the log_reuse_wait and log_reuse_wait_desc columns of the sys.databases catalog view.
Regards,
Fanny LiuFanny Liu
TechNet Community Support- Proposed as answer by Vedran Kesegic Saturday, December 7, 2013 1:21 AM
Wednesday, December 4, 2013 11:04 AM -
Both databases have Full recovery Model
k
Friday, December 6, 2013 1:48 AM -
Sorry Shanky,
i got busy in some othe stuff, so as mentioned in both databases recovery model is FULL,
the stored procedure does huge insert job in all over the database,
k
Friday, December 6, 2013 2:09 AM -
Sorry Shanky,
i got busy in some othe stuff, so as mentioned in both databases recovery model is FULL,
the stored procedure does huge insert job in all over the database,
k
Ok does any of environment has mirroring configured for database.This can happen in sync mirroring where if transaction move slowly for commit on mirror primary has to wait and this causes log growth on primary.
Does my any chance rows involved in delete operation for both DB's are differnent may be huge difference
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
Friday, December 6, 2013 7:15 AM -
yes one of the environments that has mirroring does not have the issue
but for the second one mirroring is setup recently.
REgards
k
Friday, December 6, 2013 4:58 PM -
Hi Humm
if both db is in full recovery and environment with issue doesn't have full recovery than you must check your transactions while you call your sp. You can use below query to check transaction which is filling your t-log file most.
Transaction Filling Log Space in Sql server
/************Transaction causing logspace filled most in database**************/ SELECT tst.[session_id], s.[login_name] AS [Login Name], DB_NAME (tdt.database_id) AS [Database], tdt.[database_transaction_begin_time] AS [Begin Time], tdt.[database_transaction_log_record_count] AS [Log Records], tdt.[database_transaction_log_bytes_used] AS [Log Bytes Used], tdt.[database_transaction_log_bytes_reserved] AS [Log Bytes Rsvd], SUBSTRING(st.text, (r.statement_start_offset/2)+1, ((CASE r.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE r.statement_end_offset END - r.statement_start_offset)/2) + 1) AS statement_text, st.[text] AS [Last T-SQL Text], qp.[query_plan] AS [Last Plan] FROM sys.dm_tran_database_transactions tdt JOIN sys.dm_tran_session_transactions tst ON tst.[transaction_id] = tdt.[transaction_id] JOIN sys.[dm_exec_sessions] s ON s.[session_id] = tst.[session_id] JOIN sys.dm_exec_connections c ON c.[session_id] = tst.[session_id] LEFT OUTER JOIN sys.dm_exec_requests r ON r.[session_id] = tst.[session_id] CROSS APPLY sys.dm_exec_sql_text (c.[most_recent_sql_handle]) AS st OUTER APPLY sys.dm_exec_query_plan (r.[plan_handle]) AS qp where DB_NAME (tdt.database_id) = 'tempdb'ORDER BY [Log Bytes Used] DESC; /***************************************************************************************************/ ------> Please modify database name
Thanks
Saurabh Sinha
http://saurabhsinhainblogs.blogspot.in/
Please click the Mark as answer button and vote as helpful if this reply solves your problem
- Marked as answer by '''HuuM''' Monday, December 9, 2013 8:00 PM
- Edited by Saurabh Sinha DBA Tuesday, December 9, 2014 6:40 PM
Friday, December 6, 2013 11:25 PM -
Hi Humm,
Seems that the log file growth rate of the database in B environment is set in %. Set the log file growth rate of the database in B environment to a specific value like 50MB or 100MB.
For best storage utilization by database in B environment I would suggest you to do the following:
- Stop mirroring on B environment.
- Set the recovery model of the B environment database to simple recovery model ans shrink the log files.
- Set the recovery model of the B environment database back to full recovery model and change the log file growth rate to 50MB or 100MB.
- Set up mirroring again on the B environment database.
- To control the log file growth you can set up the below backup plan : a) Weekly full backup during the weekend on Sunday. b) Daily once differential backup from Monday to Saturday. c) Transaction log backup at an interval of every 1 hr or 2 hrs depending upon the DB criticality.
Thanks and Regards Alankar Chakravorty MCITP Database Administrator SQL Server 2008 MCITP Database Administrator SQL Server 2005
Monday, December 9, 2013 6:16 AM