postgresql duplicate key violates unique constraint

Robby Russell wrote in post #72333:

SELECT MAX(id) FROM entities;
Then run...
This should be higher than the last result.
If it's not higher... run this to try and fix it. (run a quick
pg_dump first...)
SELECT setval('entities_id_seq', (SELECT MAX(id) FROM entities)+1);
reload your app...and see if its still happening.

I have the same problem but I don't know how to solve it since I can't
relate the solution here (names of tables, etc.) to the data given by
the OP. How do you know you need to SELECT MAX(id) FROM entities, or
SELECT setval('entities_id_seq', (SELECT MAX(id) FROM entities)+1);
with the information given by the OP? I can't see the relation and
therefore I have no clue how I can solve my problem.