Skip to content

Commit

Permalink
Merge branch 'master' into cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Nov 7, 2023
2 parents c4ad2fa + a820772 commit 6903f0e
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .config/python/dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ six==1.16.0
subprocess-tee==0.4.1
text-unidecode==1.3
tomli==2.0.1
urllib3==1.26.17
urllib3==1.26.18
wcmatch==8.4.1
websocket-client==1.5.2
yamllint==1.31.0
1 change: 0 additions & 1 deletion .github/workflows/molecule_pgpro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- centos8
- debian10
- debian11
- ubuntu1804
- ubuntu2004
- ubuntu2204

Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/schedule_pg_ubuntu1804.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ _Table of results of daily automated testing of cluster deployment:_
| Debian 10 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_debian10.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_debian10.yml) |
| Debian 11 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_debian11.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_debian11.yml) |
| Debian 12 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_debian11.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_debian12.yml) |
| Ubuntu 18.04 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_ubuntu1804.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_ubuntu1804.yml) |
| Ubuntu 20.04 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_ubuntu2004.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_ubuntu2004.yml) |
| Ubuntu 22.04 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_ubuntu2204.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_ubuntu2204.yml) |
| CentOS Stream 8 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vitabaks/postgresql_cluster/schedule_pg_centosstream8.yml?branch=master)](https://github.com/vitabaks/postgresql_cluster/actions/workflows/schedule_pg_centosstream8.yml) |
Expand Down
2 changes: 1 addition & 1 deletion group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ os_minimum_versions:
CentOS: 7
Rocky: 8.4
OracleLinux: 7
Ubuntu: 18.04
Ubuntu: 20.04
Debian: 10
AlmaLinux: 8.3
1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
consul_node_role: server # if dcs_type: "consul"
consul_bootstrap_expect: true # if dcs_type: "consul"
postgresql_version: "15" # to test custom WAL dir
pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport)
cacheable: true

- name: Set variables for custom PostgreSQL data and WAL directory test
Expand Down
1 change: 1 addition & 0 deletions molecule/pg_upgrade/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
consul_node_role: server # if dcs_type: "consul"
consul_bootstrap_expect: true # if dcs_type: "consul"
postgresql_version: "14" # redefine the version to install for the upgrade test
pgbouncer_processes: 4 # Test multiple pgbouncer processes (so_reuseport)
cacheable: true

- name: Set variables for custom PostgreSQL data and WAL directory test
Expand Down
3 changes: 2 additions & 1 deletion roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ etcd3:
{% endif %}
{% if dcs_exists|bool and dcs_type == 'etcd' %}
etcd3:
hosts: {% for etcd_hosts in patroni_etcd_hosts %}{{etcd_hosts.host}}:{{etcd_hosts.port}}{% if not loop.last %},{% endif %}{% endfor +%}
hosts: {% for etcd_hosts in patroni_etcd_hosts %}{{etcd_hosts.host}}:{{etcd_hosts.port}}{% if not loop.last %},{% endif %}{% endfor %}

{% if patroni_etcd_username | default('') | length > 0 %}
username: {{ patroni_etcd_username | default('') }}
{% endif %}
Expand Down
8 changes: 6 additions & 2 deletions roles/pgbouncer/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
- name: Update pgbouncer.ini
ansible.builtin.template:
src: ../templates/pgbouncer.ini.j2
dest: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
dest: "{{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
owner: postgres
group: postgres
mode: "0640"
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
notify: "restart pgbouncer"
when: existing_pgcluster is not defined or not existing_pgcluster|bool
tags: pgbouncer, pgbouncer_conf
Expand All @@ -26,7 +30,7 @@
become: true
become_user: postgres
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXcq
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"SELECT concat('\"', usename, '\" \"', passwd, '\"') FROM pg_shadow where usename != '{{ patroni_replication_username }}'"
register: pg_shadow_result
changed_when: false
Expand Down
12 changes: 10 additions & 2 deletions roles/pgbouncer/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

- name: Restart pgbouncer service
ansible.builtin.systemd:
name: pgbouncer
name: pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}
enabled: true
state: restarted
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
listen: "restart pgbouncer"

- name: Wait for port "{{ pgbouncer_listen_port }}" to become open on the host
Expand All @@ -19,8 +23,12 @@

- name: Reload pgbouncer service
ansible.builtin.systemd:
name: pgbouncer
name: pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}
state: reloaded
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
listen: "reload pgbouncer"
ignore_errors: true # Added to prevent test failures in CI.

Expand Down
72 changes: 43 additions & 29 deletions roles/pgbouncer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,26 @@
- name: Configure pgbouncer systemd service file
ansible.builtin.template:
src: templates/pgbouncer.service.j2
dest: /etc/systemd/system/pgbouncer.service
dest: "/etc/systemd/system/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.service"
owner: postgres
group: postgres
mode: "0644"
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
notify: "restart pgbouncer"
tags: pgbouncer_service, pgbouncer

- name: Ensure pgbouncer service is enabled
ansible.builtin.systemd:
daemon_reload: true
name: pgbouncer
name: "pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}"
enabled: true
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
tags: pgbouncer_service, pgbouncer

- block: # workaround for pgbouncer from postgrespro repo
Expand All @@ -88,7 +96,7 @@
- name: Enable log rotation with logrotate
ansible.builtin.copy:
content: |
/var/log/pgbouncer/pgbouncer.log {
{{ pgbouncer_log_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.log {
daily
rotate 7
copytruncate
Expand All @@ -98,16 +106,24 @@
missingok
su root root
}
dest: /etc/logrotate.d/pgbouncer
dest: "/etc/logrotate.d/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}"
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
tags: pgbouncer_logrotate, pgbouncer

- name: Configure pgbouncer.ini
ansible.builtin.template:
src: templates/pgbouncer.ini.j2
dest: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
dest: "{{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
owner: postgres
group: postgres
mode: "0640"
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
notify: "restart pgbouncer"
when: existing_pgcluster is not defined or not existing_pgcluster|bool
tags: pgbouncer_conf, pgbouncer
Expand All @@ -128,10 +144,14 @@
- name: Fetch pgbouncer.ini file from master
run_once: true
ansible.builtin.fetch:
src: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
src: "{{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
dest: files/
validate_checksum: true
flat: true
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
delegate_to: "{{ groups.master[0] }}"

- name: Fetch userlist.txt conf file from master
Expand All @@ -146,11 +166,15 @@

- name: Copy pgbouncer.ini file to replica
ansible.builtin.copy:
src: files/pgbouncer.ini
src: "files/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
dest: "{{ pgbouncer_conf_dir }}"
owner: postgres
group: postgres
mode: "0640"
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"

- name: Copy userlist.txt conf file to replica
ansible.builtin.copy:
Expand All @@ -165,8 +189,12 @@
become: false
run_once: true
ansible.builtin.file:
path: files/pgbouncer.ini
path: "files/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
state: absent
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
delegate_to: localhost

- name: Remove userlist.txt conf file from localhost
Expand All @@ -180,30 +208,16 @@

- name: Prepare pgbouncer.ini conf file (replace "listen_addr")
ansible.builtin.lineinfile:
path: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
backrefs: true
loop:
- { regexp: '^listen_addr =', line: 'listen_addr = {{ hostvars[inventory_hostname].inventory_hostname }}' }
loop_control:
label: "{{ item.line }}"
notify: "restart pgbouncer"
when: with_haproxy_load_balancing|bool or
(cluster_vip is not defined or cluster_vip | length < 1)

- name: Prepare pgbouncer.ini conf file (replace "listen_addr")
ansible.builtin.lineinfile:
path: "{{ pgbouncer_conf_dir }}/pgbouncer.ini"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
path: "{{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini"
regexp: '^listen_addr ='
line: 'listen_addr = {{ pgbouncer_listen_addr }}'
backrefs: true
loop:
- { regexp: '^listen_addr =', line: 'listen_addr = {{ hostvars[inventory_hostname].inventory_hostname }},{{ cluster_vip }}' }
loop: "{{ range(0, (pgbouncer_processes | default(1) | int)) | list }}"
loop_control:
label: "{{ item.line }}"
index_var: idx
label: "{{ 'pgbouncer' if idx == 0 else 'pgbouncer-%d' % (idx + 1) }}"
notify: "restart pgbouncer"
when: not with_haproxy_load_balancing|bool and (cluster_vip is defined and cluster_vip | length > 0 )
when: pgbouncer_listen_addr != "0.0.0.0"
when: existing_pgcluster is defined and existing_pgcluster|bool
tags: pgbouncer_conf, pgbouncer

Expand Down
8 changes: 5 additions & 3 deletions roles/pgbouncer/templates/pgbouncer.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* = host=127.0.0.1 port={{ postgresql_port }}

[pgbouncer]
logfile = {{ pgbouncer_log_dir }}/pgbouncer.log
pidfile = /run/pgbouncer/pgbouncer.pid
logfile = {{ pgbouncer_log_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.log
pidfile = /run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}/pgbouncer.pid
listen_addr = {{ pgbouncer_listen_addr | default('0.0.0.0') }}
listen_port = {{ pgbouncer_listen_port | default(6432) }}
unix_socket_dir = /var/run/postgresql
unix_socket_dir = /var/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}
auth_type = {{ pgbouncer_auth_type }}
{% if pgbouncer_auth_user | bool %}
auth_user = {{ pgbouncer_auth_username }}
Expand All @@ -34,6 +34,8 @@ max_db_connections = {{ pgbouncer_max_db_connections }}
pkt_buf = 8192
listen_backlog = 4096

so_reuseport = 1

log_connections = 0
log_disconnections = 0

Expand Down
10 changes: 5 additions & 5 deletions roles/pgbouncer/templates/pgbouncer.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ User=postgres
Group=postgres

PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /run/pgbouncer {{ pgbouncer_log_dir }}
ExecStartPre=/bin/chown -R postgres:postgres /run/pgbouncer {{ pgbouncer_log_dir }}
ExecStartPre=-/bin/mkdir -p /run/pgbouncer /var/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }} {{ pgbouncer_log_dir }}
ExecStartPre=/bin/chown -R postgres:postgres /run/pgbouncer /var/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }} {{ pgbouncer_log_dir }}
{% if ansible_os_family == "Debian" %}
ExecStart=/usr/sbin/pgbouncer -d {{ pgbouncer_conf_dir }}/pgbouncer.ini
ExecStart=/usr/sbin/pgbouncer -d {{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini
{% endif %}
{% if ansible_os_family == "RedHat" %}
ExecStart=/usr/bin/pgbouncer -d {{ pgbouncer_conf_dir }}/pgbouncer.ini
ExecStart=/usr/bin/pgbouncer -d {{ pgbouncer_conf_dir }}/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}.ini
{% endif %}
ExecReload=/bin/kill -SIGHUP $MAINPID
PIDFile=/run/pgbouncer/pgbouncer.pid
PIDFile=/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}/pgbouncer.pid
Restart=on-failure

LimitNOFILE=100000
Expand Down
5 changes: 3 additions & 2 deletions roles/pre-checks/tasks/pgbouncer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
ansible.builtin.set_fact:
pgbouncer_total_pool_size: >-
{{
(pgbouncer_pool_size | int)
((pgbouncer_pool_size | int)
+
(postgresql_databases
| default([])
| rejectattr('db', 'in', pgbouncer_pools | map(attribute='dbname') | list)
| length
) * (pgbouncer_default_pool_size | default(0) | int)
) * (pgbouncer_default_pool_size | default(0) | int))
* (pgbouncer_processes | default(1) | int)
}}
when: pgbouncer_pool_size is defined

Expand Down
4 changes: 2 additions & 2 deletions roles/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ Please see the variable file vars/[upgrade.yml](../../vars/upgrade.yml)
- **Check if PostgreSQL tablespaces exist**
- Print tablespace location (if exists)
- Note: If tablespaces are present they will be upgraded (step 5) on replicas using rsync
- **Test PgBouncer access via localhost**
- test access via 'localhost' to be able to perform 'PAUSE' command
- **Test PgBouncer access via unix socket**
- test access via unix socket to be able to perform 'PAUSE' command
- **Make sure that the cluster ip address (VIP) is running**
- Notes: if 'cluster_vip' is defined

Expand Down
Loading

0 comments on commit 6903f0e

Please sign in to comment.