DEV Community

Aitzaz Mumtaz Khan
Aitzaz Mumtaz Khan

Posted on • Originally published at Medium on

When Indexes & Performance Tuning don’t fix Slow queries in Postgres

A tale of resolving a blocked query by fixing Postgres disk usage via Vacuum, Analyse and 2 minutes break. And it might save you a few days!

An index or server params tuning may not always fix a slow or even blocked query. Postgres table bloat may cause such issues and Vacuum Analyse can fix it.

...

Indexes are not a silver bullet!

A team member suggested a new index but I knew that an index won’t help due to low cardinality of the column used in the query and nature of the data. However, he tried that but the full table scan was still there.

BTW this happens when the query optimizer decides that reading table data pages sequentially (full table scan) is faster than reading pages in random order (which is done when an index is used). Normally index is skipped by query optimizer if query covers more than 20–30% table data search.

...

Continue reading on Medium »

Top comments (0)