scope: patroni
namespace: /service/
# name将通过环境变量PATRONI_NAME设置

restapi:
  listen: 0.0.0.0:8008
  # connect_address将通过环境变量PATRONI_RESTAPI_CONNECT_ADDRESS设置

#ctl:
#  insecure: false # Allow connections to Patroni REST API without verifying certificates
#  certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
#  keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
#  cacert: /etc/ssl/certs/ssl-cacert-snakeoil.pem

#citus:
#  database: citus
#  group: 0  # coordinator

#etcd3:
#  hosts: 10.255.1.101:2379,10.255.1.102:2379,10.255.1.103:2379

#raft:
#  data_dir: .
#  self_addr: 127.0.0.1:2222
#  partner_addrs:
#  - 127.0.0.1:2223
#  - 127.0.0.1:2224

# The bootstrap configuration. Works only when the cluster is not yet initialized.
# If the cluster is already initialized, all changes in the `bootstrap` section are ignored!

bootstrap:
  dcs:
    ttl: 30
    loop_wait: 10
    retry_timeout: 10
    maximum_lag_on_failover: 1048576
    postgresql:
      use_pg_rewind: true
      use_slots: true
      parameters:
        timezone: 'Asia/Shanghai'
        max_replication_slots: 5
        wal_keep_size: 128MB
        max_connections: 5000
        # wal_level = minimal    # 最小记录
        # wal_level = replica    # 支持复制 (替代 archive 和 hot_standby)
        # wal_level = logical    # 支持逻辑复制
        wal_level: logical
        max_logical_replication_workers: 4
        max_worker_processes: 8
        wal_keep_segments: 8
        max_wal_senders: 10
        max_prepared_transactions: 0
        max_locks_per_transaction: 64
        wal_log_hints: "on"
        track_commit_timestamp: "off"
        archive_mode: "on"
        archive_timeout: 1800s
        archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f

      recovery_conf:
        restore_command: cp ../wal_archive/%f %p
  initdb:
    - encoding: UTF8
    - locale: en_US.UTF-8
    - data-checksums
  post_bootstrap: /docker-entrypoint-initdb.d/post_bootstrap.sh
  pg_hba:
    - host all all 0.0.0.0/0 md5
    - host replication replicator 0.0.0.0/0 md5

postgresql:
  listen: 0.0.0.0:5432
  # connect_address将通过环境变量PATRONI_POSTGRESQL_CONNECT_ADDRESS设置
  data_dir: /home/postgres/data
  bin_dir: /usr/lib/postgresql/16/bin
  authentication:
    superuser:
      username: postgres
      password: postgres@2020
    replication:
      username: replicator
      password: replicator@2020
  parameters:
    max_connections: 5000
    timezone: 'Asia/Shanghai'
    wal_level: logical
    max_logical_replication_workers: 4
    wal_keep_size: 128MB
    max_wal_senders: 10
    max_replication_slots: 5
    archive_mode: "on"
    archive_timeout: 1800s
    archive_command: 'cd .'
  # 自动创建和管理复制槽
  create_replica_methods:
    - basebackup
  basebackup:
    checkpoint: 'fast'

tags:
  # failover_priority: 1
  noloadbalance: false
  clonefrom: false
  nosync: false
  nostream: false