Most of the bacteria you might encounter in potting soil and compost is of the beneficial variety, part of a community of microorganisms that helps to make nutrients available to plants and contributes to good soil structure. Unfortunately, very rarely some harmful bacteria can be lurking in there as well.
There have been reports from the U.S., Britain, and Australia of people contacting the respiratory ailment called Legionnaire's disease from Legionella bacteria found in potting soils. While this has happened only rarely (Legionnaire's disease is most often transmitted by bacteria found in certain types of water storage systems) and people with compromised immune systems or the elderly are most at risk, it's a good idea to follow some commonsense precautions suggested by the Royal Horticultural Society (RHS) in Britain when working with potting soil. It's not clear if there is a difference in risk between soilless mixes and those containing soil; in either case, the following suggestions below are a good idea.
First of all, wear gloves when handling soil or compost. Wet mixes down to decrease the amount of air-borne particles. Consider wearing a dust mask when opening or using potting mixes. Don't store bags of potting mix in the sun since the increased temperature can promote bacterial growth. Wash your hands after using potting soil. Be aware of the symptoms of Legionnaire's disease: shortness of breath, achy muscles, fever and chills.