When should I use the full recovery model and when should I use the simple recovery model for databases?
You should use the full recovery model when you require point-in-time recovery of your database. You should use simple recovery model when you don't need point-in-time recovery of your database, and when the last full or differential backup is sufficient as a recovery point. (Note: there is another recovery model, bulk logged. For more information on the bulk-logged recovery model see this reference)
Microsoft OLE DB Provider for SQL Server (0x80040E14) The transaction log for database 'DATABASE NAME' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
The reason you got that error (most likely) is because you haven't been backing up your transaction log. When it isn't backed up, then it will continue to physically grow the transaction log file (provided autogrowth is enabled and maxsize allows) because it can't reuse any of the "portions" of the transaction log (virtual log files). It can only mark those VLFs for reuse and allow the "wrap-around" nature of the transaction log when you do a transaction log backup (and a few other requirements, such as no active transactions, some replication aspects, etc.).
To shrink the log and making the database accessable again, I changed the recovery model from FULL to SIMPLE and shrinked the logical file log, with the following command
......
It helped, but now I need to understand WHY it helped, HOW this situation started and HOW to prevent this in the future?
This helped you because by setting your database to the simple recovery model you told SQL Server that you no longer care about point-in-time recovery, and the requirement to ensure that virtual log files no longer need to be preserved and marked as active, now a checkpoint process marks these VLFs as inactive.
Excerpt/quote taken from this MSDN reference:
Under the simple recovery model, unless some factor is delaying log truncation, an automatic checkpoint truncates the unused section of the transaction log. In contrast, under the full and bulk-logged recovery models, once a log backup chain has been established, automatic checkpoints do not cause log truncation.
Then you did a physical database file shrink and because there was free space in your transaction log now it was able to physically shrink the NTFS file.
Reading worth spending some time on:
- Recovery Models
- Managing Transaction Logs (Gail Shaw)
- Factors That Can Delay Log Truncation
EDIT after your Edit:
Is the new recovery model and databaseshrink going to be a conflict with this script?
That BACKUP DATABASE
command will work with either recovery models. As for the routine database shrink... DON'T DO IT!!!! Seriously, size your database accordingly, and if you utilize the full recovery model then ensure that you are doing routine and frequent transaction log files, not just to keep the transaction log size at bay but to also meet recovery point objects.
We are not doing any other kind of backup of the databases, and therefore not the transaction logs, should we?
If your database is utilizing the full recovery model, then yes you should be doing transaction log backups. If your database is in simple recovery, then you physically can not do a transaction log backup.
As for what recovery model to use (simple vs. full), we can't make that decision for you. Only you, your business team, and your SLAs can.
The only thing you're really changing by using simple recovery is you're shifting the time when you have to perform additional backup work. Instead of taking log backups throughout the process (which shouldn't be extra work, because you should already be doing that!), now you have to take a full backup at the end of the process. In the meantime, you've opened yourself up to real problems because should anything go wrong between the start of the operation and the completion of the full backup, you are going to be in some hot water because you've lost the ability to recover to a point in time.
(Since the bulk of your activity is delete, you can't even benefit from minimal logging - and even if you could, Thomas' advice to use bulk-logged is a better approach than switching to simple - this still allows you to recover to a point in time that has been backed up by the log and is not inside a minimally-logged transaction.)
As you're planning to delete 90% of your data, you may want to think about this in a different way: move the data you want to keep to a new table, then drop the old table and rename the new one. The stuff that costs a lot of log is when there is a lot of data movement. DROP is logged too, but unlike DELETE, only the deallocation, no movement. You'll need a little extra space to support this (~10%) but you'll also avoid any after-the-fact rebuild.
All of these options involve trade-offs, but I think your plan to change recovery to simple offers the least benefit and introduces you to the most risk. I wouldn't do it without having your resume dusted off.
Best Answer
It depends on your RTO (Recovery Time Objective) and RPO (Recovery Point Objective).
Recovery Time Objective: Time duration to restore the database in case of any disaster.
Recovery Time Objective: The time interval that may pass until the database recovered. (Acceptable time duration for data loss).
Before you decide your recovery model and backup strategy, I would suggest you go through the Database Recovery Model and Backup Types in SQL Server before you decide your recovery model and backup strategy.
Edit:1
The ola-hallengren backup SP doesn't automatically execute all supported backups according to the recovery model of respective databases.
So, if you execute the SP with
@BackupType = 'LOG'
for the database with simple recovery model, I hope it'll fail and raise & log an error.You need to execute separate script for all types of backup with
@BackupType = 'FULL',
@BackupType = 'DIFF' &@BackupType = 'LOG'
.You can execute separate script for LOG backup of the databases with FULL/BULKED_LOG recovery model with
@Databases='Database_1, Database_2,...'
.Note: All backup logs (success/failure) are maintained into
CommandLog
table.Edit:2
At line 2136, it's validating, " if
@BackupType
with recovery model of the database, then only it's proceeding to prepare backup script. to if condition is like this. Prior to that line I didn't see any validation to raise/log an error message into thecommandlong
table.So I would suggest you to execute separate script for transaction log backup that includes the databases with full recovery model.
Fourth line of the below script validating the condition.
Thanks!