SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Records suddenly disappear from fn_dblog in SQL Server 2008


Records suddenly disappear from fn_dblog in SQL Server 2008

Author
Message
rani_rahbani
rani_rahbani
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 9
Hello,

I have a problem with the records from fn_dblog.

When i make an insert/update/delete the records of the concerning table are shown in fn_dblog but after a little time they suddenly disappear.

Do you have any idea why that happens and how to solve the problem ?

Note : my database recovery mode is set to full, there have been no back up and no recovery done to the database and I am using sql server 2008....

Thank you
GilaMonster
GilaMonster
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225807 Visits: 46321
Because the database has never had a backup, it's behaving as though it's in simple recovery model. A DB in full recovery requires a full backup to initialise the log chain, only after a full backup has been run is the DB actually in full recovery. After that point only log backups will mark the log as reusable (truncate the log).

Because the database is behaving as though it's in simple recovery model, a checkpoint operation will truncate the log, marking VLFs which are no longer needed as inactive. fn_dblog only shows log records in active VLFs.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


rani_rahbani
rani_rahbani
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 9
thank you ,

I will try backing up my database and see if the problem is solved.

In the mean while I am doing this because i am asked to check every night who made insert/update/delete to a certain table and check the old data (deleted and updated) or the new data (inserted)

is there a way to do so (maybe a stored procedure..) ?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225807 Visits: 46321
rani_rahbani (3/14/2014)
In the mean while I am doing this because i am asked to check every night who made insert/update/delete to a certain table and check the old data (deleted and updated) or the new data (inserted)


Audit trigger writing into an audit table.

The transaction log is NOT for audit purposes, don't try to use it as such. Go with a trigger or, if this is actually a SQL 2008+ server, CDC, Change Tracking or SQL Audit, whichever meets your needs

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


rani_rahbani
rani_rahbani
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 9
Ok but the problem is that i have more then 100 tables to audit and check so creating a trigger or CDC is not really a good option.

What is the best practice to use an audit for these 100+ tables without creating commands for every table (perhaps there is an option or a tool that allows me to monitor all the tables on a database and save in case of any insert/update/delete...)

thank you for your help.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225807 Visits: 46321
Trigger/CDC is indeed a good idea. Write a script to auto-create the triggers on all the necessary tables, not that hard to do.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


rani_rahbani
rani_rahbani
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 9
thank you for the advice,

I am already trying to create a dynamic trigger.

in the mean while i am trying to get to know fn_dblog() better.
But i noticed a problem in the fuction.
while reading topics related to fn_dblog i noticed that there is a slot ID in fn_dblog that saves the slot ID of the updated record here is my scenario :

A record is updated then another record is deleted that is above the updated record then the slot ID of the updated table has changed but the Slot ID in the fn_dblog stays the same and when i run the procedure it indicates another row that has not been updated
EXAMPLE:
in the students tabel I have four records, record 1 with slot ID = 0, record 2 with slot ID = 1, record 3 with slot ID = 2 and recod 4 with slot ID = 3

I update Record 3 and the saved slot ID in fn_dblog is 2.
I delete Record 2 and the slot ID of Record 3 is now 1 but it stays 2 in fn_dblog.
i run Recover_Modified_Data_Proc it gives me Record 4 (things get more complicated with multiple deletes and updates)
is there any way to rectify this problem ?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225807 Visits: 46321
rani_rahbani (3/17/2014)
I am already trying to create a dynamic trigger.


No, don't try to create triggers which use dynamic SQL to do anything anywhere. That's going to kill performance, maintainability and a bunch more.

Create a procedure which uses the catalog views to create a specific trigger for each table.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


rani_rahbani
rani_rahbani
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 9
Ok I am going to do just that...

Relating my other problem do you have any idea about the problem or how to solve it ??
GilaMonster
GilaMonster
SSC Guru
SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)SSC Guru (225K reputation)

Group: General Forum Members
Points: 225807 Visits: 46321
I'd have to sit and play with the log for a few hours to figure out what you're describing. It's not documented at all, it changes from version to version, it's not a good thing to base important code on

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search