I'd like to have visited Moscow while I was in Russia, but I didn't manage to.
Is "to have visited" OK here?
I'd like to have visited Moscow while I was in Russia, but I didn't manage to.
Is "to have visited" OK here?
Yes to "to have visited". It is correct and frequently used in English by general speakers in any situation (i.e. spoken or written, formal or informal, whether the speaker is highly educated or not).
The phrase, "to have visited" functions as a noun (noun phrase) in the sentence, and if you want to express that it (to have visited) is something you would like (if it had happened), you can either say it in the present as you have in your question, "I'd [I would] like to have visited ... "
Or, (as Michael Rybkin and Mike-SMT have said) you can express your liking as something you would have felt in the past (if the visit had happened): " I would have liked to have visited ..."
The difference in meaning is negligible ("I would currently like a hypothetical situation of the past" vs. "I would have liked the same situation at the time it happened, if it had). The second construction using "would have liked to have visited" is a little wordy and cumbersome, and many speakers would rather express the idea using the phrase in your question ["I'd like to have visited"], but both are correct.
Another way to say this is :
I wish I had visited Moscow while I was in Russia, but I didn't manage to.
Is "to have visited" OK here?
I think in this sentence it does not fit well.
The words "I'd like to have" is more of a present/future tense. Used more commonly when asking for something in the moment or when thinking on the future. "I'd like to have the special" or "I'd like to have a house someday".
When speaking in the past tense you need to structure your sentence to reflect the same.
"I would have liked to visit Moscow when I was in Russia."