Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


simple recovery model Log truncation


simple recovery model Log truncation

Author
Message
parthi-1705
parthi-1705
SSChasing Mays
SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)SSChasing Mays (602 reputation)

Group: General Forum Members
Points: 602 Visits: 2196
Hi
1) At what time intervel does the simple recovery model truncates the trans Log
2) I am having a 30 million records i need to delete 25 million old records with minimum log how it can be done there will be continues users accessing the table

Thanks
Parthi

Thanks
Parthi
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47175 Visits: 44356
1) Whenever a checkpoint occurs. Only log records up to the beginning of the oldest open transaction can be truncated.
2) Do it in batches and run CHECKPOINT between those batches.


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


vidya_pande
vidya_pande
SSC Eights!
SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)

Group: General Forum Members
Points: 891 Visits: 242
I have simple solution for you.

Copy 5 Million records to another dummy or staging table.
Truncate the original table.
And then copy 5 Million rows from Dummy table to original table.

If you do not have partitions created on table this is the fastest way.

;-)



Brandie Tarvin
Brandie Tarvin
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7752 Visits: 8726
parthi-1705 (3/17/2010)
I am having a 30 million records i need to delete 25 million old records with minimum log how it can be done there will be continues users accessing the table


Understand that minimum logging is different than "no" logging. You might want to change the Recovery mode to Bulk-Logged instead of Simple (unless the db is already set to Simple) before doing your delete. This way, if you need to recover, you'll still have a transaction log to recover from.

In Simple mode, checkpoints happen quite regularly and automatically. Usually, you'll hear people say "the transaction log truncates all transactions as soon as they are commited." It's not quite a true statement, but it does mean that transactions are unrecoverable almost instantaneously. The logging that occurs is only for the SQL Server engine, not for the DBA.

Per BOL:
If the database is using the simple recovery model, an automatic checkpoint is generated whenever the number of log records reaches the lesser of these two values:

The log becomes 70 percent full.

The number of log records reaches the number the Database Engine estimates it can process during the time specified in the recovery interval option.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
Brandie Tarvin (3/17/2010)
Understand that minimum logging is different than "no" logging. You might want to change the Recovery mode to Bulk-Logged instead of Simple (unless the db is already set to Simple) before doing your delete. This way, if you need to recover, you'll still have a transaction log to recover from.

Deletes are always fully logged (truncate table excepted, which is always 'minimally logged' - sort of) regardless of the recovery model.
Changing from simple recovery also changes nothing until a full backup is taken to establish a base for a future restore.
The log stays in auto-truncate mode until the first full backup after a change from simple recovery.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
vidya_pande (3/17/2010)
I have simple solution for you.

Copy 5 Million records to another dummy or staging table.
Truncate the original table.
And then copy 5 Million rows from Dummy table to original table.

If you do not have partitions created on table this is the fastest way.

;-)

Simple, yes. But not always practical on a production system.
Also, remember that foreign key constraints will need to be dropped, indexes re-created etc etc etc
Good idea, though.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
The Natrix
The Natrix
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 653
vidya_pande (3/17/2010)
I have simple solution for you.

Copy 5 Million records to another dummy or staging table.
Truncate the original table.
And then copy 5 Million rows from Dummy table to original table.

If you do not have partitions created on table this is the fastest way.

;-)



I had originally thought to do that since the table I had wasn't referenced by foreign keys. But its a replicated database, so no truncations allowed.
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
How To Delete a Large Number of Records
Limiting Deleted Rows by Using TOP



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
hp_dba_uk
hp_dba_uk
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 123
Hi there,

I used a script to changed around 60 cust-test DBs from Full to simple recovery model as they were not needed to be in Full recovery mode etc

I did the change on Fri and today is Monday..I was expecting the see lot of space freed up on the drive where files are stored, by this as thinking it will run checkpoint etc....but below reasons tells me it wont happen straight away:
================
If the database is using the simple recovery model, an automatic checkpoint is generated whenever the number of log records reaches the lesser of these two values:

The log becomes 70 percent full.

The number of log records reaches the number the Database Engine estimates it can process during the time specified in the recovery interval option.
=================


Some of these DBs have never been backed up but were in Full recovery model. So does this change anything?
or is it a simple matter of watining?
Divine Flame
Divine Flame
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1567 Visits: 2799
hp_dba_uk (9/24/2012)
Hi there,

I used a script to changed around 60 cust-test DBs from Full to simple recovery model as they were not needed to be in Full recovery mode etc

I did the change on Fri and today is Monday..I was expecting the see lot of space freed up on the drive where files are stored, by this as thinking it will run checkpoint etc....but below reasons tells me it wont happen straight away:
================
If the database is using the simple recovery model, an automatic checkpoint is generated whenever the number of log records reaches the lesser of these two values:

The log becomes 70 percent full.

The number of log records reaches the number the Database Engine estimates it can process during the time specified in the recovery interval option.
=================


Some of these DBs have never been backed up but were in Full recovery model. So does this change anything?
or is it a simple matter of watining?



Are you waiting for the space to be available to OS? If yes, that won't happen automatically. Changing the recovery model to SIMPLE does break the log chain & allows the transaction log to be truncated on every check point. However, truncatation of the transaction log means making the inactive VLFs inside the transaction log file as reusable & nothing else.

In case you want the freed space returned to OS itself, you need to shrink the transaction log file.

Note: If you know that after few days the transaction log file is going to be of the same size again (after shrinking), there is no point in shrinking it.


Sujeet Singh
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