I am answering under the assumption you are referring to the anal glands.
Anal glands are two small glands located within and on either side of the anus. They are filled with a brown substance that has a very foul, musky smell. The glands are expressed when dogs urinate, defecate or mark their territory. When dogs meet one another they also raise their tails and excrete a small amount of substance.
Dog anal glands are frequently impacted and the problem usually occurs in smaller breeds. Scooting, licking and biting the anal area may indicate compaction or infection. Digital inspection by a qualified veterinarian is indicated, and antibiotic treatment may be necessary if infection is present. Some complications from anal gland compaction, infection, or abcess may occur, including: fistulous tracts leading from the infected sacs and rupturing through the skin.
The problem is associated with poor diet and usually with dogs fed on a low quality commercial pet food. The bulk (grains and other cheap filler) create a stool that is too soft to effectively express the anal glands.
Also, tapeworms will cause a blockage. A pet gets tapeworms from eating fleas. If you see small white rice looking things on his poo, take him to the vet and they can give a wormer specifically for this issue. Over the counter wormers do not treat tapeworms ! They may say they do but there are different types of tapes and the most common can not be treated with over the counter products.