ReinDBby Bandlei

11. Settings: match the workload, then keep it there

Brett Rosenblatt · Database tuning guide v1.3 · PDF

Configuration rarely turns a bad design into a good one, but a bad setting can cripple a good design. Defaults are written for a generic machine and a generic workload, and they are often years behind the hardware you run on. This chapter covers how to match settings to the workload, the kinds of settings that matter in every engine (with each engine's own in the notes), and how to stop them drifting afterwards.

11.1Principles

  1. Know the workload class first. OLTP: many short transactions, a small hot working set, high concurrency, commit latency matters. Analytics: large scans, big sorts and hashes, parallelism, memory per query. Mixed: protect the OLTP side from the reports, with replicas or resource governance.
  2. Judge each setting against the right moment. Caches are sized for the average working set. Per-operation memory, connection limits and log sizes are sized for the peak. Judging a peak setting against an average day is how systems fall over at month end.
  3. Change one setting at a time, and measure at the same hour on the following days.
  4. Prefer scoped overrides to global changes. If one report needs more sort memory, give it to that report, not to every session.
  5. Use the engine's own advice (advisory views, checkpoint logs, wait statistics) before rules of thumb from the internet.
  6. On managed services, change the provider's parameter settings, not the instance. Some parameters are static and need a reboot, and some are controlled by the provider (see the cloud note in section 11.3).

11.2The settings that matter, by category

The names differ, but every engine asks you to make the same decisions:

CategoryWhat you decideJudge against
Data cacheHow much memory holds data and index pagesAverage
Memory per operationSort and hash memory for each step of a query, multiplied by how many run at oncePeak
ConnectionsThe maximum number of sessions, and whether a pool sits in frontPeak
Log and checkpoint sizingHow much log space absorbs write bursts before the engine must flush or switchPeak
DurabilityWhether each commit waits for its log write to reach storageNot load-dependent
ParallelismWhen a query goes parallel, and how many workers it may usePeak
Optimizer cost model and featuresStorage cost assumptions, the optimizer version and adaptive featuresNot load-dependent
Background workStatistics gathering, cleanup and flushing ratesPeak
Temporary spaceHow much memory internal temporary results get before they spill, and where they spill toPeak
Timeouts and limitsStatement and idle-transaction timeouts, and caps on runaway sessionsPeak
InstrumentationWhat the engine measures and keeps (Chapter 2)Not load-dependent

11.3Starting points by engine

The engine notes list the settings that matter most in each engine, with a starting point for each and the moment to judge it against. Starting points are where you begin measuring, not where you stop.

11.4Scoped overrides for the outliers

Give the outliers what they need, and only them. Every engine lets you change settings for a narrower scope than the whole server: a user or role, a session or transaction, or a single statement.

For whole workloads, use resource governance where the engine offers it, so reporting users can't starve the transactional ones of CPU, parallelism or memory. Check which editions include it for your version.

11.5Keeping it there

Settings drift. A parameter changed during an incident never gets changed back, an upgrade brings new defaults, an instance is resized and memory settings stay where they were. Treat configuration like code.

  • Keep the approved configuration in version control: parameter files, parameter groups (through Terraform or CloudFormation), sp_configure and database scoped configuration scripts.
  • Compare live settings against it on a schedule, and alert on differences.
  • Re-evaluate after every version upgrade, instance resize, major workload change or doubling of data.
  • Record every change with the reason, the person, and the before and after values.

Each engine can list what has been changed from its defaults. Save the output and compare it over time:

This is one chapter of the free database tuning guide for PostgreSQL, MySQL, SQL Server and Oracle. Download the whole guide as a PDF.