postgres/variables.yml

413 lines
11 KiB
YAML
Raw Normal View History

2023-09-07 21:34:06 +02:00
---
2023-12-21 23:15:47 +01:00
# Name of the job to generate
# Also used to controler service names
instance: postgres
pg:
2024-04-09 10:18:19 +02:00
nomad:
# Set higher priority for the postgres job
priority: 80
vault:
pki:
ou: Postgres
# List of vault policies to attach to the task
policies:
- '[[ .instance ]][[ .consul.suffix ]]'
2024-01-31 15:58:44 +01:00
database:
role: '[[ .instance ]]-admin'
pgrole: dba
# Random secrets to generate if missing, and store in vault KV
rand_secrets:
fields:
- pg_pwd
- api_pwd
- monitor_pwd
- replicator_pwd
- rewind_pwd
- vault_initial_pwd
# Postgres server settings
server:
# Major version of postgres to use
pg_version: 15
# Version of patroni
patroni_version: 3.3.0
# The image to use
2024-05-02 14:45:10 +02:00
image: '[[ .docker.repo ]]patroni:[[ .pg.server.pg_version ]]-[[ .pg.server.patroni_version ]]-2'
# Number of postgres instance. Patroni will handle leader election and replication
count: 1
# Optional en vars to pass to the container
# You should set PGBACKREST_XXX variable if you intend to use the back service
# Eg
# env:
# PGBACKREST_PROCESS_MAX: 4
2023-11-30 21:23:11 +01:00
# PGBACKREST_REPO1_RETENTION_FULL: 1
# PGBACKREST_REPO1_RETENTION_DIFF: 7
# PGBACKREST_REPO1_TYPE: sftp
# PGBACKREST_REPO1_SFTP_HOST: pbs.lapiole.org
# PGBACKREST_REPO1_SFTP_HOST_USER: pitr
# PGBACKREST_REPO1_PATH: /postgres/pgbackrest
# PGBACKREST_REPO1_SFTP_HOST_KEY_HASH_TYPE: sha256
# # awk '{print $2}' ssh_host_ecdsa_key.pub | base64 -d | sha256sum
# PGBACKREST_REPO1_SFTP_HOST_FINGERPRINT: ce6eb1c79ce6596d7580f3b08021b48e39e5a30f2fd751a7fa82b480d821eb99
# PGBACKREST_REPO1_SFTP_HOST_KEY_CHECK_TYPE: fingerprint
env:
PGBACKREST_STANZA: '[[ .instance ]]'
2023-11-12 20:05:20 +01:00
nomad:
# Enforce running on distinct hosts
constraints:
- operator: distinct_hosts
value: true
2024-04-09 10:18:19 +02:00
update:
# When running in recovery mode, use huge deadlines as it can take a lot of time
healthy_deadline: '[[ .pg.server.recovery | ternary "48h" "2h" ]]'
progress_deadline: '[[ .pg.server.recovery | ternary "72h" "3h" ]]'
2023-11-12 20:05:20 +01:00
# In recovery mode, neither patroni nor postgres will be started. The container will start and wait for manual recovery
2024-03-27 13:26:29 +01:00
recovery: false
# Recovery configuration to pass to patroni config
recovery_conf: {}
2023-11-30 21:23:11 +01:00
# How many nodes should use synchronous replication. No effect unless count > 1
synchronous_node_count: 0
2024-04-24 23:51:51 +02:00
# Options to pass to initdb when initializing the cluster
initdb:
- "data-checksum"
- "encoding: UTF-8"
# Postgres parameters
# The following memory related settings can be expressed as a percentage, and wil be computed based on the memory allocation of the container
# shared_buffers effective_cache_size maintenance_work_mem wal_buffers work_mem
2023-09-18 12:16:24 +02:00
parameters:
2023-11-03 15:03:44 +01:00
log_line_prefix: "'[%m] u=%u,d=%d,a=%a,c=%h,xid=%x '"
2023-09-18 12:16:24 +02:00
wal_compression: zstd
log_min_duration_statement: 2000
log_timezone: '{{ env "TZ" }}'
timezone: '{{ env "TZ" }}'
log_destination: stderr
2023-11-03 15:19:23 +01:00
log_directory: /proc/1/fd
2023-09-18 12:16:24 +02:00
log_filename: 1
2023-11-03 15:03:44 +01:00
#logging_collector: on
#log_truncate_on_rotation: on
#log_rotation_size: 0
#log_rotation_age: 1440
log_statement: ddl
log_connections: on
log_disconnections: on
2023-10-18 10:38:34 +02:00
datestyle: 'ISO, DMY'
2023-09-18 12:16:24 +02:00
autovacuum_vacuum_threshold: 500
autovacuum_analyze_threshold: 500
autovacuum_vacuum_scale_factor: 0.1
autovacuum_analyze_scale_factor: 0.05
shared_buffers: 50%
2023-09-18 12:16:24 +02:00
maintenance_work_mem: 5%
work_mem: 1%
2023-09-25 15:56:00 +02:00
wal_keep_size: 512
2023-10-30 21:50:28 +01:00
# You can configure ldap auth for postgres
# users needing ldap auth should be members of the ldap_roles role in postgres
ldap_auth:
# Is the auth enabled
enabled: false
# List of servers to try to connect to
servers:
- localhost
# Port
port: 389
# Should StartTLS be used to connect
starttls: true
# The base DN where postgres will start looking for users
base_dn: OU=People,DC=example,DC=org
# Search filter to find matching users
search_filter: "(&(objectClass=user)(!(useraccountcontrol:1.2.840.113556.1.4.803:=2))(memberOf:1.2.840.113556.1.4.1941:=CN=Role_DBA,OU=Roles,DC=example,DC=org)(sAMAccountName=$username))"
# Optional bind DN and password to do the search operation
# If undefined, the search will be done anonymously
#bind_dn: CN=Postgres,OU=Apps,DC=example,DC=org
2024-01-31 15:58:44 +01:00
bind_password: '{{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}{{ .Data.data.ldap_pwd }}{{ end }}'
2023-10-30 21:50:28 +01:00
# Resource allocation for the container
resources:
2023-11-18 23:00:00 +01:00
cpu: 1000
memory: 1024
2023-10-08 17:14:30 +02:00
# URL of the service as seen from the outside
# This is used to initialize connection from vault to handle database secrets
2023-10-30 16:24:54 +01:00
# public_url: postgres://postgres.example.org:5432
2023-10-08 17:14:30 +02:00
traefik:
2024-01-29 14:45:10 +01:00
proto: tcp
# List of entrypoint the service will listen to
entrypoints:
- postgres
2023-10-08 17:14:30 +02:00
prometheus:
2024-03-27 13:26:29 +01:00
enabled: '[[ .prometheus.available ]]'
2023-10-08 17:14:30 +02:00
metrics_url: http://localhost:9187
# Backup service uses pgbackrest to perform
# WAL archive, and regular full/incr/diff backups
backup:
# Additional env var.
# Note that pg.server.env will be inherited so PGBACKREST config only needs to be set there
env: {}
2023-10-18 12:03:42 +02:00
# pgbackrest based backups
pgbackrest:
2024-03-27 13:26:29 +01:00
enabled: false
2023-10-18 12:03:42 +02:00
# Schedules for backups. Empty string to disable
cron:
2023-11-30 21:23:11 +01:00
full: 15 02 * * sun
diff: 15 02 * * mon,tue,wed,thu,fri,sat
incr: ''
2023-10-18 12:03:42 +02:00
# pg_dump based backups
dumps:
2024-03-27 13:26:29 +01:00
enabled: false
2023-10-18 12:03:42 +02:00
format: custom
compression: 6
cron: 39 03 * * *
# Resource allocations
resources:
2023-11-18 23:00:00 +01:00
cpu: 300
memory: 50
memory_max: 256
# Postgres exporter for prometheus
2024-03-27 13:26:29 +01:00
# Only used if prometheus.enabled is true
exporter:
2024-03-28 22:36:37 +01:00
version: 0.15.0
# Image to use
2024-03-28 22:36:37 +01:00
image: '[[ .docker.repo ]]postgres-exporter:[[ .pg.exporter.version ]]-1'
# Additional env var
env: {}
# Resources
resources:
2023-11-18 23:00:00 +01:00
cpu: 50
memory: 32
2023-10-25 23:25:15 +02:00
# manage can create database, users and sync permissions from LDAP (using ldap2pg)
manage:
# Image to use
image: '[[ .docker.repo ]]ldap2pg:6.0-10'
2023-10-30 21:50:28 +01:00
# Resource allocation
resources:
2023-11-18 23:00:00 +01:00
cpu: 50
2023-09-25 15:56:00 +02:00
memory: 32
2023-10-30 21:50:28 +01:00
2023-10-30 23:51:42 +01:00
# Services to wait before running
wait_for:
2023-12-21 23:15:47 +01:00
- service: 'master.[[ .instance ]]'
2023-10-30 23:51:42 +01:00
# Additional env var
env:
WAIT_FOR_TARGETS: localhost:5432
2023-10-30 21:50:28 +01:00
# Connection to postgres through the service mesg
2023-10-08 17:14:30 +02:00
consul:
connect:
upstreams:
2023-12-21 23:15:47 +01:00
- destination_name: "[[ .instance ]]"
2023-10-08 17:14:30 +02:00
local_bind_port: 5432
2023-10-30 21:50:28 +01:00
# List of databases to create (so permissions can be applied)
# For each database, a role with the same name (and NOLOGIN) will be created and be owner of the database
2023-10-30 21:50:28 +01:00
# databases:
# - name: vaultwarden
# - name: odoo
# owner: erp
# encoding: UTF-8
# locale: fr_FR.utf8
2024-01-10 21:22:12 +01:00
# template: template1
# extensions:
# - uuid-ossp
databases: []
2023-10-30 21:50:28 +01:00
# Schedule to run ldap2pg regularily, to ensure permissions are up to date
# This is especially useful when syncing roles from LDAP
2023-10-25 23:25:15 +02:00
# An empty string disable running the job as a cron
cron: ""
2023-10-30 21:50:28 +01:00
# mode can be dry (no change will be made) or real
#
2023-09-11 23:54:10 +02:00
mode: dry
2023-10-30 21:50:28 +01:00
# Default config for ldap2pg (except for rules which are handled separately)
default_config:
version: 6
postgres:
managed_roles_query: |
VALUES
('public'),
('managed_roles')
UNION
SELECT DISTINCT role.rolname
FROM pg_roles AS role
JOIN pg_auth_members AS ms ON ms.member = role.oid
JOIN pg_roles AS parent
ON parent.rolname = 'managed_roles' AND parent.oid = ms.roleid
ORDER BY 1;
privileges:
user:
- __connect__
- __usage_on_schema__
reader:
- user
- __select_on_tables__
- __select_on_sequences__
- __usage_on_sequences__
writer:
- reader
- __temporary__
- __insert_on_tables__
- __update_on_tables__
2023-10-08 17:14:30 +02:00
- __delete_on_tables__
- __update_on_sequences__
- __execute_on_functions__
- __trigger_on_tables__
owner:
- writer
- __create_on_schemas__
- __truncate_on_tables__
rewinder:
- __connect__
- __execute_on_functions__
# Custom config : will be merged on top of default_config
2023-09-11 23:54:10 +02:00
config: {}
# A set of default rules to apply
default_rules:
- roles:
- name: managed_roles
comment: Parent role for all ldap2pg managed roles
- name: ldap_roles
comment: "Parent role for LDAP synced roles"
options: NOLOGIN
parents:
- managed_roles
- name: backup
comment: "DB backup"
options: LOGIN REPLICATION
parents:
- pg_read_all_data
- managed_roles
2023-10-31 15:04:31 +01:00
- name: dba
comment: "Databases admins"
options: SUPERUSER NOLOGIN
2023-10-30 21:50:28 +01:00
parents:
- managed_roles
- name: rewind
comment: "Databases rewinder"
options: LOGIN
2023-10-30 21:50:28 +01:00
parents:
- managed_roles
- name: monitor
comment: "Databases monitor"
options: LOGIN
parents:
- managed_roles
- pg_monitor
- name: vault
comment: "Hashicorp Vault"
options: SUPERUSER LOGIN
2023-10-30 21:50:28 +01:00
parents:
- managed_roles
- grant:
role: vault
privileges: reader
databases: postgres
- grant:
role: monitor
privileges: user
- grant:
role: rewind
privileges: rewinder
databases: postgres
2023-10-30 21:50:28 +01:00
- grant:
2023-10-31 15:04:31 +01:00
role: dba
2023-10-30 21:50:28 +01:00
privileges: owner
# Additional custom rules to apply (will be appended to default_rules)
2023-09-11 23:54:10 +02:00
rules: []
2023-09-17 22:29:40 +02:00
2023-11-30 21:23:11 +01:00
# Settings for major upgrades
upgrade:
2024-04-24 23:51:51 +02:00
# Set to true to run the upgrade
enabled: false
# Docker image to use
image: '[[ .docker.repo ]]postgres-major-upgrade:latest'
# Custom env var to set in the container
2023-11-30 21:23:11 +01:00
env: {}
2024-04-24 23:51:51 +02:00
# Options to pass to pg_upgrade
options:
2024-04-25 09:53:56 +02:00
# Will only work if using XFS, ZFS or btrfs. Else, replace with link
2024-04-24 23:51:51 +02:00
- clone
# Major postgres versions, eg
# from: 15
# to: 16
2023-11-30 21:23:11 +01:00
from: ""
to: ""
2024-04-24 23:51:51 +02:00
# Resource allocation
2023-11-30 21:23:11 +01:00
resources:
cpu: '[[ .pg.server.resources.cpu ]]'
memory: '[[ .pg.server.resources.memory ]]'
2023-10-26 23:58:35 +02:00
# Volumes
volumes:
2023-10-27 14:18:23 +02:00
# The data volume is used to store postgres data
# It'll be opened as single-node-writer, and it's recommended to be a block based volume (eg, iSCSI)
# The volumes are connected using per_alloc, so the alloc ID will be appended. Eg postgres-data[0], postgres-data[1] etc.
2023-10-26 23:58:35 +02:00
data:
type: csi
2023-12-21 23:15:47 +01:00
source: '[[ .instance ]]-data'
per_alloc: true
2023-10-27 14:18:23 +02:00
# Backup volume (can be used for pgbackrest and dumps)
# Will be opened as multi-node-multi-writer. Can be NFS
2023-10-26 23:58:35 +02:00
backup:
type: csi
2023-12-21 23:15:47 +01:00
source: '[[ .instance ]]-backup'
access_mode: multi-node-multi-writer