Know which side one`s bread is buttered on

To know who can help you and therefore try to please him or her, to know what is good for oneself.

The man is careful not to make his boss angry. He knows which side his bread is buttered on.