Sambovi is correct. Tail wagging is a sign of emotional state, generally excitement.
An excited dog is not a good thing. It can send your dog into a red zone, positive or negative. The main reason it’s bad is because the dog is so focused that it’s unresponsive and therefore difficult to control.
Also, in the dog world, excitement sits very close to aggression. A rescue dog is very sensitive to emotional changes because it’s life probably rested on a few seconds decisions to survive.
Training is the solution. That includes you and the dog.
You: I expect you’ve started stressing about it, especially when you’re about to come across the situation. The dog will feel that before you realise. It will feel that you’re suddenly tensing through the lead, it will “smell” the chemicals your body produces to face the situation. (After all, dog can smell cancer!)
Can dogs smell fear
Your solution is to relax and get over the problem. Notice the potential problem but react calmly, relaxed but also be in charge of the situation in a calm assertive manner.
The dog: it doesn’t know any better. That’s the only way it knows to react.
It needs to be trained. The important point here is to notice the signs of excitement before it gets to the red zone so you can have control. There, you can stop and redirect the behaviour.
A very assertive “no”, a sideways tug on the lead(don’t hurt the dog!), a disapproving noise. Enforce your command. Dogs will switch in a microseconds.
Food is another distraction. Keep your dog on a lead when passing another dog whilst it smells yummy food. Only give the food is you get the required calm behaviour or if you see an improvement to guide the dog in the right direction.
Do not let the dog off the lead when excited, you’re encouraging the behaviour.
Work in small steps and practise a lot. If you know regular dog walkers, ask them if you can enlist their help to practise. There are a few videos from Cesar Milan for that.
Rescue dogs generally need a lot of training to be able to live well in their new found environment. It is a lot of hard work but in my experience well worth it! I have trained many rescues considered lost cases and I will always have them because it’s so rewarding for the dog and the human.
The best training model in my opinion is from this guy: