Config Templates

Use Pigsty’s built-in Patroni config templates or customize your own

Pigsty provides four preset Patroni/PostgreSQL config templates optimized for different workloads:

TemplateCPU CoresUse CaseCharacteristics
oltp.yml4-128COLTP transactionsHigh concurrency, low latency
olap.yml4-128COLAP analyticsLarge queries, high parallelism
crit.yml4-128CCritical/FinanceData safety, audit, zero-loss
tiny.yml1-3CTiny instancesResource-constrained envs

Use pg_conf to select a template; default is oltp.yml.

The database tuning template pg_conf should be paired with the OS tuning template node_tune.


Usage

Set pg_conf in your cluster definition. It’s recommended to set node_tune accordingly for OS-level tuning:

pg-test:
  hosts:
    10.10.10.11: { pg_seq: 1, pg_role: primary }
    10.10.10.12: { pg_seq: 2, pg_role: replica }
  vars:
    pg_cluster: pg-test
    pg_conf: oltp.yml    # PostgreSQL config template (default)
    node_tune: oltp      # OS tuning template (default)

For critical financial workloads, use crit.yml:

pg-finance:
  hosts:
    10.10.10.21: { pg_seq: 1, pg_role: primary }
    10.10.10.22: { pg_seq: 2, pg_role: replica }
    10.10.10.23: { pg_seq: 3, pg_role: replica }
  vars:
    pg_cluster: pg-finance
    pg_conf: crit.yml    # PostgreSQL critical template
    node_tune: crit      # OS critical tuning

For low-spec VMs or dev environments, use tiny.yml:

pg-dev:
  hosts:
    10.10.10.31: { pg_seq: 1, pg_role: primary }
  vars:
    pg_cluster: pg-dev
    pg_conf: tiny.yml    # PostgreSQL tiny template
    node_tune: tiny      # OS tiny tuning

Comparison

The four templates differ significantly in key parameters:

Connections & Memory

ParameterOLTPOLAPCRITTINY
max_connections500/1000500500/1000250
work_mem range64MB-1GB64MB-8GB64MB-1GB16MB-256MB
maintenance_work_mem25% shmem50% shmem25% shmem25% shmem
max_locks_per_transaction1-2x maxconn2-4x maxconn1-2x maxconn1-2x maxconn

Parallel Query

ParameterOLTPOLAPCRITTINY
max_worker_processescpu+8cpu+12cpu+8cpu+4
max_parallel_workers50% cpu80% cpu50% cpu50% cpu
max_parallel_workers_per_gather20% cpu (max 8)50% cpu0 (off)0 (off)
parallel_setup_cost2000100020001000
parallel_tuple_cost0.20.10.20.1

Sync Replication

ParameterOLTPOLAPCRITTINY
synchronous_modedepends pg_rpodepends pg_rpoforced ondepends pg_rpo
data_checksumsoptionaloptionalforced onoptional

Vacuum Config

ParameterOLTPOLAPCRITTINY
vacuum_cost_delay20ms10ms20ms20ms
vacuum_cost_limit20001000020002000
autovacuum_max_workers3332

Timeout & Security

ParameterOLTPOLAPCRITTINY
idle_in_transaction_session_timeout10minoff1min10min
log_min_duration_statement100ms1000ms100ms100ms
default_statistics_target4001000400200
track_activity_query_size8KB8KB32KB8KB
log_connectionsauthauthfulldefault

IO Config (PG17+)

ParameterOLTPOLAPCRITTINY
io_workers25% cpu (4-16)50% cpu (4-32)25% cpu (4-8)3
temp_file_limit1/20 disk1/5 disk1/20 disk1/20 disk

Selection Guide

  • OLTP Template: Default choice for most transaction processing. Ideal for e-commerce, social, gaming apps.

  • OLAP Template: For data warehouses, BI reports, ETL. Allows large queries, high parallelism, relaxed timeouts.

  • CRIT Template: For financial transactions, core accounting with strict consistency/security requirements. Forced sync replication, checksums, full audit.

  • TINY Template: For dev/test environments, resource-constrained VMs, Raspberry Pi. Minimizes resource usage, disables parallel queries.


Custom Templates

Create custom templates based on existing ones. Templates are in roles/pgsql/templates/:

roles/pgsql/templates/
├── oltp.yml    # OLTP template (default)
├── olap.yml    # OLAP template
├── crit.yml    # CRIT critical template
└── tiny.yml    # TINY micro template

Steps to create a custom template:

  1. Copy an existing template as base
  2. Modify parameters as needed
  3. Place in roles/pgsql/templates/
  4. Reference via pg_conf

Example:

cp roles/pgsql/templates/oltp.yml roles/pgsql/templates/myapp.yml
# Edit myapp.yml as needed

Then use in your cluster:

pg-myapp:
  vars:
    pg_conf: myapp.yml

Templates use Jinja2 syntax; parameters are dynamically computed based on node resources (CPU, memory, disk).


Tuning Strategy

For technical details on template parameter optimization, see Tuning Strategy:

  • Memory tuning (shared buffers, work mem, max connections)
  • CPU tuning (parallel query worker config)
  • Storage tuning (WAL size, temp file limits)
  • Manual parameter adjustment


默认配置模板的参数优化策略说明

了解在 Pigsty 中,预置的四种 Patroni 场景化模板所采用的不同参数优化策略

OLTP Template

PostgreSQL config template optimized for online transaction processing workloads

OLAP Template

PostgreSQL config template optimized for online analytical processing workloads

CRIT Template

PostgreSQL config template optimized for critical/financial workloads with data safety and audit compliance

TINY Template

PostgreSQL config template optimized for micro instances and resource-constrained environments