Parameters
You can set PostgreSQL parameters at several levels with different scopes and priorities. Pigsty supports four levels, from global to local:
| Level | Scope | Configuration Method | Storage Location |
|---|---|---|---|
| Cluster | All instances in cluster | Patroni DCS / Tuning Templates | etcd + postgresql.conf |
| Instance | Single PG instance | pg_parameters / ALTER SYSTEM | postgresql.auto.conf |
| Database | All sessions in a DB | pg_databases[].parameters | pg_db_role_setting |
| User | All sessions of a user | pg_users[].parameters | pg_db_role_setting |
Priority from low to high: Cluster < Instance < Database < User < Session (SET command).
Higher priority settings override lower ones.
For complete PostgreSQL parameter documentation, see PostgreSQL Docs: Server Configuration.
Cluster Level
Cluster-level parameters apply to every primary and replica in a PostgreSQL cluster. Pigsty manages them through Patroni and stores them in DCS, which is etcd by default.
Pigsty provides four Patroni tuning templates for different workloads.
Select one with pg_conf:
| Template | Use Case | Characteristics |
|---|---|---|
oltp.yml | OLTP transactions | Low latency, high concurrency (default) |
olap.yml | OLAP analytics | Large queries, high throughput |
crit.yml | Critical/Financial | Max durability, safety over perf |
tiny.yml | Tiny instances | Resource-constrained, dev/test |
Template files are in roles/pgsql/templates/.
They calculate parameter values from the hardware specifications.
During cluster initialization, Pigsty generates /etc/patroni/patroni.yml from the template.
See Tuning Templates.
Before cluster creation, adjust the templates to change initial parameters. After initialization, change parameters through Patroni configuration management.
Patroni DCS Config
Patroni stores cluster configuration in DCS, which is etcd by default. This keeps all members configured consistently.
Storage Structure:
Rendering Flow:
- Init: Template (e.g.,
oltp.yml) rendered via Jinja2 to/etc/patroni/patroni.yml - Start: Patroni reads local config, writes PostgreSQL parameters to DCS
- Runtime: Patroni periodically syncs DCS config to local PostgreSQL
Local Cache:
Each Patroni instance caches DCS config locally at /pg/conf/<instance>.yml:
- On start: Load from DCS, cache locally
- Runtime: Periodically sync DCS to local cache
- DCS unavailable: Continue with local cache (no failover possible)
Config File Hierarchy
Patroni renders DCS config to local PostgreSQL config files:
Load Order (priority low to high):
postgresql.conf: Dynamically generated by Patroni with DCS cluster paramspostgresql.base.conf: Loaded viainclude, static base configpostgresql.auto.conf: Auto-loaded by PostgreSQL, instance overrides
Since postgresql.auto.conf loads last, its parameters override earlier files.
Instance Level
Instance-level parameters apply to one PostgreSQL instance and override cluster-level configuration.
Pigsty writes them to postgresql.auto.conf.
This file loads last and can override any cluster parameter.
Use instance parameters for settings such as:
- Set
hot_standby_feedback = onon replicas - Adjust
work_memormaintenance_work_memfor specific instances - Set
recovery_min_apply_delayfor delayed replicas
Using pg_parameters
In Pigsty config, use pg_parameters to define instance-level parameters:
Run ./pgsql.yml -l <cls> -t pg_param to write these parameters to postgresql.auto.conf.
Override Hierarchy
pg_parameters can be defined at different Ansible config levels, priority low to high:
Using ALTER SYSTEM
You can also modify instance parameters at runtime via ALTER SYSTEM:
ALTER SYSTEM writes to postgresql.auto.conf.
Note: In Pigsty-managed clusters,
postgresql.auto.confis managed by Ansible viapg_parameters. ManualALTER SYSTEMchanges may be overwritten on next playbook run. Usepg_parametersinpigsty.ymlfor persistent instance-level params.
List-Type Parameters
Some PostgreSQL parameters accept comma-separated lists. In YAML, quote the entire value. Otherwise, YAML parses it as an array:
Pigsty auto-detects these list parameters and renders them without outer quotes:
| Parameter | Description | Example Value |
|---|---|---|
shared_preload_libraries | Preload shared libs | 'timescaledb, pg_stat_statements' |
search_path | Schema search path | '"$user", public, app' |
local_preload_libraries | Local preload libs | 'auto_explain' |
session_preload_libraries | Session preload libs | 'pg_hint_plan' |
log_destination | Log output targets | 'csvlog, stderr' |
unix_socket_directories | Unix socket dirs | '/var/run/postgresql, /tmp' |
temp_tablespaces | Temp tablespaces | 'ssd_space, hdd_space' |
debug_io_direct | Direct I/O mode (PG16+) | 'data, wal' |
Rendering Example:
Database Level
Database-level parameters apply to all sessions connected to a specific database.
ALTER DATABASE ... SET sets them in pg_db_role_setting.
Configuration
Use the parameters field in pg_databases:
Like instance-level params, list-type values must be quoted in YAML.
Rendering Rules
Pigsty sets database parameters with ALTER DATABASE ... SET.
It selects the required syntax automatically:
List-type params (search_path, temp_tablespaces, local_preload_libraries, session_preload_libraries, log_destination) without outer quotes:
Scalar params with quoted values:
Note:
log_destinationis in the database whitelist, but itscontextissighup. It cannot take effect at database level. Set it at instance level withpg_parameters.
View Database Params
Manual Management
User Level
User-level parameters apply to all sessions for a specific database user.
ALTER USER ... SET sets them in pg_db_role_setting.
Configuration
Use the parameters field in pg_users or pg_default_roles:
Rendering Rules
Same as database-level:
List-type params (search_path, temp_tablespaces, local_preload_libraries, session_preload_libraries) without outer quotes:
Scalar params with quoted values:
DEFAULT Value
Use DEFAULT (case-insensitive) to reset a parameter to PostgreSQL default:
View User Params
Manual Management
Priority
When the same parameter is set at multiple levels, PostgreSQL applies this priority (low to high):
Database vs User Priority:
If the same parameter is set for both the database and the connecting user, PostgreSQL uses the user-level parameter. The user setting has higher priority.
Example:
analystconnecting toanalytics:work_mem = 512MB(user takes precedence)- Other users connecting to
analytics:work_mem = 256MB(database applies) analystconnecting to other DBs:work_mem = 512MB(user applies)
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)