PostgreSQL provides debug parameters for exactly this.
See the enable_
params in the docs.
Please don't use them in production; it might seem like a good idea at the time, but those settings won't adapt as the data changes and grows, so what starts out as a performance win will probably become a problem later.