autovacuum is not working
PostgreSQL-only checks require some information about which rows are "visible" for current transactions, i.e. not deleted versions of updated rows, not uncommitted inserts or new versions of updates.
This information is stored in a "visibility map".
Visibility mapping is supported by VACUUM , usually in the background by auto-vacuum workers.
If autovacuum does not support writing, or if autovacuum is disabled, then scanning only by index will probably not be used, because PostgreSQL will see that there is no data on the visibility map for a sufficient number of tables.
Enable autodiscovery. Then manually VACUUM table to get its relevance immediately.
BTW, in addition to visibility map information, auto VACUUM can also record hint information, which can quickly insert / update data to SELECT .
Autovacuum also maintains statistics on tables that are vital to efficient query planning. Disabling it will cause the scheduler to use more outdated information.
It is also crucial to prevent a problem called transactional authentication, which is an abnormal condition that can cause the entire database to crash until the time-consuming whole VACUUM table is executed.
Do not turn off autovacuum .
As for why he sometimes uses validation only for the index, and sometimes not, a few possibilities:
The current random_page_cost parameter random_page_cost you think that random I / O will be slower than it actually is, so it tries to complicate it.
Table statistics, especially limit values, are out of date. Thus, he does not understand that there is a good chance that the estimated value will be quickly detected in a scan of only the index,
The visibility map is out of date, so he believes that scanning only for the index will find too many values ββthat require heap checking to do it slower than other methods, especially if he believes that the proportion of values ββthat can be found is high.
Most of these problems are resolved, leaving only auto-vacuum. In fact, on frequently joined tables, you should set autovacuum to run much more often than the default value so that it updates the limit statistics more. (This helps to work with PostgreSQL scheduler problems with tables where the most frequently requested data is the last insert with an incremental identifier or timestamp, which means that the most desirable values ββare never found in the table histograms and statistics).
Turn the auto vacuum on , then turn it on.