Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to check log file size?

Author  Topic 

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-02-22 : 00:50:54
Hi, how to check the log file size if more than 10 Mb, then shrink it to the target size?


Thanks.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-22 : 00:54:00
With 'dbcc sqlperf(logspace)'.
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-02-22 : 00:55:09
Try

SP_HELPFILE
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-02-22 : 02:47:57
how to filter by database name and return only the log size??
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-25 : 14:28:23
You can put result of 'dbcc sqlperf(logspace)' in temp table and filter with proper query.
Go to Top of Page

cybertron
Starting Member

4 Posts

Posted - 2008-02-26 : 05:02:43
I've tried to created that problem. You can go to this link, maybe it can help you.
http://cybertron-network.blogspot.com/2008/02/how-to-shrink-your-transaction-log.html

If you guys any idea better than i've tried, tell me ok ...

---------------------------------------------------------------------------------------------------


"We give you that we know, We share to you that we've learned, We send to you that we need to be discussed"
http://cybertron-network.blogspot.com
Go to Top of Page

juicyapple
Posting Yak Master

176 Posts

Posted - 2008-02-27 : 20:15:57
I found some useful code here...


Check log size

--First create the table to hold data from dbcc sqlperf
CREATE TABLE LogSpaceUsage
(
DBName Sysname,
LogSize_MB Numeric(12,7),
LogSpaceUsed_Percent Numeric(9,6),
Status TinyInt,
UsageStatTimeStamp SmallDateTime
)


--Create Procedures here one by one
-- Proc 1
CREATE PROCEDURE LogUsageInfo
AS
SET NOCOUNT ON
BEGIN
dbcc sqlperf(logspace)
END
GO

-- Proc 2
CREATE PROCEDURE FindLogSpaceUsage
(
@UsageStatTimeStamp SmallDateTime =NULL
)
AS

SET NOCOUNT ON

DECLARE
@CurrentTime SmallDatetime

BEGIN
Create Table #tmpLogSpaceUsage
(
DBName Sysname,
LogSize_MB Numeric(12,7),
LogSpaceUsed_Percent Numeric(9,6),
Status TinyInt,
UsageStatTimeStamp SmallDateTime
)


-- Get the Log Space Usage data
INSERT INTO #tmpLogSpaceUsage
(
DBName,
LogSize_MB,
LogSpaceUsed_Percent,
Status
)
exec LogUsageInfo


-- Get Current Date Time -
SET @CurrentTime = getdate()


-- Fill in timestamp of log space usage report
UPDATE #tmpLogSpaceUsage
SET UsageStatTimeStamp = @CurrentTime


-- Populate your table created
INSERT LogSpaceUsage
SELECT
DBName,
LogSize_MB,
LogSpaceUsed_Percent,
Status,
UsageStatTimeStamp
FROM #tmpLogSpaceUsage WHERE DBName = 'DBName'

-- Fetch data from your table. UsageStatTimeStamp would give you the timestamp to filter
-- on any particular time instance.
IF (@UsageStatTimeStamp IS NULL)
SELECT *
FROM LogSpaceUsage
WHERE UsageStatTimeStamp = @CurrentTime
ELSE
SELECT *
FROM LogSpaceUsage
WHERE UsageStatTimeStamp = @UsageStatTimeStamp

END

GO



--Finally, get your data.
EXEC FindLogSpaceUsage

SELECT * FROM LogSpaceUsage WHERE DBName = 'DBName'

Go to Top of Page
   

- Advertisement -