Skip to content

Commit

Permalink
add ability to override tuning calculated values
Browse files Browse the repository at this point in the history
On servers with low ram or custom footprint, it may be useful to manualy
set specific config values like shared_memory and let the tuning role
set other values automaticaly.
  • Loading branch information
aya authored and vibhorkumar123 committed Feb 28, 2024
1 parent 5765541 commit f4e244c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
14 changes: 14 additions & 0 deletions roles/tuning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ The rest of the variables can be configured and are available in the:
* [roles/tuning/vars/PG.yml](./vars/PG.yml)


### `pg_conf_override_tuning`

Defines if the `pg_postgres_conf_params` should override the `tuning`
values automaticaly calculated from gathered memory informations.
Default: `false`

Example:
```yaml
pg_conf_override_tuning: "true"
pg_postgres_conf_params:
- name: shared_buffers
value: "128MB"
```
### `tuned_profile`

This is the `tuned` profile name used for configuring the system. Default: `edb`
Expand Down
1 change: 1 addition & 0 deletions roles/tuning/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pg_instance_name: main
pg_version: 14
pg_conf_override_tuning: false
tuned_profile: "edb"
tuned_configuration_dir: "/etc/tuned"
ssd_disk: false
Expand Down
32 changes: 30 additions & 2 deletions roles/tuning/tasks/tune_postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,38 @@
_pg_max_connections: >-
{{ [_sys_nvcpus | int * 4, 100] | max }}
# Set the shared buffers value
# Override the max_connections value with pg_postgres_conf_params
- name: Override the variable _pg_max_connections
ansible.builtin.set_fact:
_pg_max_connections: >-
{{ pg_postgres_conf_params |selectattr('name', 'equalto', 'max_connections') |map(attribute='value') |default([_pg_max_connections], true) |first }}
when: pg_conf_override_tuning

# Set the shared_buffers value
- name: Set the variable _pg_shared_buffers_mb
ansible.builtin.include_tasks: tune_pg_shared_buffers.yml

# Override the shared_buffers value with pg_postgres_conf_params
- name: Override the variable _pg_shared_buffers_mb
ansible.builtin.set_fact:
_pg_shared_buffers_mb: >-
{{ pg_postgres_conf_params |selectattr('name', 'equalto', 'shared_buffers') |map(attribute='value') |default([_pg_shared_buffers_mb], true) |first |ansible.builtin.regex_replace('mb', '', ignorecase=True) }}
when: pg_conf_override_tuning

# Set the work_mem value to: ((Total RAM - shared_buffers)/(16 x CPU cores))
- name: Set the variable _pg_work_mem_mb
ansible.builtin.set_fact:
_pg_work_mem_mb: >-
{{ ((_sys_memtotal_mb | int - _pg_shared_buffers_mb | int) / (16 * _sys_nvcpus | int)) | round | int }}
# Set the maintenance_work_mem_mb value to:
# Override the work_mem value with pg_postgres_conf_params
- name: Override the variable _pg_work_mem_mb
ansible.builtin.set_fact:
_pg_work_mem_mb: >-
{{ pg_postgres_conf_params |selectattr('name', 'equalto', 'work_mem') |map(attribute='value') |default([_pg_work_mem_mb], true) |first |ansible.builtin.regex_replace('mb', '', ignorecase=True) }}
when: pg_conf_override_tuning

# Set the maintenance_work_mem value to:
# MAX(15% x (Total RAM - shared_buffers) / autovacuum_max_workers, 1GB)
- name: Set the variable _pg_maintenance_work_mem_mb
ansible.builtin.set_fact:
Expand All @@ -96,6 +117,13 @@
] | min
}}
# Override the maintenance_work_mem value with pg_postgres_conf_params
- name: Override the variable _pg_maintenance_work_mem_mb
ansible.builtin.set_fact:
_pg_maintenance_work_mem_mb: >-
{{ pg_postgres_conf_params |selectattr('name', 'equalto', 'maintenance_work_mem') |map(attribute='value') |default([_pg_maintenance_work_mem_mb], true) |first |ansible.builtin.regex_replace('mb', '', ignorecase=True) }}
when: pg_conf_override_tuning

- name: Initialize the Postgres parameters list
ansible.builtin.set_fact:
_pg_postgres_conf_params:
Expand Down

0 comments on commit f4e244c

Please sign in to comment.