Is your Transaction Log full ? And are you not able to execute transactions because of error saying "Transaction Log is full" ?
Problem Explanation:
In
SQL Server, we have three recovery models.
Simple
Recovery Model
Full
Recovery Model
Bulk-Logged
Recovery Model.
An
SQL Server database has two files by default namely,
Data
file “.mdf”
Log
file “.ldf”
This
database should be managed under one of the earlier mentioned
recovery models.
NOTE:
Taking Transaction Log Backup is the only way to truncate(empty) the
log file.
In
Simple Recovery model,
SQL
Server automatically truncates the log file in regular intervals.
That
is the reason why we are not allowed to take a transaction log
backup in this mode of recovery (And there is no need to take
transaction log backup also in this mode).
So,
coming to the main point, log file will never get fulled in this
mode of recovery.
In
Full Recovery model,
Burden
of maintaining and controlling the transaction log is completely
left on the DBA.
So,
If we dont take regular log backups of the database, then log file
will get filled up until the threshold (Refer the NOTE mentioned
earlier).
Listed
below are some other regular scenarios when transaction log file of
SQL Server database grows:
If
there are no scheduled log backups or log backups are not working.
If
there are active transactions in the log file
If
there are long running queries
In
database mirroring if mirror server fails
In
replication if distributor fails
If
there is no disk space to grow the Transaction Log file
If
bulk data was imported without dividing into multiple batches or
transactions.
Problem Solution:
When
the transaction log becomes full, SQL Server Database Engine issues a
9002 error.
Follow
the below mentioned steps to take a transaction log backup.
After
connecting to the appropriate instance of the SQL Server Database
Engine, in Object Explorer, click the server name to expand the
server tree.
Expand
Databases, and select a desired database.
Right-click
the database, point to Tasks, and then click Back Up. The Back Up
Database dialog box appears.
In
the Database list box, verify the database name. You can
optionally select a different database from the list.
Verify
that the recovery model is either FULL or BULK_LOGGED.
In
the Backup type list box, select Transaction Log.
Optionally,
you can select Copy Only Backup to create a copy-only backup.
Leave this here.
Either
accept the default backup set name suggested in the Name text box,
or enter a different name for the backup set.
Optionally,
in the Description text box, enter a description of the backup
set.
Choose
the type of backup destination by clicking Disk or Tape. To
select the paths of up to 64 disk or tape drives containing a single
media set, click Add. The selected paths are displayed in the
Backup to list box.
To
remove a backup destination, select it and click Remove. To view
the contents of a backup destination, select it and click Contents.
To
view or select the advanced options, click Options in the Select
a page pane.
Select
an Overwrite Media option, by clicking one of the following:
In
the Reliability section, optionally, check:
Verify
backup when finished.
Perform
checksum before writing to media, and, optionally, Continue on
checksum error.
In
the Transaction log section:
For
routine log backups, keep the default selection, Truncate the
transaction log by removing inactive entries.
To
back up the tail of the log (that is, the active log), check Back
up the tail of the log, and leave database in the restoring state.
If
you are backing up to a tape drive (as specified in the Destination
section of the General page), the Unload the tape after backup
option is active. Clicking this option activates the Rewind the
tape before unloading option.
SQL
Server 2008 Enterprise and later supports backup compression. By
default, whether a backup is compressed depends on the value of the
backup-compression default server configuration option. However,
regardless of the current server-level default, you can compress a
backup by checking Compress backup, and you can prevent compression
by checking Do not compress backup.
After
taking transaction log backups, in-active log will be truncated and
empty space is created for the upcoming transactions. We can come
out of the problem.
In
order to prevent the occurrence of this problem in future, log
backups should be scheduled at regular intervals according to the
server traffic when we have opted for the Full Recovery mode.
Note: The
process detailed above will only empty the log file. It will not
reduce the log file size.The side reduction
of database files is achieved by shrinking them. Shrinking is not a
suggested operation. It is always good to maintain adequate log size by taking regular backups.