SP_Who
zjistit Session ID daného spojeníKILL <session id>
spojení ukončitSELECT DB_NAME(dbid) as DBName, COUNT(dbid) as NumberOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame
So here is the quick dirty way to change the initial size of the transaction log file:
It depends on current recovery model:
Just shrink the file! If the file doesn't shrink to the size you want, then try again, and again. If it still doesn't shrink to the size you want, then read this (the „Shrinking of transaction log file“ section).
If you are in full recovery model, and this is where you want to be, then you have to make a decision:
Is it OK to break the transaction log backup chain?
By this we mean the chain of log backups you may have. If you don't have any prior log backups (perhaps not even a prior database backup), then it is OK to break the chain of log backups. If you do have earlier log backups and want to be able to restore from them up to any point in time then it isn't OK to break the chain of log backups.
Commands to do the actual shrink: Simple recovery model
USE dbname CHECKPOINT --First param below is fileno for log file, often 2. Check with SELECT * FROM sys.database_files --Second is desired size, in MB. DBCC SHRINKFILE(2, 500) DBCC SQLPERF(LOGSPACE) --Optional DBCC LOGINFO --Optional Now repeate above commands as many times as needed!
Full or bulk_logged recovery model
USE dbname BACKUP LOG dbname TO DISK = 'C:\x\dbname.trn' --First param below is fileno for log file, often 2. Check with sys.database_files --Second is desired size, in MB. DBCC SHRINKFILE(2, 500) DBCC SQLPERF(LOGSPACE) --Optional DBCC LOGINFO --Optional
Now repeate above commands as many times as needed! What you end up doing is empty the log (CHECKPOINT or BACKUP LOG) and DBCC SHRINKFILE several times, so that SQL Server can move the head of the log to beginning of the file and also so the end of the file becomes unused. Investigate the layout of the log file using DBCC LOGINFO in between.
(http://www.karaszi.com/SQLServer/info_large_transaction_log_file.asp).