It depends on the person, program, and state.
For example, if you're a US grad in CA, you *must* have it passed by the end of your PGY2 year or you cannot start PGY3... by law. If you're a foreign grad, you must have it passed by the end of your PGY3 year. But some programs (including the one I graduated from) require you to have taken it by the end of your PGY1 year as an internal policy.
OTOH, in some states, there's no requirement at all as long as you remain a trainee (thus on a teaching license), so there's people who graduate residency and start fellowship without passing it. This is generally a poor decision because many fellowship programs require you to have passed it before you apply (just to avoid licensing paperwork issues).
The latest I'd take it if my state didn't require me to is the start of PGY3 year, just to make sure I had a passing score by the time I needed an unrestricted license. And that's probably pushing it.
That said, my advice would be to take USMLE Step 3 (or COMLEX level 3 if you're a DO) sometime in the second half of your intern year. The reason? You should still be close enough to medical school that you can brush up on your peds/ob pretty easily, and you've gotten a lot more comfortable with adult medicine over the course of the year. Adult medicine (including basic psychiatry/mental health and basic surgical diseases, which you should be aware of anyway) makes up the bulk of the test, so you'll have a bit of an advantage there. Buckling down and reviewing the basics again allows you to review any of your own weaknesses.
And for gods sake, don't waste your vacation studying/taking it. The test REALLY doesn't matter and a few weeks of part-time studying while on an elective rotation (you should have at least one sometime in the second half of intern year) is more than enough. On my PGY1 EM rotation, I got through <2/3 of uworld, flipped through my step 2 study book and took the test to pass with plenty of room to spare. And I'm nowhere near a rockstar on the steps.