The smell of rain could be pleasant or have quite the stench. No matter if one finds the odor pleasing or not, how the smell is formed does not change.
Petrichor, in the ground, is decomposing matter with bacteria. That leads to geosmin, a form of an alcohol, which is a result from the decomposing organic product. These elements are in the ground, and once it starts to rain the scent is released from the ground and spreads outward.
That is why a heavy rainfall can alert those down wind that rain is on the way. The odor is most noticeable after dry periods of weather.
Now one may be thinking that the ground is what causes the scent rather than the rain, and that is correct.