Deleting Very large objects from the second stage recycle bin
Have you ever been in a situation where the second stage library has a folder that is very large say about 56 GB. And it cannot be deleted because the database locks during deletion and the site becomes inaccessible. The process eventually times out and the site access resumes, but the item remains in the second stage recycle bin.
Then this article might be helpful....read on
First lets get a little familiar with the terms used
- First stage recycle bin - It is nothing but the site's Recycle Bin. Anything a user delete's from the site goes here.
Users can delete it from here or restore the item back
- Second stage recycle bin - The site Collection Recycle Bin. If item is deleted from the site recycle bin it lands here.
Site collection Administrators can delete it from here or restore the item back
Some helpful articles
- New to SharePoint 2007 recycle bin, read View, restore, or delete items in the Recycle Bin of a SharePoint site
- Want to know how to configure it then refer SharePoint Recycle Bin Administration
- An interesting article on how to use the recycle bin
- Protect and restore content by using Recycle Bins and versioning https://technet.microsoft.com/en-us/library/cc288451.aspx
How does deletion work
When you delete an item from a Web site, the item is sent to the site's Recycle Bin. If you click Recycle Bin on the Quick Launch, you can see all of the items that you've deleted from your site. You can either restore or delete the item from the Recycle Bin. When you delete an item from the Recycle Bin, the item is sent to the Site Collection Recycle Bin.
When an item is deleted from the site collection recycle bin (manually or automatically) the item is flushed from the content database. Other wise it remains in the database. Only one flag
Few thoughts that crossed my mind
- How can one land up with this big an item in the second stage recycle bin?
- If it is in second stage recycle bin, how did they flush it from first stage?
- Is this an acceptable behavior?
Here's what i found
- Lets consider one example: say there is a folder in the document library which has many files uploaded. The folder is deleted which is few GB in size.
- When we delete items from the site or the first stage recycle bin it remains in the content database. But when we delete it from second stage recycle bin, that is when it is flushed from the content database. So deleting a large file from first stage bin was not a problem.
- Ideally speaking no, but as of now we need to leave with it.
There are certain things that can be done to avoid this situation
1. Restore the problem library to its original location. Delete the documents few at a time. Flush the second stage recycle bin periodically.
By default the below command will show the period at which the recycle job will be run
STSADM -o getproperty -propertyname job-recycle-bin-cleanup -url https://<sitename>Run the below command to run the recycle timer job periodically
STSADM -o setproperty -propertyname job-recycle-bin-cleanup -propertyvalue "<configure a convenient time>" -url https://<site name>2. Disable Second stage recycle bin from the central administration page
Go to Central Administration > Application Management > Web Application General Settings
Set Recycle Bin > Second stage Recycle Bin > OFFNote: This will flush the items in the second stage recycle bin for site collections in that web application. This is a web application level setting.
On enabling second stage recycle bin the items will be removed from the recycle bin. The files are deleted from the database so it cannot be retrieved.3. A custom code based on SharePoint Object Model can be used to flush the large files from the second stage recycle bin.
Sample code
SPSite site = new SPSite(<<siteurl>>);
SPWeb web = site.RootWeb;SPRecycleBinQuery q = new SPRecycleBinQuery();
q.RowLimit = Int32.Parse(<<number of items to be deleted>>);
q.OrderBy = SPRecycleBinOrderBy.Default;SPRecycleBinItemCollection itemColl = web.GetRecycleBinItems(q);
foreach (SPRecycleBinItem item in itemColl)
{
Guid[] id = new Guid[1];
id[0] = item.ID;
itemColl.Delete(id);
}Disclaimer:
The sample code provided is on "AS IS" basis with no warranties, and confers no rights.
Comments
Anonymous
November 02, 2010
Thanks. I found this very useful. I wish Microsoft improves its documentation on this API.Anonymous
August 10, 2011
I also found this quite educational. Thanks for posting it.Anonymous
September 29, 2011
Indeed!! verry useful!!http://www.weareverbeads.comAnonymous
October 23, 2011
Hi Ajitha,I found that once you delete the documents from secondary recycle bin, the site quota shows the correct size however the content database still shows the same size as before deletion. Any explanation would help?Anonymous
August 08, 2013
I have a folder of size around 10GB which is currently in second stage recycle bin. I need to understand that when SharePoint timer job will run to delete that will that be an issue on DB server like timeout/tempDB full/ transaction log growing in hugh amount? Any comments/instructions will be helpful.Anonymous
July 21, 2015
You will need to shrink SQL DatabaseAnonymous
August 16, 2015
Great post.. let me try the 3 approaches and let you know