The problem with answering this question accurately is that the only true definition of a postdoc is "job you get after the PhD." At one one end you have externally-funded postdocs (e.g. NSF) which act more like mini-professorships, in which you are the PI, NSF pays your salary, and the lab (or research group) or university just gives you space in exchange for the overhead money (= the so-called "indirect costs".) At the other end, you have glorified technical positions, in which you are no more than a lab tech, programmer, teacher, whatever, with the title of "postdoc" as an excuse to pay you less than the job is actually worth. And everything in the middle.
Then there's the issue that "applying for a postdoc" is not as simple as looking up the job postings and filling out applications. For example, some PIs have pockets of unencumbered/discretionary money which they can use to fund a postdoc if a great candidate happens to come along. Other people find postdocs by writing grants with established PIs, writing a postdoc position as part of the grant, with the agreement that they'll be that postdoc if the grant lands. Other postoc positions are, like the one I described above, something you get directly from a funding agency after writing a grant application. Yet other postdocs are the type where a PI writes a grant, gets the money, then advertises the position, reviews applications, and hires the first good candidate. And so on.
So when do you apply for postdocs? In a sense, you should start preparing for a postdoc the day you start your PhD, making contacts with potential PIs, visiting other research groups, giving talks at conferences so people have you on their minds when good opportunities show up, growing a list of collaborators (all potential postdoc advisors), etc. The closer you get to the end of your PhD, the more time and effort you should spend tapping into your network, and yes, sending applications out to advertised positions. It really does not matter how you get a postdoc, it only matters that you get one.
When applying to advertised opportunities, 5 months feels to me close to the sweet spot between too early and too late. Some people will reject your application right away, as they only want people who already have the PhD at hand. Oh well, so be it. But other potential employers will welcome your early application and if they like you, save the position for you until you defend your thesis. I've seen in happen many times. But you can't tell who's who from just reading the job postings, so might as well apply to all the positions to which you are qualified.