Showing posts with label functioning. Show all posts
Showing posts with label functioning. Show all posts

Friday, March 30, 2012

Mirroring and Log File Growth

We currently have a 10GB database that is functioning properly mirrored. The only issue we have is that the log files grow very quickly during the early morning hours when a large number of transactions hit our DB from scheduled jobs. We have transaction log backup and shrink job that runs every 3 hours to backup the log and shrink the logical file to 10GB. In most cases this will shrink the log back down to it's desired size of 10GB. However, on some mornings it takes more repetitions of the log backup/shrink job to return the log size back to "normal". During this these times when it does not shrink the DB effectively, I get a report of the job process by email that states "Cannot shrink log file 2 (e_Log) because all logical log files are in use." I run a DBCC OPENTRAN command, and there are no open transactions. Eventually, the log file will return to it's normal size of 10GB through the log file backup job. I have a few questions though.

1. Is this normal behavior during moderate database use?
2. Does mirroring have any effect on the SIZE of the log file?
3. Is it normal for the size of the data file to be smaller than the size of the log file on a heavily used database?
4. Does anyone have any suggestions to better maintain the log file size?

Thank you,
Greg

Mirroring won't affect the log, unless the Principal can't connect to the mirror in which case transactions will queue in the log and may cause issues.

Why are you shrinking your log? It should be as big as it needs to be, i.e. large enough to hold the transactions from your scheduled jobs. Having it auto-grow then re-shinking it is a waste of time and resources (it will slow down your scheduled jobs while the log grows).

The reason you can't shrink it sometimes is because the log actually consists of Virtual Log Files (VLFs). If the active one of these is near the end of the log file, it won't be shrinkable until it moves back to the beginning of the log file due to transactions having happened.

Normally the log file is smaller than the data file, but there may be exceptions. The bottom line is, the log needs to be as big as is required by the size and volume of transactions using the database.

Ensure you have adequate log backups of a suitable frequency all the time, and especially during your batch processing.

Monday, March 19, 2012

Min not working

Hi all:
Because me not this functioning the following one query.

simply me not the function respects min, because?, that I am doing badly?

Select Distinct(Min(c.gentime)),
a.CardNumber,a.CardHolderId,a.Deleted,
b.RecordId,b.FirstName,b.LastName,b.Deleted,b.Note 4,
c.param3,c.param2,c.param1,c.recvtime,c.gentime,c. link1,c.link2,c.link3,c.deleted,c.recordid,c.seqid
From Card a,
CardHolder b,
History c
Where ((a.cardholderid = b.recordid)And(b.recordid=c.link3))
And(a.Deleted = 0)And (b.Deleted = 0)And(c.deleted = 0)
And(a.cardnumber Between 1500 And 1600)
And(b.note4 <> 'Mantenimiento')
And(c.RecvTime >= CONVERT(DATETIME, '2006-10-01 00:00:00', 102))And(c.RecvTime <= CONVERT(DATETIME, '2006-10-12 23:59:59', 102))
And(c.Link1=10)
Group By a.CardNumber, a.CardHolderID, a.Deleted,
b.RecordID, b.Deleted, b.FirstName, b.LastName, b.Note4,
c.Deleted, c.RecvTime, c.GenTime, c.Param1, c.Param2, c.Param3, c.Link1, c.Link2, c.Link3, c.Link4,c.recordid,c.seqid
Order By a.CardNumber,c.recvtime

Thanks.:confused:the problem is because you have c.Link4 in the GROUP BY but not in the SELECT

also, please note: DISTINCT is not a function

try this --select Min(c.gentime) as min_gentime
, a.CardNumber
, a.CardHolderId
, a.Deleted
, b.RecordId
, b.FirstName
, b.LastName
, b.Deleted
, b.Note4
, c.param3
, c.param2
, c.param1
, c.recvtime
, c.gentime
, c.link1
, c.link2
, c.link3
, c.deleted
, c.recordid
, c.seqid
from Card a
inner
join CardHolder b
on b.recordid = a.cardholderid
inner
join History c
on c.link3 = b.recordid
where a.Deleted = 0
and b.Deleted = 0
and c.deleted = 0
and a.cardnumber between 1500 and 1600
and b.note4 <> 'Mantenimiento'
and c.RecvTime >= '2006-10-01'
and c.RecvTime < '2006-10-13'
and c.Link1 = 10
group
by a.CardNumber
, a.CardHolderId
, a.Deleted
, b.RecordId
, b.FirstName
, b.LastName
, b.Deleted
, b.Note4
, c.param3
, c.param2
, c.param1
, c.recvtime
, c.gentime
, c.link1
, c.link2
, c.link3
, c.deleted
, c.recordid
, c.seqid
order
by a.CardNumber
, c.recvtime|||thanks by answering, the problem is, that the inner join does not respect me the rank dated, I need a value by each employee, by each I gave of the rank.

Thanks.:confused:|||okay, try this --select c.gentime as min_gentime
, a.CardNumber
, a.CardHolderId
, a.Deleted
, b.RecordId
, b.FirstName
, b.LastName
, b.Deleted
, b.Note4
, c.param3
, c.param2
, c.param1
, c.recvtime
, c.gentime
, c.link1
, c.link2
, c.link3
, c.deleted
, c.recordid
, c.seqid
from Card a
inner
join CardHolder b
on b.recordid = a.cardholderid
inner
join History c
on c.link3 = b.recordid
where a.Deleted = 0
and b.Deleted = 0
and c.deleted = 0
and a.cardnumber between 1500 and 1600
and b.note4 <> 'Mantenimiento'
and c.RecvTime >= '2006-10-01'
and c.RecvTime < '2006-10-13'
and c.Link1 = 10
and c.gentime =
( select min(c.gentime)
from History
where link3 = b.recordid
and deleted = 0
and RecvTime >= '2006-10-01'
and RecvTime < '2006-10-13'
and Link1 = 10 )
order
by a.CardNumber
, c.recvtime|||thanks but the following error marks me:

An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

:eek:|||i'm going to move this query to the SQL Server forum

i don't understand the error message, maybe someone else does|||Not completely sure what is going on here, but trying moving the subquery to the JOIN clause:select c.gentime as min_gentime
, a.CardNumber
, a.CardHolderId
, a.Deleted
, b.RecordId
, b.FirstName
, b.LastName
, b.Deleted
, b.Note4
, c.param3
, c.param2
, c.param1
, c.recvtime
, c.gentime
, c.link1
, c.link2
, c.link3
, c.deleted
, c.recordid
, c.seqid
from Card a
inner
join CardHolder b
on b.recordid = a.cardholderid
inner
join History c
on c.link3 = b.recordid
inner
join --subquery
(select link3,
min(c.gentime) as gentime
from History
where link3 = b.recordid
and deleted = 0
and RecvTime >= '2006-10-01'
and RecvTime < '2006-10-13'
and Link1 = 10
group by link3) subquery
on subquery.link3 = b.recordid
and subquery.gentime = c.gentime
where a.Deleted = 0
and b.Deleted = 0
and c.deleted = 0
and a.cardnumber between 1500 and 1600
and b.note4 <> 'Mantenimiento'
and c.RecvTime >= '2006-10-01'
and c.RecvTime < '2006-10-13'
and c.Link1 = 10
order
by a.CardNumber
, c.recvtime