{"id":2650,"date":"2015-11-23T03:48:29","date_gmt":"2015-11-23T08:48:29","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=2650"},"modified":"2023-10-17T05:34:28","modified_gmt":"2023-10-17T09:34:28","slug":"bulk-logged-recovery-model","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/bulk-logged-recovery-model\/","title":{"rendered":"Bulk-logged Recovery Model"},"content":{"rendered":"
The bulk-logged recovery model is\u00a0designed for intermittent use to improve the performance of bulk imports of large amounts of data. It’s practically\u00a0the same as the full recovery model with the only exception\u00a0that under the bulk-logged recovery model some operations are logged minimally. These operations are:<\/p>\n
<\/p>\n
Though the bulk-logged recovery model reduces log space usage by using minimal logging for most bulk-logged\u00a0operations, it is recommended to temporarily switch to bulk-logged recovery model right before performing these operations and then immediately switch back to the full recovery model. This allows to minimize the use of bulk-logged recovery model.<\/p>\n
There is the risk of data loss for these bulk-copy operations\u00a0because bulk-logging operations prevent\u00a0recapturing changes on a transaction-by-transaction basis. The point-in-time recovery with the bulk-logged recovery model is not possible\u00a0because none of the minimally logged operations can be restored.<\/p>\n
Let’s consider another scenario:<\/p>\n
<\/p>\n
This picture shows that the failure occurs at 15:00, but before this a minimally logged operation took place and the next transaction log backup (marked yellow, at 16:00) contains bulk-logged changes. This means\u00a0that point-in-time recovery is possible only up to the previous log backup. If you try to restore your database to later point-in-time you’ll get the following errors:<\/p>\n
This log backup contains bulk-logged changes. It cannot be used to stop at an arbitrary point in time.<\/span>\r\n\r\nThe STOPAT clause specifies a point too early to allow this backup set to be restored. Choose a different stop point or use RESTORE DATABASE WITH RECOVERY to recover at the current point.<\/span>\r\n\r\nRESTORE LOG is terminating abnormally<\/span><\/pre>\nSo the best sequence of actions in this case is to restore the database to its state as of 14:00. All other changes will be irretrievably lost.<\/p>\n
Here’s how to do it:<\/p>\n
RESTORE DATABASE your_database<\/span><\/em> FROM DISK =<\/span> 'full_10_00.bak'<\/span> WITH NORECOVERY,<\/span> REPLACE<\/span>\r\nRESTORE LOG<\/span> your_database<\/span> <\/em>FROM DISK =<\/span> 'log_12_00.bak'<\/span> WITH NORECOVERY\r\nRESTORE<\/span> LOG <\/span>your_database<\/em> <\/span>FROM DISK <\/span>=<\/span> 'log_14_00.bak'<\/span> WITH <\/span>RECOVERY<\/span><\/pre>\nIt is also important to mention that under the bulk-logged recovery model if a log backup covers any bulk operations it contains both log records and the data pages that were changed by bulk operations. \u00a0Also, if read\/write database is changed to read-only access after a bulk-logged operation, subsequent log backups might capture more data than necessary. This is because the data file cannot be updated to track which data extents were changed by a bulk-logged operation.<\/p>\n
Use the following command to set bulk-logged recovery model :<\/p>\n
ALTER DATABASE<\/span>\u00a0your_database<\/i> SET RECOVERY BULK_LOGGED<\/span><\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"The bulk-logged recovery model is\u00a0designed for intermittent use to improve the performance of bulk imports of large amounts of data. It’s practically\u00a0the same as the full recovery model with the only exception\u00a0that under the bulk-logged recovery model some operations are logged minimally. These operations are: Bulk import operations (bcp, INSERT … SELECT, and BULK INSERT). […]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[],"yoast_head":"\n
Bulk-logged Recovery Model - Sql Server Backup Academy<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n