These sort of problems can occur (for example) when very complicated joins are performed, or when unstructured data is being used as part of a join, as these tend to lead to poor estimates of the number of rows that the different parts of the query will yeild.
Relevant docs here:
https://www.postgresql.org/docs/current/static/runtime-confi...
It's not too abnormal. Sometimes you know the structure of your data better than the database's internal summary does, so you just give it a nudge in the right direction.
There are also statistics that can be tweaked on vacuum analyze to improve the accuracy of the planner.
A good start to understanding how these work in an optimization context is: http://blog.2ndquadrant.com/postgresql-ctes-are-optimization...