A fence usually has three components; posts, rails and palings. The posts are installed in concrete and give a fence its strength, so they are likely a big part of the issue if your fence is leaning.
If your fence is falling over completely, it may mean the posts have rotted out, in which case they would likely need to be replaced.
If they are simply leaning, then there may be ways to re-secure them. - JacobZ
The cheapest solution to fix a leaning fence is to excavate around the leaning post and re-concrete it while it is held in the correct upright position. This repair requires access to both sides of the fence and is only suitable if the post is still structurally sound.
If the post has rotted at ground level or the timber is no longer sound, replacing the post is the better long-term solution. - Jewelleryrescue
Leaving rotted posts and their existing footings in place and simply pouring new concrete around them is not a reliable long-term repair. New concrete doesn't structurally bond to old concrete in a way that restores its strength, especially when the original footing contains a post that has already failed. The most durable solution is to remove the failed post and footing completely, install a new post in fresh concrete, then reconnect the fence rails and palings. - MitchellMc
If it’s an older leaning timber fence, you're likely dealing with a combination of worn or rotting posts, brittle rails and weathered palings. Temporary bracing can help push the fence back into position while repairs are carried out, but if the existing rails are too brittle to take fasteners, it's often better to replace them rather than try to patch them.
If the fence posts themselves are rotting at the base or feel loose when pushed, the issue may go deeper, and in that case, you might be better off replacing the affected section.
For a DIYer with some basic tools and patience, this repair is doable. However, if you find multiple posts are failing or the fence continues to lean despite reinforcement, it may be more cost-effective and safer to call in a local fencing contractor for a partial rebuild. – EricL
Temporary supports such as Star pickets won't support the fence at all, they will bend under the weight. Posts need to be at least one-third of their length in the ground. While digging post holes isn't an easy job, you can hire a post hole digger or use pincer hole diggers. - Nailbag