Monday, April 17, 2017

Shrinking a Log File with Database in Always ON Availability.



                   Once we had a situation in our production server that the database which is in Always ON Availability group has been grown to the maximum size.

 Many of them say that we can't shrink the log file as the database is in Always ON and we should take the downtime to perform the operation. But we shrink-ed the database log file to 5 GB from 180 GB.

Steps are as below:

--To Check the Number of pages allocated by the LogFile.
DBCC LOGINFO

--To check the file sixe
sp_helpdb [SQLPantry]

--To check the Log file Size
DBCC SQLPERF(LOGSPACE)

The above statement will show the logspace of all db at present situation.

--To check the Log_reuse_wait description of a log file.
select log_reuse_wait_desc,* from sys.databases

The above statement will show the status of the log whether it has to be backuped i.e., LogBackup, Nothing, Active Transaction. 

When ever there is status as Active Transaction then we have to wait till the transaction has completed and start Backup Log and shrink the log file.

--Take a log backup.
Backup log [SQLPantry] to disk='D:\Backups\OnyxDevDaily\1.trn'

The above statement will be used to backup the log first and then start the shrinking of log file.
Atleast  3 or 4 time we have to take the log backups and start the shrink operation on it.

--To shirnk the log file after taking the backup. and run back to back.
--Log File has grown to the Szie of 3008457 GB

DBCC SHRINKFILE(2,300000)
DBCC SHRINKFILE(2,200000)
DBCC SHRINKFILE(2,100000)
DBCC SHRINKFILE(2,90000)
DBCC SHRINKFILE(2,80000)
DBCC SHRINKFILE(2,70000)
DBCC SHRINKFILE(2,60000)
DBCC SHRINKFILE(2,50000)
DBCC SHRINKFILE(2,40000)
DBCC SHRINKFILE(2,30000)
DBCC SHRINKFILE(2,20000)
DBCC SHRINKFILE(2,10000)
DBCC SHRINKFILE(2,5000)

The above statements are used to shrink the log file if the log has been increase to huge size then that has to be changed according to the requirement and perform it. 



--To check the open transactions on the Database

DBCC OPENTRAN()



4 comments:

Unknown said...
This comment has been removed by the author.
julia lie said...

Join dan Rasakan Kemenangan Berlipat Ganda bersama keris99

Akurasi kemenangan sangat tinggi

situs judi online keris99 Agen Sakong Online Capsa Susun Bandar Poker Judi Domino99 BandarQ AduQ dengan akurasi kemenangan tertinggi masa kini.

Daftar sekarang juga di keris99 dan rasakan sensasi nikmatnya kemenangan Beruntun jatuh hanya untuk anda para pecinta judi online.

Kunjungi situs resmi :
Agen Sakong
Agen Sakong Online
Agen Domino99
Agen BandarQ
Agen Capsa Susun
Judi Cepat Kaya

PASTI MENANG BANYAK!!

yoona lim said...

blogwalking, kunbal ya gan, makasihh

Sini Capsa Bagi Chip Setiap Hari
Nonton Online Streaming
>>>jangan klik<<<
Jutawan Kilat
konten dewasa
Asli Cerita Dewasa
Kamar Kimochi

#agenpoker #agencapsasusun #agendomino #agenceme #agenqq #kiukiuonline

agen poker uang asli said...

ItuCapsa merupakan agen judi poker online uang asli terpercaya yang menyediakan permainan terlengkap yakni : Game poker online, domino qq / kiu kiu, capsa susun, ceme keliling, bandar ceme, dominobet, samgong dan casino war dalam 1 akun permainan
Menang terus menerus bukan hal yang mustahil disini!
Untuk Info Pendaftaran, silakan kunjungi :
bandar poker online
qiu qiu online
poker online terpercaya
daftar poker online
Pin BBM: dcd508f3 / itucapsa
WA = +855712346048
LINE : ITUCAPSA