I am running SQL Server 2005 SP2 CU3, and have noticed this from time to time. We periodically restore production databases back to our test environment and do so by first disabling publishing and distribution on the test publication servers. We then restore the databases from production, and then re-run the replication script created from "Generate Scripts". After this, we restart the Snapshot agents on all our publications which uses one distribution database and server to distribute to various subscriber servers, all of which are not updateable subscriptions.
Every once in a while I notice that although Publisher To Distributor History and Distributor To Subscriber History have caught-up and report "No replicated transactions are available", the Undistributed Commands shows a number of commands still in the distribution database waiting to be applied to one or more subscriptions. Sometimes 1 subscription will show 0 commands waiting, while another subscription to the same publication shows more. Even if I wait it out, I notice no movement on the commands.
If I run sp_browsereplcmds I can see a few updates, index creation commands, and a bunch of snapshot scripts waiting to be applied. However, if I check these out, I notice that the tables involved are in synch with the publisher with no need of these commands to run.
What is then happening? I've tried to run the distribution agent clean-up job but this accomplishes nothing. Usually, only after 3 days will the clean-up expired subscriptions job run and remove these "bad commands".
How can I ensure that the undistributed commands are "clean" so that after re-establishing replication, I can ensure a zero value?
Any help would be appreciated.