can you avoid that by tweaking the cost factors in postgres config?
Once you understand what is going on, it makes perfect sense. It's just getting there that is the trick.
If I were to skew more of my development cycles to dedicated database management, I think incorporating analytic tools like postgresqltuner would be a must. Although I would probably cross-reference any suggestions with my past experience and dig into Postgres docs on the specific parameters it highlights. Regardless I suspect it would be a valuable source of additional context.