Directory Services/Active Directory

Ulf B. Simon-Weidner's Blog
Some details about Tombstones, Garbage Collection and Whitespace in the AD DB

I was rereading one of my posts in this blog today - Active Directory Backup? Don't rush - you'll get more time - and realized that not everyone might be aware what a Tombstone is.

As we know Active Directory is a multi-master directory: Every DC is usually able to write into the directory. Examples of single-master directories are classical DNS (only one primary server per zone, and the primary server is the one who writes updates to the zone, many secondaries are able to pull those informations and provide them to other clients/servers) or a Windows NT 4.0 Domain with one Primary Domain Controller (PDC) and multiple Backup Domain Controllers (BDC) (same thing here - only the primary is allowed to write).

One of the things to consider when designing a multi-master directory are how content will be deleted. If we would delete something completely and right away, how would another domain controller figure out that it was deleted and that he needs to delete the same object in his database?

And that's where the tombstones fit into the picture. If we delete a object it is not immediately deleted but "converted" into a tombstone. When replication occurs the other DCs note the change of the object and convert their local copies in the database into tombstones by replicating the changes of the object. So what happens to the object when it is deleted?

The object will be marked as deleted, meaning the isDeleted-Attribute is set to true. It will be also moved to the "Deleted Objects"-container. Also all Attributes which are not supposed to remain in a tombstone will be stripped from the object. So most data is not there anymore, but the most important ones like the Global Unique Identifier (GUID) and the Security Identifyer (SID) will remain. There are additional attributes being kept in the tombstone, e.g. in Windows Server 2003 there is also the SID-History kept in the tombstone. Which attributes will remain in the tombstone is defined in the schema, in the definition of the attribute. If the fourth bit in the searchflags (= decimal 8) is set the attribute will remain in the tombstones. You are able to configure additional attributes to remain in the tombstone by setting this bit as well.

Using the following command you are able to retrieve most attributes which remain in the tombstone (everything in one line):

dsquery * cn=schema,cn=configuration,dc=yourcomain,dc=com
  -filter "(&(objectClass=AttributeSchema)(searchFlags:1.2.840.113556.1.4.803:=8))"
  -scope subtree -attr name

~eric reminded me that this query will not necessarily return all attributes which are preserved in a tombstone - some critical objects and changes of the list are hardcoded and will remain in the tombstone no matter what the searchflags state. SidHistory in Windows Server 2003 SP1 is one of them which won't appear in the schema unless you change it yourself, but will remain in the tombstone. The reason for this approach is to not require a update in the schema partition when installing SP1. However I wouldn't call changing the searchflags of an attribute a major change in the schema (you are able to reverse it, and especially the change of tombstone behavior has not this much of an impact), but that's another topic. I do understand why Microsoft used that approach.

To see the tombstones in your AD you can use LDP.exe in the support tools. Instructions for this are in the Windows 2000 Resource Kit in the Distributed Systems Guide: Searching for Deleted Objects

After a object is tombstoned it will remain in the directory for the tombstone-lifetime (60 or 180 days by default, see Active Directory Backup? Don't rush - you'll get more time). The tombstone-lifetime assures that the tombstone will be replicated to every DC, so that every DC knows that the object is deleted. This is the reason why you can not use a backup to restore Active Directory which is older than the tombstone-lifetime - it would reintroduce objects which have been deleted prior.

The garbage collection process one every domain controller takes care that tombstones which are older than the tombstone-lifetime are deleted permanently. The garbage-collection process runs by default every 12 hours on each DC. You can also configure other periods by modifying the garbageCollPeriod Attribute of the CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=yourdomain,DC=com Object. However this should not be necessary, and I encourage nobody to modify it.

However, the object is permanently deleted now, but the NTDS.dit-Databasefile which contains the Active Directory will not decrease it's size. Instead the new "Whitespace" will be used for new objects. The only possibility to release the Whitespace in the database is to perform a offline defragmentation using NTDSUtil in the Directory Services Restore Mode. See the Knowledgebase-Article (315131) HOW TO: Use Ntdsutil to Manage Active Directory Files from the Command Line in Windows 2000 on how to perform the offline defragmentation. However this is usually not necessary that often, but should definitely been done after upgrading a domain from Windows 2000 to Windows Server 2003. You may also want to do that after you deleted a lot of objects and the tombstone-lifetime is over.

You can check whenever the garbage collection process runs and how big the amount of whitespace in the database-file is. After you set the following registry-key on your domain controller (usually no need to set it on every DC since the size and whitespace should be about the same on every DC of the domain) you'll get events in the directory services eventlog when the garbage-collection is started, stopped and how much whitespace it detected in the NTDS.dit:

HKLM\System\CurrentControlSet\Services\NTDS\Diagnostics
"6 Garbage Collection" = 1 (reg_dword)

Be careful with the logging-levels underneath that key, they are by default all 0, and you can increase them up to 5 to increase the logging-level. However as higher as the level is you might get performance issues and the eventlogs are flooded with a lot of informations. Keep them at 0, and only increase them slightly if you have specific reasons.

OK, that's it for now, but I'll have some follow-ups on related topics soon.

Published Sat, Oct 29 2005 21:26 by Ulf B. Simon-Weidner

Filed under:

Comments

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Monday, November 14, 2005 7:38 PM

One thing to note....your dsquery example for the preserved attribute list for tombstones isn't quite complete. More complete would be...those are the attributes which the schema is specifying. If you take that list and add to it the hard coded list (we have a list, in the code, which is hard coded in....this way you can't accidentally tell us to remove something which we really need) then you will have the full list. :)

Ulf B. Simon-Weidner

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Monday, November 14, 2005 7:40 PM

Oh and on this item:
"There are additional attributes being kept in the tombstone, e.g. in Windows Server 2003 there is also the SID-History kept in the tombstone"

We actually added sidHistory as of WS2003 SP1 to that hard coded list I mentioned in the last post. We didn't change it in the schema as we didn't want a schema change associated with a service pack, but we wanted a more low-risk way of preserving this data.

Ulf B. Simon-Weidner

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Wednesday, April 19, 2006 5:18 PM

I need some guidance on and AD subject. If I delete a user account from Active Directory, I want to prevent the reuse of that user ID FOREVER. For example, my user ID is “adamc”. If my account is deleted, I wish that no other person be allowed to use the user ID “adamc” forever until the end of time. This is for a medical company that currently tags record updates in their medical with the AD user ID of the user making the update. This user ID needs to remain unique, even after users are deleted from AD.



I understand there is a tombstone lifetime for objects in AD, but I do not know if it can be set to infinity.



Is there a simple solution for this?

can you email me at praveenv78 at yahoo dot com

Praveen

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Tuesday, May 02, 2006 11:52 PM

Hello praveenv,
sorry - I've just seen your comment (for some reason the notification was off).
The tombstone-lifetime won't help you to fulfill your goal - you'd need to either keep those accounts in active directory but disable them, or create other objects with the same name which will prevent you from reusing the name. However other accounts are quite tricky - depending on which exact name-attributes you want to "lock".

I'd recommend to keep them, but disable them, and move them to a OU where they don't bother you. Or if you have a provisioning mechanism you can build it in there.

Ulf B. Simon-Weidner

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Friday, May 12, 2006 3:04 PM

This is great information, but I have a few questions on the subject. Is it possible to purge all records manually in the "Deleted Objects" container? Can you set the tombstone lifetime to 1 day and have the garbage collection wipe out all records? Finally, once a tombstoned record has been purged, can we be guaranteed that it is not recoverable through the database? We are possible spinning off a division and were thinking about allowing the division to keep the DC and we would just delete all objects not part of the division's OU, but would want to make sure they couldn't recover any deleted objects.

Thanks!!

Steve

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Tuesday, May 16, 2006 4:56 PM

Hi Steve,

very interesting question. There's a two-day limit in the number you can set on the tombstone-lifetime, and setting it pretty low is dangerous as well (you need to keep the tombstone until everything is replicated to any DC in the forest). Microsoft recommends at least a value between 30-40 days. Also be aware, that tombstone-lifetime is a pre-forest setting, and that you may not use backups which are older than the tombstone-lifetime. Also if you want them to keep a DC be aware that you have to split the whole forest, so they need a DC of every domain.

Actually in the tombstone there are not that many dangerous informations. You could change those informations before tombstoning (deleting) the objects, only the GUID and SIDs remain, and those are only dangerous if the networks have access to each other again, which is in no way supported or recommended in a split-forest-scenario. So they would not be able to get any important information out of the tombstones, and they will expire anyways. You can check the attributes which are remaining in the tombstone by querying attributes with the dsquery command provided in the post above. Then write a script which changes all those attributes you do not want to another value, and delete the object.

When splitting the forest make sure that all required services, DNS, GCs, FSMOs a.s.o. are adjusted, and don't forget to do a metadata-cleanup of all DCs on the other side.

I hope those thoughts are usefull for you.

Ulf B. Simon-Weidner

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Monday, May 22, 2006 6:40 PM

Thank you for your reply, those were helpful comments. The idea was to take their DC off the net, seize roles, delete EVERYTHING possible, adjust the tombstone so it all purged ASAP and then bring up a 2nd DC to replicate and transfer roles and take my original DC back. If the occasion arises, we will see what happens. Thanks again!
Steve

Steve

# delete without tombstone@ Friday, July 07, 2006 10:38 AM

i have a single DC, is there a posibility that the objects in Ad be deleted without being tombstoned.

thanks.

kini

# re: Some details about Tombstones, Garbage Collection and Whitespace in the AD DB@ Sunday, July 16, 2006 4:14 PM

Hello Kini,

No, that's not generally possible. AD will always create tombstones, and the minimum lifetime is 2 days. You could play around with the date and force garbage collection, but I woudn't do that.
However it's not bad to have tombstones. What's the reason why you don't want them. Actually I know companies who are using tombstones in their recovery plan instead of (authoritative) restores. And there are tools out there which rely on tombstones for AD-Recovery.
Let me know why you don't want them.

Ulf B. Simon-Weidner