Luke's adoptive parents, Owen and Beru, inherit Luke from Obi-Wan after Padme gives birth to him. Obi Wan tells them that the father is Anakin, and Owen decides to raise his brother-in-law's child.
Meanwhile, Senator Organa, a member of the Imperial Senate, has Captain Antilles conceal Anakin's possession of R2 and Padmé's 3PO, which belonged to Anakin. Obi-Wan and Yoda warned her of the danger she would face if the two droids were discovered by Vader. Obi-Wan was vaguely aware of the fact that the two droids had visited the Lars' house three years earlier, and Padme must have told him. He must have heard about it from Padme.
Padme was also concerned that the two droids might be discovered by Vader. So Obi-Wan asked Senator Organa to have the Antilles erase 3PO's memories, but not R2's, since he's not as chatty as 3PO.
Twenty-three years later, the two droids accidentally return to the Lars' home. 3PO had been seen by the Lars before, but they were unrecognizable as the same droid because Padme had gilded their appearance and they were noticeably dirty. Even if we did, we couldn't be sure that it was 3PO, because the memory of the droid had been wiped out; R2 was not remembered, and his appearance was unchanged! Fortunately, however, it had not been seen much by the Lars 23 years ago. In other words, Owen himself, who bought it from Java, had no idea that R2 had any memory of Luke's parents' past. And Luke, of course. If it weren't for the message from Leia to Benkenobi, Luke might have erased all of R2's memories as instructed by Owen.
R2 himself remembered Anakin and Padme's past, but when he met Luke, he did not recognize Luke as the child of Anakin and Padme. But it is true that I do remember. Considering this, Obi-Wan tells Luke to replay R2's memories in the holo if he wants to see his real parents. At this, Luke is astonished.
"R2, you not only served my sister, but my mother and father as well!
I'm so glad I didn't erase the memory when we first met. If Mom had shown you to Uncle Owen often, he would have been surprised to see you guys again."