Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

How would you manage PostgreSQL configuration for 100 clusters of different sizes in a consistent and reviewable way?

I would define a few instance classes, compute each class's settings from its CPU, memory and storage in a template kept in version control, and apply them with automation such as Ansible, Terraform parameter groups or a Kubernetes operator, never by hand. Changes go through review, canary clusters and an easy rollback, settings that need a restart are handled separately using pending_restart in pg_settings, and a drift check compares every cluster's live pg_settings with the source of truth. Per-role and per-database overrides are allowed, but each one is written down with its reason.

Why this question is asked

With three clusters, people can remember why each setting is what it is. With 100 clusters of different sizes, nobody can, and over a few years every cluster drifts into its own mix of hand edits, emergency fixes and forgotten experiments. Then an incident on one cluster cannot be compared with another, and an upgrade breaks because of a setting nobody knew about. Interviewers ask this design question to see whether we can make configuration consistent, reviewable and safe to change at scale. In this answer, we will recap where PostgreSQL settings come from, build templates per instance class, design the change process, handle restart-only settings, detect drift, and keep overrides under control.

1A Quick Recap: Where a Setting's Value Comes From

A PostgreSQL setting can be set in several places, and the last one wins. The base is postgresql.conf. ALTER SYSTEM writes to postgresql.auto.conf, which is read after it. Then a database or a role can override a setting with ALTER DATABASE ... SET or ALTER ROLE ... SET, and finally a session can change it with SET. The view pg_settings shows the effective value and, in its source column, where it came from.

Settings also differ in how they take effect, shown in the context column. Some, with context postmaster, such as shared_buffers and max_connections, need a server restart. Others, with context sighup, take effect on a configuration reload. Many can be changed per session. Any design has to treat these groups differently.

SQL
SELECT name, setting, source, context, pending_restart
FROM pg_settings WHERE name IN ('shared_buffers', 'work_mem', 'max_connections');
-- max_connections | 300 | configuration file | postmaster | t (changed, restart still needed)
-- shared_buffers | 2097152 | configuration file | postmaster | f
-- work_mem | 32768 | configuration file | user | f

2Templates per Instance Class

Instead of tuning 100 clusters by hand, we define a small number of instance classes, for example small (4 vCPU, 16 GB), medium (8 vCPU, 64 GB) and large (32 vCPU, 256 GB), each with SSD storage. A template computes settings from the class: shared_buffers as 25 percent of memory, effective_cache_size as 70 percent, max_worker_processes and the parallel worker settings from the CPU count, and random_page_cost and effective_io_concurrency from the storage type. Settings that should be the same everywhere, such as log formats, statement timeouts for sessions without one, and autovacuum logging, are a shared base.

The templates live in version control next to the automation that applies them. On our own servers that might be Ansible writing postgresql.conf; on a cloud provider it is Terraform managing parameter groups; on Kubernetes it is an operator such as CloudNativePG reading the cluster resource. In every case, the repository is the source of truth, and a person reading it can see every value and why.

YAML
# classes/medium.yaml (8 vCPU, 64 GB, SSD)
memory_gb: 64
shared_buffers: "{{ (memory_gb * 0.25) | int }}GB" # 16GB
effective_cache_size: "{{ (memory_gb * 0.70) | int }}GB" # 44GB
max_parallel_workers: 8
random_page_cost: 1.1
# overrides with a reason
work_mem: 32MB # raised from 16MB in change 412: reporting spills
Step throughHow a cluster gets its configuration
  1. Shared baselogging, timeouts, autovacuum logging: the same everywhere
  2. Instance classmemory, CPU and storage formulas: small, medium, large
  3. Cluster overridesrare, each with a reason and a change id
  4. Role and database overridesALTER ROLE ... SET, documented in the repo
  5. Live serverpg_settings, compared with the repo by the drift check

5 layers, from the top down. Step through them one at a time.

3A Change Process That Is Safe at Scale

Every change is a pull request that changes the template and records why: the problem, the measurement and the expected effect. A reviewer from the database team approves it. The automation then rolls it out in waves: first to a few canary clusters, for example one of each class in staging and two low-risk production clusters, then to 10 percent of the fleet, then to the rest. Between waves we watch latency, memory, checkpoint frequency and error rates for a day.

Rollback must be as easy as the change itself: revert the pull request and run the same automation. Because every value lives in the repository, we never ask what the setting was before, we look at the history.

Step throughRolling out a configuration change
  1. Pull request with reason and measurementreviewed by the database team
  2. Apply to canary clustersone per class plus two low-risk ones
  3. Metrics healthy after a day?
    YesRoll out to 10 percent, then allNoRevert the pull request
  4. Needs a restart?
    YesSchedule restarts per cluster windowNoReload and finish
  5. Drift check confirms every clusterpending_restart is false everywhere

5 steps in order. Play them, or step through them one at a time.

4Handling Settings That Need a Restart

Reloadable settings can roll out in minutes. Restart settings cannot, because a restart of a primary is a short outage, or a planned switchover in a high availability setup. So the automation writes the new value and reloads, and PostgreSQL then marks the setting with pending_restart = true in pg_settings. The value is in the file but not yet active.

We report pending_restart across the fleet, and each cluster's owner restarts within its maintenance window, ideally by switching over to a standby first. The drift check treats a pending restart as its own state, so we always know how many clusters run the new value and how many only have it on disk.

5Detecting Drift

Even with automation, drift happens: someone runs ALTER SYSTEM during an incident, or a cloud console change bypasses Terraform. So a daily job reads pg_settings from every cluster, keeps only values whose source is not default, and compares them with what the template says. Any difference creates a ticket for the owner: either put the change into the repository with a reason, or let the automation put the value back.

SQL
SELECT name, setting, unit, source
FROM pg_settings
WHERE source NOT IN ('default', 'override')
ORDER BY name;
-- compared, setting by setting, with the rendered template for this cluster

PostgreSQL 17 added the setting allow_alter_system, which can turn off ALTER SYSTEM on clusters where the automation owns the files; check your version. That removes one common source of drift.

6Keeping Role and Database Overrides Honest

Some workloads really do need different values, such as a reporting role with a larger work_mem or a batch database with a longer statement timeout. ALTER ROLE ... SET and ALTER DATABASE ... SET are the right tools, because they limit the change to that workload instead of the whole cluster. But they are stored in the catalog table pg_db_role_setting, not in a file, so they are easy to forget. We manage them in the same repository and apply them with the same automation, and the drift check reads pg_db_role_setting as well.

SQL
SELECT r.rolname, s.setconfig
FROM pg_db_role_setting s JOIN pg_roles r ON r.oid = s.setrole;
-- reporting | {work_mem=512MB,statement_timeout=10min}

7Follow-up questions

Why not let each team tune its own cluster?

Teams can propose changes, but through the same repository and review. Free hand tuning makes clusters impossible to compare and means the knowledge leaves with the person. The templates give a good default for everyone, and documented overrides cover real differences.

How do you choose the formulas in the templates?

From measurements on representative clusters of each class: hit ratios, temporary file usage, checkpoint frequency and memory headroom. The formulas start from common guidance, such as 25 percent of memory for shared_buffers, and are adjusted when a measured problem shows they are wrong for a class.

What about managed services where some settings cannot be changed?

The template records which settings each platform allows, and the automation only renders those. The drift check still compares what can be read, so the process stays the same across self-managed and managed clusters.

8Conclusion

In this answer, we built configuration management for 100 clusters around templates per instance class, computed from CPU, memory and storage, kept in version control and applied by automation. Changes go through review, canaries and waves with an easy revert; restart-only settings are tracked through pending_restart in pg_settings and applied in maintenance windows; a daily drift check compares live settings with the repository; and role and database overrides are managed and documented the same way.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by defining a few instance classes, say small, medium and large, and put the configuration in version control as templates: a shared base for things like logging and timeouts, and formulas per class from CPU, memory and storage, such as shared_buffers at a quarter of memory and parallel workers from the CPU count.

Then, if they want more

Automation applies it, Ansible for our own servers, Terraform parameter groups on the cloud or an operator on Kubernetes, so nobody edits a server by hand. Every change is a pull request with the reason and the measurement behind it, reviewed by the database team, then rolled out to canary clusters, then in waves, with rollback being a revert.

I would treat restart settings like shared_buffers and max_connections separately: the automation writes and reloads, pg_settings shows pending_restart, and owners restart in their windows, ideally through a switchover.

A daily drift job reads pg_settings and pg_db_role_setting from every cluster and compares non-default values with the rendered template, and anything different becomes a ticket to either document it or revert it; on PostgreSQL 17 I can also turn off ALTER SYSTEM.

Role and database overrides, like a larger work_mem for reporting, are fine, but they live in the same repository with a reason.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 17
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
PostgreSQL documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How would you manage PostgreSQL configuration for 100 clusters of different sizes in a...": https://scrivio-interview-library.netlify.app/databases/postgresql/07e77b4c3e/