brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: EXPLAIN (SETTINGS) lists the planner settings that differ from the defaults

Performance
~/tips/tip-postgresql-explain-settings

EXPLAIN (SETTINGS) SELECT * FROM my_table WHERE id = 42;

Adds a line to the plan with every planner-related setting that has a non-default value.

When the same query gets a different plan on two servers, a changed setting is high on my list of suspects. EXPLAIN can show them in the plan itself.

SET random_page_cost = 1.1;
EXPLAIN (SETTINGS) SELECT * FROM my_table WHERE id = 42;

With SETTINGS on, the plan gets an extra Settings: line. The docs say it includes the options that affect query planning with a value different from the built-in default. So here you would see random_page_cost in the output, and nothing at all if everything is at its default. The option defaults to false.

That makes plans easier to compare when you paste them into a ticket or send them to a colleague. The settings travel with the plan, so nobody has to guess whether work_mem or enable_seqscan was changed on that session.

The caveat is the word planning: settings that don’t influence the planner are not listed, and neither are defaults. It is also not a full dump of your configuration. For that, query the pg_settings view and check the source column. You can combine it with other options, for example EXPLAIN (ANALYZE, BUFFERS, SETTINGS).

Further reading: EXPLAIN

More Performance tips sudo apt install hyperfine sudo apt install fio dtparam=fan_temp0=55000 sudo cpufreq-set -g powersave Settings > Media Management > File Management > Analyze video files All Performance tips (9) All topics

Link