Hold the knot.
A male dog expects to knot very soon after a few humps. The initial humping may take as little as 10s and then the knot swells enough to prevent further movement. But for this to happen the female dog has to use the vaginal ring muscle to hold the knot.
Human females do not have this muscle. The only thing that the human body has somewhat similar to this is the anal sphincter which is not powerful enough anyway to hold a tie.
Use your fingers and palm to squeeze behind the knot and provide pulsating pressure until he wants to dismount. Do not hold the legs, tail or any other part of the dog.
After the knot swells he will want to jump off and turn around butt to butt, that is normal and in natural circumstances the female dog is strong enough to hold the knot during this and after this. Human orifices are not, so use your hand.
Dogs are not designed to mount and stay in this position, they naturally want to turn butt to butt.
Go watch some dog mating on youtube to get the idea.