From 8060a2038fc7b124092cd762e57f4d7d56251c3d Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 15 Sep 2026 22:18:25 +0200 Subject: [PATCH] log_hostname can be set autonomously from external_int, temp_buffers is now a multiple of 8k. --- defaults/main.yml | 39 ++++++++++++++++++++++++++++++++- tasks/postgresql-config-deb.yml | 2 +- tasks/postgresql-config-el.yml | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 01064b8..219d53a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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' } diff --git a/tasks/postgresql-config-deb.yml b/tasks/postgresql-config-deb.yml index 95ea843..8af41ab 100644 --- a/tasks/postgresql-config-deb.yml +++ b/tasks/postgresql-config-deb.yml @@ -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 diff --git a/tasks/postgresql-config-el.yml b/tasks/postgresql-config-el.yml index f11916c..1dc1bf0 100644 --- a/tasks/postgresql-config-el.yml +++ b/tasks/postgresql-config-el.yml @@ -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