# default
data_directory = '/var/lib/postgresql/{{ pg_ver }}/main'
hba_file = '/etc/postgresql/{{ pg_ver }}/main/pg_hba.conf'
ident_file = '/etc/postgresql/{{ pg_ver }}/main/pg_ident.conf'
external_pid_file = '/var/run/postgresql/{{ pg_ver }}-main.pid'
port = 5432
# worker(50) * n_workers(<=128)
max_connections = 6400
unix_socket_directories = '/var/run/postgresql'
ssl = off
# ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
# ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
dynamic_shared_memory_type = posix
max_wal_size = 1GB
min_wal_size = 80MB
log_line_prefix = '%m [%p] %q%u@%d '
log_timezone = 'Europe/Moscow'
cluster_name = '{{ pg_ver }}/main'
stats_temp_directory = '/var/run/postgresql/{{ pg_ver }}-main.pg_stat_tmp'
datestyle = 'iso, mdy'
timezone = 'Europe/Moscow'
lc_messages = 'C.UTF-8'
lc_monetary = 'C.UTF-8'
lc_numeric = 'C.UTF-8'
lc_time = 'C.UTF-8'
default_text_search_config = 'pg_catalog.english'
include_dir = 'conf.d'

# carbon

# The shared lock table has space for max_locks_per_transaction objects (e.g., tables) per server process or prepared transaction;
#  hence, no more than this many distinct objects can be locked at any one time.
# This parameter limits the average number of object locks used by each transaction;
# individual transactions can lock more objects as long as the locks of all transactions fit in the lock table.
# This is not the number of rows that can be locked; that value is unlimited.
# The default, 64, has historically proven sufficient,
#   but you might need to raise this value if you have queries that touch many different tables in a single transaction,
#   e.g., query of a parent table with many children. This parameter can only be set at server start.
# !!! When running a standby server, you must set this parameter to have the same or higher value as on the primary server.
#   Otherwise, queries will not be allowed in the standby server.
max_locks_per_transaction = 256
shared_buffers = {{ shared_buffers }}MB
temp_buffers = {{ temp_buffers }}MB
work_mem = {{ work_mem }}MB

# https://bcrm.carbonsoft.ru/project/Document/DOC-000190#optimizacziya-pamyati-postgresql
# другие косты считаются от seq_page, этому его ставим в 1 _для простоты рассчётов_
seq_page_cost = 0.5

# не сильно завышен, но всё ещё даёт двойной прирост по сравнению с mysql
random_page_cost = 0.6

# типа общий объём файлового кэша всех слоёв: VM, хоста, рейда - чисто коэффициент для рассчёта костов
# если большой — считает что индексы юзать удобно, делаем его большим, считая что вся наша БД входит в память
effective_cache_size = 4GB

# нужно увеличивать при больших объёмах в бд, жирных update etc, у нас нет т.к. db per client
maintenance_work_mem = 1MB

# хитрая фигня для запросов выхлопа во внешние системы в виде json'а, мы это не делаем (в теории перестраховка)
# мб backup restore его юзает
logical_decoding_work_mem = 1MB

# если стоит другое - всё начинает тормозить в два раза сильнее
shared_memory_type = mmap

# asyncio для основных потоков (1000 норм для SSD, а больше _вроде_ нельзя)
effective_io_concurrency = 1000

# asyncio для служебных потоков
maintenance_io_concurrency = 100

# нет параллельной обработки _одного_ запроса
max_worker_processes = 1

# TODO: удалить при выпуске боксовой версии
listen_addresses = '0.0.0.0'
