log_hostname can be set autonomously from external_int, temp_buffers is now a multiple of 8k.

This commit is contained in:
Andrea Dell'Amico 2026-09-15 22:18:25 +02:00
parent d45d544a13
commit 8060a2038f
Signed by untrusted user: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 40 additions and 3 deletions

View File

@ -68,7 +68,25 @@ psql_conf_parameters:
- { name: 'shared_buffers', value: '{{ (ansible_memtotal_mb / 4) | int }}MB', set: 'true' }
- { name: 'work_mem', value: '{{ ((ansible_memtotal_mb * 1024) / (400 * ansible_processor_vcpus)) | int }}kB', set: 'true' }
- { name: 'maintenance_work_mem', value: '{{ (ansible_memtotal_mb / 8) | int }}MB', set: 'true' }
- { name: 'temp_buffers', value: '{{ ansible_memtotal_mb }}kB', set: 'true' }
# A thousandth of the memory, like every other entry of this list is a
# fraction of it: N MB of RAM become N kB of temp_buffers.
#
# Expressed in the BASE UNIT of this parameter, 8kB blocks, which is what the
# division is for. The previous form, '{{ ansible_memtotal_mb }}kB', sets the
# same thing and postgresql_set is idempotent with it (measured: a real run
# against an already configured cluster reports `changed: false`). What it
# hides is the rounding: 7941kB is 992.625 blocks, PostgreSQL stores 993, and
# the value that comes back is 7944kB. Writing the block count says what will
# actually be stored.
#
# Two things worth knowing about this parameter, both measured:
# * its context is `user`, and postgresql_set reports
# `restart_required: false`, so it never needed to sit in this list of
# parameters that require a restart;
# * in CHECK MODE postgresql_set reports `changed` for every parameter,
# including ones already at the wanted value. Do not read a check run of
# this role as a list of pending changes.
- { name: 'temp_buffers', value: '{{ (ansible_memtotal_mb / 8) | round | int }}', set: 'true' }
- { name: 'wal_buffers', value: '{{ (ansible_memtotal_mb / 1024 * 2) | int }}MB', set: 'true' }
- { name: 'min_wal_size', value: '{{ (ansible_memtotal_mb / 16) | int }}MB', set: 'true' }
- { name: 'max_wal_size', value: '{{ (ansible_memtotal_mb / 8) | int }}MB', set: 'true' }
@ -79,6 +97,25 @@ psql_conf_parameters:
# Custom parameters. Default empty
psql_conf_custom_parameters: []
# Reverse DNS lookup on every incoming connection.
#
# The default keeps what the role has always done: `on` as soon as the cluster
# listens on an external interface. That has a cost worth knowing about, namely
# a resolver round trip per connection, and a pair of log lines every time the
# peer has no PTR record:
#
# WARNING: pg_getnameinfo_all() failed: Temporary failure in name resolution
# LOG: connection received: host=??? port=???
#
# Set it to 'off' to log the addresses instead, which on a private network is
# usually the more useful of the two and costs nothing. 'default' also resolves
# to off, since off is the PostgreSQL default.
#
# log_connections and log_disconnections are still decided the same way, in
# tasks/postgresql-config-{deb,el}.yml; they follow this pattern if they ever
# need to become configurable as well.
psql_log_hostname: "{% if psql_listen_on_ext_int %}on{% else %}default{% endif %}"
# logging configuration. Important: the parameters that need a restart must be listed in psql_conf_parameters
psql_log_configuration:
- { name: 'log_destination', value: 'stderr', set: 'true' }

View File

@ -132,7 +132,7 @@
become_user: postgres
community.postgresql.postgresql_set:
name: 'log_hostname'
value: "{% if psql_listen_on_ext_int %}on{% else %}default{% endif %}"
value: '{{ psql_log_hostname }}'
notify: Reload postgresql
- name: postgresql-config-deb | Flush flush_handlers Restart PostgreSQL

View File

@ -153,7 +153,7 @@
become_user: postgres
community.postgresql.postgresql_set:
name: 'log_hostname'
value: "{% if psql_listen_on_ext_int %}on{% else %}default{% endif %}"
value: '{{ psql_log_hostname }}'
notify: Reload postgresql
- name: postgresql-config-el | Flush flush_handlers Reload PostgreSQL