Transaction Log file is growing large in SQL Server

Transaction Log file is growing large in SQL Server

Analyze the log size of the databases present in SQL Server:

dbcc sqlperf (logspace );

Output:

Database Name   Log Size(MB) Log space Used(%)  Status
--------------  -----------  -----------------  -------
AdventureWorks  813.245      71.3443535         0
TEST              0.5        79.1235678         0


It show the log size of all databases Present in SQL Server instance.

Logspace is growing large because of recovery mode defines.
Recover model is simple then once checkpoint is occurred then it truncate the logs. No point in time recovery at simple recovery.
Recover model is bulk-logged then at checkpoint occurred, its not truncated the transaction logging.
Recover model is full then every transaction is full logged and transaction is not truncated
Note:Another way is to take backup of transaction log otherwise it becomes larger or larger in size

Check the Status of Log transaction status

select name , log_reuse_wait_desc from sys.databases;
Output:

NAME             LOG_RESUE_WAIT_DESC
-------------    --------------------
master		 NOTHING
AdventureWorks   LOG_BACKUP
TEST             ACTIVE_TRANSACTION

LOG BACKUP values show need to be backup the transactional log for adventureworks database otherwise its continue grow until you take a transaction backup.

You can take the transaction log backup with right click on database in SQL Server Management Studio.

In TEST database having active transaction it finished after checkpoint issue.

Manually fire the checkpoint on ADVENTUREWORKS & TEST database

use ADVENTUREWORKS
Checkpoint

use TEST
Checkpoint

Check the status of log transaction again:

select name , log_reuse_wait_desc from sys.databases;

name             log_Resue_wait_desc
-------------    --------------------
master           NOTHING
AdventureWorks   NOTHING
TEST             NOTHING

Check again the AdventureWorks transaction Log space

dbcc sqlperf (logspace );

Output:

Database Name   Log Size(MB) Log space Used(%)  Status
--------------  -----------  -----------------  -------
AdventureWorks  813.245      2.443535         0
TEST              0.5        79.1235678         0

Following are steps to shrink the Transaction Log file in File System of Operating system:

alter database adventureworks set recovery simple;
Go
-- Shrink log file to 1 MB
DBCC shrinkfile (adventureworks_log,1);
Go
alter database adventureworks set recovery FULL;
GO

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s