All dogs have anal glands that secrete odorous fluids when they defecate, coating the feces and effectively personalizing it. The anal glands allow dogs to identify other dogs by smell. This is why dogs greet each other by sniffing their backsides -- the anal gland odor helps them identify one another. Defecation isn't the only time when the glands emit their pungent secretions, though.
Anal Gland Release
Generally, dogs can't choose when they empty their anal sacs; it simply happens naturally when they defecate. If your dog becomes unexpectedly excited or stressed, his anal sac may release spontaneously and uncontrollably, emitting a foul smell that is distinguishable from flatulence by its fishy overtone. If your dog seems to emit this smell on a daily basis, take him to your veterinarian -- this could indicate that his anal sac has become impacted and needs to be manually drained. It's common in smaller dogs; scooting on his rump is an indicator.