March 14, 2014 at 4:00 am
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
March 14, 2014 at 4:10 am
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
March 14, 2014 at 5:01 am
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..) ?
March 14, 2014 at 5:15 am
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
March 14, 2014 at 5:31 am
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.
March 14, 2014 at 5:38 am
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
March 17, 2014 at 9:31 am
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 ?
March 17, 2014 at 9:35 am
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
March 17, 2014 at 9:42 am
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 ??
March 17, 2014 at 9:44 am
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
March 17, 2014 at 10:02 am
Ok but i will appreciate if you could give me a hint on how to solve this problem (the case scenario happened at work and i needed to retrieve a record that was modified on friday and i was pointed to another record that was not modified because of this i noticed the problem)
thank you
March 17, 2014 at 10:08 am
Sure, once I've found a few hours to sit and investigate the scenario you're describing, figure out what's happening.
The log is not an audit trail, don't try to use it as such.
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
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply