Postgresql performance problem and solution

Usually postgresql performance issue is because of statistics data out of date. The planner may think one table is small but actually its huge.

Diagnosis

For example:

Solution

TODO

To maintain a health database, should put slow query alert there, and setup auto vacuum.