Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for the total pgbouncer pool_size less than the PostgreSQL max_connections (#236) #237

Merged
merged 13 commits into from
Jan 25, 2023
Merged
24 changes: 24 additions & 0 deletions roles/pgbouncer/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@
mode: 0750
tags: pgbouncer, pgbouncer_conf

- name: Calculate pool_size for defined pgbouncer_pools (if not defined pool_size, then calculate as pgbouncer_default_pool_size)
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
set_fact:
defined_pool_size: "{{ defined_pool_size|default(0)|int + item.pool_parameters|regex_replace ('[^0-9]')|default(pgbouncer_default_pool_size, true)|int }}"
loop: "{{ pgbouncer_pools }}"
tags: pgbouncer_conf, pgbouncer

- name: Calculate totla_pool_size
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
set_fact:
total_pool_size: "{{ defined_pool_size|default(0)|int + (postgresql_databases|length|int - pgbouncer_pools|length|int) * pgbouncer_default_pool_size|int }}"
tags: pgbouncer_conf, pgbouncer

- name: Check max_connections
set_fact:
max_connections: "{{ item.value }}"
when: item.option == "max_connections"
artemsafiyulin marked this conversation as resolved.
Show resolved Hide resolved
loop: "{{ postgresql_parameters }}"
tags: pgbouncer_conf, pgbouncer

- name: Failed when total_pool_size > max_connections
fail:
msg: "total_pool_size: {{ total_pool_size }} > max_connections: {{ max_connections }}. Need change settings"
when: pgbouncer_pools is defined and pgbouncer_pools | length > 0 and total_pool_size | int > max_connections | int
tags: pgbouncer_conf, pgbouncer

- name: Update pgbouncer.ini
template:
src: ../templates/pgbouncer.ini.j2
Expand Down
35 changes: 35 additions & 0 deletions roles/pgbouncer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@
dest: /etc/logrotate.d/pgbouncer
tags: pgbouncer_logrotate, pgbouncer

- name: Calculate pool_size for defined pgbouncer_pools (if not defined pool_size, then calculate as pgbouncer_default_pool_size)
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
set_fact:
defined_pool_size: "{{ defined_pool_size|default(0)|int + item.pool_parameters|regex_replace ('[^0-9]')|default(pgbouncer_default_pool_size, true)|int }}"
loop: "{{ pgbouncer_pools }}"
tags: pgbouncer_conf, pgbouncer

- name: Calculate totla_pool_size
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
set_fact:
total_pool_size: "{{ defined_pool_size|default(0)|int + (postgresql_databases|length|int - pgbouncer_pools|length|int) * pgbouncer_default_pool_size|int }}"
tags: pgbouncer_conf, pgbouncer

- name: Check max_connections
set_fact:
max_connections: "{{ item.value }}"
when: item.option == "max_connections"
loop: "{{ postgresql_parameters }}"
tags: pgbouncer_conf, pgbouncer

- name: Failed when total_pool_size > max_connections
fail:
msg: "total_pool_size: {{ total_pool_size }} > max_connections: {{ max_connections }}. Need change settings"
when: pgbouncer_pools is defined and pgbouncer_pools | length > 0 and total_pool_size | int > max_connections | int
tags: pgbouncer_conf, pgbouncer

- name: Update pgbouncer.ini
template:
src: ../templates/pgbouncer.ini.j2
dest: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
owner: postgres
group: postgres
mode: 0640
notify: "restart pgbouncer"
when: existing_pgcluster is not defined or not existing_pgcluster|bool
tags: pgbouncer_conf, pgbouncer

artemsafiyulin marked this conversation as resolved.
Show resolved Hide resolved
- name: Configure pgbouncer.ini
template:
src: templates/pgbouncer.ini.j2
Expand Down