Blog about Microsoft technologies, Office System, SharePoint, MOSS, WSS, Search and "The new world of work"
in

Automatically creating content databases

As most of you all know you need to prevent your content databases to expand too much. According to best practices from Microsoft you should keep your content databases around a maximum of 50 GB. Keeping the content databases small, makes it easier to backup or restore them. This sounds like its really easy to do this, but to bad.... it isn't.

There is now way you can tell a content database automatically to stop growing and continue in another new content database if it gets to big. There is an option in Central Adminstration to set the number of Sites. You could define per site how large it can be and use that in combination with the maximum allowed sites as a maximum storage. But Central Administration will only send an email or even denies the creation of new sites in the content database if it gets to its maximum. 

Content databases can be set to two different status which are important to understand. These are:

  • Offline
    This means that it is not possible to generate any new sites in the content database
  • Ready
    The content database is available for hosting new sites

Each content database belongs to a web application. Its state can be changes in "Manage Content Database Settings" by clicking on the content database in "Manage Content databases".

When you want to use a new content database, you have to create yourself a new content database and set its status to "Ready". To prevent the previous content database to be used (and thus growing) you have to set its status to "Offline". These things can only be done through the Central Administration or by programming some code.

Doing this by code:

public static bool ExpandDatabase(SPSite site)
{
  bool success = false;

  try
  {
    // get current content database
    SPContentDatabase currentDB = site.ContentDatabase;

    // set the current database offline which means it
    // can be reached but not written to anymore
    currentDB.Status = SPObjectStatus.Disabled;
    currentDB.Update();

    // create a new name
    string newName = currentDB.Name + string.Format("_{0}", site.WebApplication.ContentDatabases.Count);

    // create the new content database and activate it
    SPContentDatabase newDB = site.WebApplication.ContentDatabases.Add(currentDB.Server, newName,
    currentDB.Username, currentDB.Password,
    currentDB.WarningSiteCount, currentDB.MaximumSiteCount, 0);

    success = true;
  }
  catch (Exception)
  {
  }

  return success;
}

This code set the current database of the web application to an offline state which prevents new sites to be created in there. Secondly a new content database with a new name for the web application is created and set to the state of ready. Therefor any new site created will be created in that content database. Below you will see the result when you have a look into the Central Administration.

So when do you know when you have reached the 50 GB? There is not a really an easy way to determine in bytes the size of a site, site collection or content database. I have posted some time ago an article describing how you could determine the size of your SPWeb object based on its folders and files.

But you could also use the following method to determine if there is a need for a new content database. The method DiskSizeRequired of the object SPContentDatabase indicates in bytes how much disk space it will take to backup the content database.

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback url for this post:
http://www.bloggix.com/blogs/microsoft/trackback.ashx?PostID=365

» Comments

    No comments yet. Be the first to comment!

» Leave a Comment

(required) 
(optional)
(required) 

Submit

Subscriptions

News

SlideShare.net
I'm using SlideShare.net for sharing my presentation material. You can find it here

Dutch SharePoint User Group
The Dutch SharePoint User Group is an independent social network for people to collaborate and share information around SharePoint Technology and products. By learning from others you can improve your skills and expertise, around areas, which are then again a benefit to the social network. This platform is a community platform for SharePoint developers, architects and designer who want to share information, tricks, code and content. Its also a good starting point for people without SharePoint knowledge who are interested in SharePoint Technology. Read more

Oktober 2008 i'm working for a new company called Sparked. The new world of work causes organizations to re-think about their ways of communication and interaction with their customers.

Increasing usage of web technology and the new generation workers brings changes into these organizations.

Sparked helps these organizations to accelerate adoption of this technology platform to effectively use it around content management, content exposure and collaboration.


April 2008 i have been to the first SharePoint Conference in Dubai. Dubai is an overwhelming town with a lot of passionate people. I had a great time. Thank you my friends!



You can also find my on Facebook

Tags

Alexander Meijers

Previous Blog about SharePoint