I've often wondered whether this expression has its origins in spanking. I did a quick check on the internet today and nobody seems completely sure. There are at least five possible origins.
1. Coastguards used to put nearly drowned people over a barrel to get water out of their lungs. The significance for the saying is that under those circumstances your life was completely in the coastguard's hands.
2. A practice of punishing someone by tying them to a barrel and rolling the barrel (!)
3. A practice of threshing rice by holding it over a barrel.
4. A 19th century practice of tying prisoners over a barrel before flogging them. This may have been a flogging on the back rather than the bottom, but this verse from 1869 makes a definite connection with spanking:
I'd like to be a school-marm,
And with the school-marms stand,
With a bad boy over a barrel
And with a spanker in my hand
(Also an unusual use of "spanker". Could it mean paddle?)
5. The naval practice of making midshipmen bend over the barrel of a cannon for punishment as
here, though this is considered to be an unlikely origin.
Any thoughts?