Skip to main content

[SQL] How to determine SQL Server database transaction log usage

 To run this command issue the following in a query window:

DBCC SQLPERF(logspace)

This is sample output


From here we can see the size of the transaction logs as well as how much space is being used.  The current log space used will tell you how much of the transaction log is being used.  If this percentage is high and the size of the log is quite big it is probably due to one of the items listed above. 

Getting information about SQL Server virtual logs using DBCC LOGINFO

The next command to look at is DBCC LOGINFO. This will give you information about your virtual logs inside your transaction log.  The primary thing to look at here is the Status column.  Since this file is written sequentially and then looped back to the beginning, you want to take a look at where the value of "2" is in the output.  This will tell you what portions of the log are in use and which are not in use Status = 0.  Another thing to keep an eye on is the FSeqNo column. This is the virtual log sequence number and the latest is the last log.  If you keep running this command as you are issuing transactions you will see these numbers keep changing.

To run this command issue the following in a query window:

DBCC LOGINFO

This is sample output:


If we now run a transaction log backup such as the following:

BACKUP LOG DBUtil TO DISK = 'C:\Backup\test.trn'

and then rerun the command you will see how the Status=2 has changed in the file. The last entry is still marked as in use, but the previous entries have been reset to 0.



Finding open SQL transactions using DBCC OPENTRAN

Another command to look at is DBCC OPENTRAN. This will show you if you have any open transactions in your transaction log that have not been completed or have not been committed.  These may be active transactions or transactions that for some reason never completed.  This can provide additional information as to why your transaction log is so big or why you may not be able to shrink the transaction log file.  This will show you both open transactions as well any un-replicated transactions if the database is published.

To run this command issue the following in a query window:

DBCC OPENTRAN

This is a sample output:



Now that you have an idea of how much of your transaction log is being used and what is being used you can start to make some decisions on how large the transaction log should be.  One thing you should try to do is find that optimum size in order to eliminate having to shrink and grow the transaction log on a constant basis.  As with all database and server activity, it is best to minimize the overhead as much as you can and this is one of those areas that you can somewhat manage by creating and maintaining the optimum transaction log size.

how big should my log file be?

For your log file is twice the size of the largest index in your database or 25% of the database size. Whichever is larger.

Why?

If the largest object in your database is larger than 25% of your database, you are likely running some type of maintenance. Index rebuilds require the size of the object being rebuilt in log space. Usually rule of thumb twice that space, in case you’re doing anything else while you’re doing that maintenance, like reports, dragging data to and purging data, whatever. If you’re only ever reorganizing the largest object, you may not need all that space.

Select your Database and run the below query to see what is your recommended log size. 


And the below method is used when the log is not shrunk. 


DBCC SQLPERF(logspace) --check log size


--Shrink Log for Restored Database

ALTER DATABASE "put your DB name" SET RECOVERY SIMPLE

USE "put your DB name"

DBCC SHRINKFILE ("put your log name", "put the size you want")  

ALTER DATABASE "put your DB name" SET RECOVERY FULL


DBCC SQLPERF(logspace)  --check log size after shrink



Comments

Popular posts from this blog

[Cisco] command and CDR log backup by FTP (gw-accounting file)

Below command has been tested with ISR4331 devices.  1. check Cisco device file size command :  a. show current folder dir flash:  b. show all folder and files dir flash 2. check file only start with "cdr." dir flash:cdr.* 3. Remove file (Add option [ /recursive /force]  when you delete file is not recovering free space) delete /recursive /force  flash:cdr.* 4. check subfolder file dir flash:\tracelogs 5. example for log back to ftp https://www.cisco.com/c/en/us/td/docs/ios/voice/cdr/developer/manual/cdrdev/cdrcsv.html#marker-1163166 enable conf t gw-accounting file primary ftp 192.168.1.51/cisco/cdr username cisco password xxxxx secondary sftp 192.168.1.52/cisco/cdr username cisco password xxxxx acct-template callhistory-detail maximum buffer-size  30 maximum retry-count 3 (note : if these setting is not working. check these area, FTP password can not be used @ and some of special characters for this command. Second, ftp location is case sensitive. Please...

[Cisco Network] connect by serial and usb & setup IP

Accessing the CLI via PuTTY with a Console Connection Step 1. Connect the switch to the computer using a standard 9-pin serial cable. The Cisco DB9 to RJ45 Console Cable also supports console connections, but only if the switch has an RJ45 Console port. An RJ45 Console port resembles an Ethernet port and is labeled CONSOLE on the back of the switch. Newer laptops don’t have Serial ports on them, so in this case you have to use a USB to Serial adapter. When plugging that into a computer it assigns a COM port number to it that is not COM1. If this is the case for you, you need to know where to look to find the correct COM port number when setting up the connection with PuTTY. Right-click on the Windows logo/Start menu and click on Device Manager to open it. In the Device Manager, you would look to see what COM port is given to the USB adapter. In this case you would need to use COM4 for the Serial line to make the connection.     Step 2. Open the PuTTY application. The  PuT...

vmware esxi 백업

  'ESXi'의 버추얼 머신(Virtual Machine)을 옮기려면 백업파일을 받아야 합니다. 'ESXi'에서 버추얼 머신 백업(backup)하면 다운로드할 수 있습니다. 이 방식으로 버추얼 머신을 백업하고 복원하는 방법을 알아봅시다.  실행 중인 버추얼 머신을 정지시키고 진행해야 합니다.   1-1. 웹에서 다운받기 백업받으려는 가상 시스템을 클릭하고 작업 > 내보내기 를 선택합니다. 2-1. 웹에서 복원하기 가상 시스템 > VM 생성/등록 을 선택하고 '생성 유형'을 'OVF 또는 OVA 파일에서 가상 시스템 배포'를 선택합니다. 위에서 다운받은 백업 파일을 넣어줍니다. 이때 넣어줄 파일은 '*.ovf'와 '*.vmdk'입니다. 하드용량에따라 시간이 걸립니다.  5M-10M 속도로 상당히 느립니다.