MS SQL Server 2000 Log File Problem

Saya ada masalah nih dengan log file ms sql server 2000 saya.

Digunakan untuk ERP, walaupun belum ke semua department

Yang mengganggu adalah ukuran log file tersebut mencapai 230 GB. Hadoh, ini
sangat menguras space kami, padahal databasenya sendiri hanya 60 GB. Saya
sudah melakukan :

– Shrink

– Automatic shrink

– Dan hal ini sudah beberapa bulan kami amati, namun upayanya belum
ada hasil yang memuaskan.

Pertanyaan : bagaimana menekan space log file (.ldf) ini supaya kecil ?
mengingat : log kan hanya catatan, kami tidak membutuhkannya. Yang
dibutuhkan kan hanya database .mdf dan .ndf sumbernya.

kalo udah ilang, ini isinya :

Dealing with a large transaction log file
Part 1
Author Nigel Rivett

Transaction log principles

Whenever a data update is made entries are added to the transaction log.
It is not possible to prevent this as it is part of the way sql server maintains integrity – particularly during recovery.

The transaction log is a circular file i.e. when the end is reached any free entries at the start will be used.
This means that all being well the file will stay at a constant size as the current entry cycles round.

The system maintains the MinLSN which is a pointer to the first active log record.
Any log records before this (in the circular file) are free.
The MinLSN will be prevented from moving forward by any open transactions – i.e. the oldest open transaction entry will be >= the MinLSN.
The MinLSN is updated at checkpoint so committing a transaction will not immediately free entries and anything that holds up the checkpoint can cause problems.

If the database is in simple recovery mode all entries prior to the MinLSN will be freed at checkpoint.
If the database is in full recovery mode (and a full backup has been taken) the entries prior to the MinLSN will only be freed by a transaction log backup (not full backup).

Common cause of large transaction log file (.ldf)

Unfortunately the sql server default (except local editions) leaves the databases in full recovery mode.
This menas that if no action is taken no tr log entries will be freed and the log file will eventally fill the disk and crash the system.
The SQL Server installation process is very simple and commonly carried out by inexperienced personel. This will appear to work happily but cause problems later.
I would recommend always setting the model database to simple recovery mode to set the default for new databases.

Stopping the transaction log file (.ldf) from growing

If the log file has grown do to being in full recovery mode then set it to simple before going any further. This should immediately stop the log from growing.
Enterprise manager
Right click on the database, properties, Options, set model to simple, OK.
sp_dboption [dbname], ‘trunc. log on chkpt.’, ‘true’

Shrinking the transaction log file (.ldf)

Before this make sure there are free entries by setting the recovery model to simple or backing up the log.

Enterprise manager
Right click on the database, All tasks, Shrink database, Files, Select log file, OK.

dbcc shrinkfile ([db_log_name])
Here [db_log_name] is the logical name of the log file as found from sp_helpdb or the table sysfiles

Shrinking the log file via detach/attach

Always take a full backup before a detach.

Detach the database, delete/rename the log file, attach the database – this will create a minimum size log file.
Note that the log file must be deleted/renamed otherwise it will be re-used even though it is not mentioned in the attach.

Enterprise manager
Right click on the database, All tasks, Detach database, OK.
Delete/rename the disk log file.
Right click on databases, All tasks, Attach database, Select the .mdf file, OK, Yes (to the create new log message).

sp_detach_db [dbname]
Delete/rename the disk log file.
sp_attach_single_file_db [dbname], [filename]
where [filename] is the name of the physical data file (.mdf).


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s